-
-
Save anonymous/1939c6e76d4bf400eb9b525a76dd2288 to your computer and use it in GitHub Desktop.
AlphaID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function decode( $input, $index ) { | |
$base = strlen( $index ); | |
$output = 0; | |
$length = strlen( $input ) - 1; | |
for( $i = 0; $i <= $length; $i++ ) { | |
$bcpow = bcpow( $base, $length - $i ); | |
$output += strpos( $index, substr( $input, $i, 1 ) ) * $bcpow; | |
} | |
$output -= pow( $base, 4 ); | |
$output = sprintf( '%F', $output ); | |
$output = substr( $output, 0, strpos( $output, '.' ) ); | |
return (int) $output; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function encode( $input, $index ) { | |
$base = strlen( $index ); | |
$input += pow( $base, 4 ); | |
$output = ''; | |
for( $i = floor( log( $input, $base ) ); $i >= 0; $i-- ) { | |
$bcp = bcpow( $base, $i ); | |
$start = floor( $input / $bcp ) % $base; | |
$output .= substr( $index, $start, 1 ); | |
$input = $input - ( $start * $bcp ); | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment