Bitcoin/public point to address: Difference between revisions

→‎{{header|Perl}}: longer pipeline and a final unpack
(→‎{{header|Perl}}: longer pipeline and a final unpack)
Line 306:
 
sub public_point_to_address {
my $ec = join '04' . join, '04', @_; # EC: concat x and y to one string and prepend '04' magic value
 
my @byte$octets = pack ='C*', map { hex } unpack('(a2)65', $ec); # transform the hex values string to list of decimal valuesoctets
my $octets = pack 'C*', @byte; # actually build the octet stream
my $hash = chr(0) . Crypt::RIPEMD160->hash(sha256 $octets); # perform RIPEMD160(SHA256(octets)
my $checksum = substr sha256(sha256 $hash), 0, 4; # build the checksum
my $hex = join '0x' . join, '0x', # build hex value of hash and checksum
map { sprintf( "%02X", ord)$_ }
(unpack 'C*', $hash.$checksum) =~ /./gs;
return '1' . sprintf "%32s", encode_base58($hex, 'bitcoin'); # Do the Base58 encoding, prepend "1"
}
Anonymous user