2019-01-30 09:16:28 +00:00
|
|
|
<?php
|
|
|
|
function getObfuscationSalt(){
|
2019-01-30 09:47:45 +00:00
|
|
|
$saltFile=dirname(__FILE__)."/idObfuscation_salt.php";
|
|
|
|
if(file_exists($saltFile)){
|
|
|
|
require $saltFile;
|
2019-01-30 09:16:28 +00:00
|
|
|
}else{
|
|
|
|
$bytes=openssl_random_pseudo_bytes(4);
|
2019-01-30 09:47:45 +00:00
|
|
|
$sf=fopen($saltFile,"w");
|
2019-01-30 09:16:28 +00:00
|
|
|
fwrite($sf,chr(60)."?php\n");
|
|
|
|
fwrite($sf,'$OBFUSCATION_SALT=0x'.bin2hex($bytes).";\n");
|
|
|
|
fwrite($sf,"?".chr(62));
|
|
|
|
fclose($sf);
|
2019-01-30 09:47:45 +00:00
|
|
|
require $saltFile;
|
2019-01-30 09:16:28 +00:00
|
|
|
}
|
|
|
|
return isset($OBFUSCATION_SALT)?$OBFUSCATION_SALT:0;
|
|
|
|
}
|
2019-01-30 11:39:13 +00:00
|
|
|
/*
|
|
|
|
This is a simple reversible hash function I made for encoding and decoding test IDs.
|
|
|
|
It is not cryptographically secure, don't use it to hash passwords or something!
|
|
|
|
*/
|
2019-01-30 09:16:28 +00:00
|
|
|
function obfdeobf($id){
|
|
|
|
$salt=getObfuscationSalt()&0xFFFFFFFF;
|
|
|
|
$id=$id&0xFFFFFFFF;
|
|
|
|
for($i=0;$i<16;$i++){
|
|
|
|
$id=$id^$salt;
|
2019-02-14 08:01:21 +00:00
|
|
|
$salt=(($salt>>1)&0xFFFFFFFF)|(($salt&0x00000001)<<31);
|
|
|
|
$id=((0x0000FFFF&$id)<<16)|((0xFFFF0000&$id)>>16);
|
2019-01-30 09:16:28 +00:00
|
|
|
$id=(($id>>1)&0xFFFFFFFF)|(($id&0x00000001)<<31);
|
|
|
|
}
|
|
|
|
return $id;
|
|
|
|
}
|
|
|
|
function obfuscateId($id){
|
2019-02-14 08:01:21 +00:00
|
|
|
return str_pad(base_convert(obfdeobf($id+1),10,36),7,0,STR_PAD_LEFT);
|
2019-01-30 09:16:28 +00:00
|
|
|
}
|
|
|
|
function deobfuscateId($id){
|
2019-02-14 08:01:21 +00:00
|
|
|
return obfdeobf(base_convert($id,36,10))-1;
|
2019-01-30 09:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//IMPORTANT: DO NOT ADD ANYTHING BELOW THE PHP CLOSING TAG, NOT EVEN EMPTY LINES!
|
|
|
|
?>
|