How to resolve the algorithm Bitcoin/public point to address step by step in the Factor programming language
How to resolve the algorithm Bitcoin/public point to address step by step in the Factor programming language
Table of Contents
Problem Statement
Bitcoin uses a specific encoding format to encode the digest of an elliptic curve public point into a short ASCII string. The purpose of this task is to perform such a conversion. The encoding steps are: The base-58 encoding is based on an alphabet of alphanumeric characters (numbers, upper case and lower case, in that order) but without the four characters 0, O, l and I. Here is an example public point: The corresponding address should be: 16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM Nb. The leading '1' is not significant as 1 is zero in base-58. It is however often added to the bitcoin address for various reasons. There can actually be several of them. You can ignore this and output an address without the leading 1. Extra credit: add a verification procedure about the public point, making sure it belongs to the secp256k1 elliptic curve
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Bitcoin/public point to address step by step in the Factor programming language
Source code in the factor programming language
USING: checksums checksums.ripemd checksums.sha io.binary kernel
math sequences ;
IN: rosetta-code.bitcoin.point-address
CONSTANT: ALPHABET "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
: btc-checksum ( bytes -- checksum-bytes )
2 [ sha-256 checksum-bytes ] times 4 head ;
: bigint>base58 ( n -- str )
33 [ 58 /mod ALPHABET nth ] "" replicate-as reverse nip ;
: >base58 ( bytes -- str )
be> bigint>base58 ;
: point>address ( X Y -- address )
[ 32 >be ] bi@ append
0x4 prefix
sha-256 checksum-bytes
ripemd-160 checksum-bytes
dup 0 prefix btc-checksum
append 0 prefix >base58 ;
You may also check:How to resolve the algorithm Minimum positive multiple in base 10 using only 0 and 1 step by step in the C programming language
You may also check:How to resolve the algorithm Selectively replace multiple instances of a character within a string step by step in the Delphi programming language
You may also check:How to resolve the algorithm Golden ratio/Convergence step by step in the RATFOR programming language
You may also check:How to resolve the algorithm Binary digits step by step in the ACL2 programming language
You may also check:How to resolve the algorithm Man or boy test step by step in the Smalltalk programming language