Bitcoin/public point to address: Difference between revisions
Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Added Seed7 example) |
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
||
Line 164:
{{out}}
<pre>16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM</pre>
=={{header|Factor}}==
<lang factor>USING: checksums checksums.ripemd checksums.sha io.binary kernel
Line 194 ⟶ 195:
point>address . ! "16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM"
</pre>
=={{header|Go}}==
{{libheader|Go sub-repositories}}
Line 301 ⟶ 303:
16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM
</pre>
=={{header|Haskell}}==
<lang haskell>import Numeric (showIntAtBase)
Line 434 ⟶ 437:
{{out}}
<pre>16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM</pre>
=={{header|Perl 6}}==▼
<lang perl6>use Digest::SHA;▼
use Digest::RIPEMD;▼
constant BASE58 = <▼
1 2 3 4 5 6 7 8 9▼
A B C D E F G H J K L M N P Q R S T U V W X Y Z▼
a b c d e f g h i j k m n o p q r s t u v w x y z▼
>;▼
sub encode( UInt $n ) {▼
[R~] BASE58[ $n.polymod: 58 xx * ]▼
}▼
sub public_point_to_address( UInt $x, UInt $y ) {▼
my @bytes = (▼
|$y.polymod( 256 xx 32 )[^32], # ignore the extraneous 33rd modulus▼
|$x.polymod( 256 xx 32 )[^32],▼
);▼
my $hash = rmd160 sha256 Blob.new: 4, @bytes.reverse;▼
my $checksum = sha256(sha256 Blob.new: 0, $hash.list).subbuf: 0, 4;▼
encode reduce * * 256 + * , flat 0, ($hash, $checksum)».list ▼
}▼
say public_point_to_address▼
0x50863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B2352,▼
0x2CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6;</lang>▼
{{out}}▼
<pre>6UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM</pre>▼
=={{header|Phix}}==
Line 715 ⟶ 687:
1 test passed
8 tests passed</pre>
(formerly Perl 6)
▲<lang perl6>use Digest::SHA;
▲use Digest::RIPEMD;
▲constant BASE58 = <
▲ 1 2 3 4 5 6 7 8 9
▲ A B C D E F G H J K L M N P Q R S T U V W X Y Z
▲ a b c d e f g h i j k m n o p q r s t u v w x y z
▲>;
▲sub encode( UInt $n ) {
▲ [R~] BASE58[ $n.polymod: 58 xx * ]
▲}
▲sub public_point_to_address( UInt $x, UInt $y ) {
▲ my @bytes = (
▲ |$y.polymod( 256 xx 32 )[^32], # ignore the extraneous 33rd modulus
▲ |$x.polymod( 256 xx 32 )[^32],
▲ );
▲ my $hash = rmd160 sha256 Blob.new: 4, @bytes.reverse;
▲ my $checksum = sha256(sha256 Blob.new: 0, $hash.list).subbuf: 0, 4;
▲ encode reduce * * 256 + * , flat 0, ($hash, $checksum)».list
▲}
▲say public_point_to_address
▲0x50863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B2352,
▲0x2CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6;</lang>
▲{{out}}
▲<pre>6UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM</pre>
=={{header|Ruby}}==
|