开发者

How i can Convert this Function Back?

fu开发者_如何学Pythonnction getVideoName($in) {
    $index = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    $base = strlen($index);

    // Digital number  <<--  alphabet letter code
    $in = strrev($in);
    $out = 0;
    $len = strlen($in) - 1;
    for ($t = 0; $t <= $len; $t++) {
        $bcpow = bcpow($base, $len - $t);
        $out = $out + strpos($index, substr($in, $t, 1)) * $bcpow;
    }

    $out = sprintf('%F', $out);
    $out = substr($out, 0, strpos($out, '.'));

    return $out;

}

This Function return a converted value How i can convert the value back to input number ?


You probably won't be able to do this. The code looks to be one way only.

for ($t = 0; $t <= $len; $t++) {
// bcpow raises the first argument to the power of the second argument,
// the first argument being the length of the string, the second being
// the length minus one, minus the current position being inspected.
// This can make a pretty large number depending on the length of the string.
    $bcpow = bcpow($base, $len - $t);
// Then that number is multiplied by the position of 
// the currently inspected character in the string,
// as if it was in the key string given earlier,
// then that number is added to the running total.
    $out = $out + strpos($index, substr($in, $t, 1)) * $bcpow;
}
// Then it's formatted as a floating point number
$out = sprintf('%F', $out);
// and then truncated at the decimal.
$out = substr($out, 0, strpos($out, '.'));

This is effectively one way because undoing it would require knowing the length of the string and the position of characters within it, and if you know that, you have the original string!


The function is also slightly buggy, getVideoName('a') returns 0. So does getVideoName('aaaaaaaaaa'). getVideoName('d') returns 3, so does getVideoName('da').

The numbering is predictable, and follows a pattern. It might be called deterministic, even. Given enough input from an outsider that doesn't know the formula, it could be possible to either reconstruct or guess an output... but that would be a very time consuming and annoying process.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜