Skip to content

Instantly share code, notes, and snippets.

@clone1018
Created February 20, 2015 21:23
Show Gist options
  • Save clone1018/be8189ae13537b894a9d to your computer and use it in GitHub Desktop.
Save clone1018/be8189ae13537b894a9d to your computer and use it in GitHub Desktop.
$testString = "test";
$modes = mcrypt_list_modes();
$algorithms = mcrypt_list_algorithms();
var_dump($modes, $algorithms);
foreach($algorithms as $cipher)
{
echo "<h1 style=\"border-top:1px solid black;\">".$cipher."</h1>\n";
foreach($modes as $mode)
{
$keySize = mcrypt_get_key_size($cipher, $mode);
$key = randString($keySize);
$iv_size = mcrypt_get_iv_size($cipher, $mode);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$encrypted_string = mcrypt_encrypt($cipher, $key, utf8_encode($testString), $mode, $iv);
$str = urlencode(base64_encode($encrypted_string));
echo "$mode:$keySize - <code>". $str ."</code> - ".strlen($str)."<br>";
}
}
function randString($length, $charset='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
{
$str = '';
$count = strlen($charset);
while ($length--) {
$str .= $charset[mt_rand(0, $count-1)];
}
return $str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment