Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an ArbitraryInteger from a novel alphabet. #419

Open
Beakerboy opened this issue Jul 7, 2021 · 0 comments
Open

Create an ArbitraryInteger from a novel alphabet. #419

Beakerboy opened this issue Jul 7, 2021 · 0 comments

Comments

@Beakerboy
Copy link
Contributor

Beakerboy commented Jul 7, 2021

In BaseEncoderDecoder::createArbitraryInteger(), I state in the description:

Create an ArbitraryInteger from a number string in novel number bases and alphabets

It looks like I may have oversold this function a little. Sure, it can create from novel alphabets, but those alphabets have to be an alphabet of successive ASCII characters. A number in RFC3548_BASE64_FILE_SAFE format can be output using the functions, but not created because the alphabet is discontinuous in its ASCII mapping. We (I) need to add a function something like this:

public function ArbitraryIntegerFromAlphabet(string $number, string $alphabet): ArbitraryInteger
{
    // Check if $number contains any characters that are not in $alphabet
    // Check if $alphabet has any duplicated characters
    // Check that $alphabet is not greater than 256 characters (if so, the check above would be violated, maybe not if unicode?)
    // Check that $alphabet is ASCII, $number too?
    $flipped_alphabet = \array_filp($alphabet);
    $chars = str_split($number);
    $zero_offset = '';
    foreach ($chars as $char) {
        $zero_offset .=  \chr($flipped_alphabet[$char]);
    }
    return self::createArbitraryInteger($zero_offset, count($alphabet), \chr(0));
}

With this, a base two number where the characters are 't' and 'f' can be created as

ArbitraryIntegerFromAlphabet('tftfttffftftft', 'ft');

All 'f' characters are converted to \chr(0) and all 't' characters to \chr(1). Then the createArbitrayInteger function can create the object. The integer representation of a Bitcoin address can be made using:

$bitcoin_base58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
$genesis_block_address = '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa';
$Integer = ArbitraryIntegerFromAlphabet($genesis_block_address, $bitcoin_base58);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant