Turning an integer into random string and back aga

2020-06-18 04:07发布

what I'm wanting is to convert an integer into a string. For example, 123456789 may become 8GFsah93r ... you know like Youtube, Pastebin and what not. I then want to convert it back.

I'm working with large integers, for example: 131569877435989900

Take a look at this link: http://codepad.viper-7.com/wHKOMi

This is my attempt using a function I found on the web, obviously... it's not correctly converting back to integer. I'm needing something that does this realiably.

Thanks

标签: php
7条回答
ら.Afraid
2楼-- · 2020-06-18 04:31

The easiest way to get random string is to use hash functions like md5() or sha1() For example:

<?php
$bigInt = '131569877435989900';
$hash = md5($bigInt);
$hashed=substr($hash,0,-20);
echo $hashed;
?>

These hash functions are irreversible-you can't get the original value(these functions are also used to crypt data). If you want you can save the original big integer in an array or a database. But decripting the hash would be impossible.

查看更多
登录 后发表回答