Skip to content

Instantly share code, notes, and snippets.

@hthuong09
Created June 23, 2015 19:28
Show Gist options
  • Save hthuong09/120b543cb7925afa8c99 to your computer and use it in GitHub Desktop.
Save hthuong09/120b543cb7925afa8c99 to your computer and use it in GitHub Desktop.
share-online.biz file size encryption algorithm
<?php
function encrypt($original) {
$arr = range(0, strlen($original) - 1);
shuffle($arr);
$shuffleStr = '';
$hexStr = '';
foreach ($arr as $char) {
$shuffleStr .= $original[$char];
$hexStr .= str_pad(dechex($char), 3, "0", STR_PAD_LEFT);
}
$str = strrev($shuffleStr . 'a|b' . $hexStr);
return $str;
}
function info($a) {
$a = strrev($a);
$a = explode('a|b', $a);
$a[1] = str_split($a[1], 3);
$b = [];
for ($i=0; $i < count($a[1]); $i++) {
$a[1][$i] = hexdec($a[1][$i]);
$b[$a[1][$i]] = $i;
}
$a[1] = "";
for ($i=0; $i < count($b); $i++) {
if (isset($a[0][$b[$i]])) {
$a[1] = $a[1].$a[0][$b[$i]];
} else {
$a[1] .= " ";
}
}
return $a[1];
}
$encryptedStr = encrypt('thisiscleanstring,nothingheree');
$decryptedStr = info($encryptedStr);
echo 'Encryped String: ' . $encryptedStr . "\n";
echo 'Decryped String: ' . $decryptedStr . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment