@ 2017-02-21T07:43:31Z <?php
$encryption_key="adfgjderuspmwzwt";
$encryptedText = "02eftQAHQKejcfMJYbm06GD21HqFCj55uhAMLqbdGEONSHWLVMn1dIchgEFCNZvCSW7oPM44qyqQ";
$key="adfgjderuspmwzwt";
$data = "02eftQAHQKejcfMJYbm06GD21HqFCj55uhAMLqbdGEONSHWLVMn1dIchgEFCNZvCSW7oPM44qyqQ";
/*$encryptionMethod = "AES-256-CBC";
// DEFINE our cipher
define('AES_256_CBC', 'aes-256-cbc');
// Generate a 256-bit encryption key
// This should be stored somewhere instead of recreating it each time
$encryption_key = openssl_random_pseudo_bytes(32);
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($encryptionMethod));
$encrypted = $encryptedText . ':' . $iv;
$parts = explode(':', $encrypted);
$decrypted = openssl_decrypt($parts[0], $encryptionMethod, $encryption_key, 0, $parts[1]);
echo "Decrypted: $decrypted\n";*/
/*function decrypt($data, $key)
{
$decode = base64_decode($data);
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128,$key,$decode,"MCRYPT_MODE_CBC","\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
}
decrypt($data, $key);*/
/**
* Decrypt a text encrypted by AES in counter mode of operation
*
* @param ciphertext source text to be decrypted
* @param password the password to use to generate a key
* @param nBits number of bits to be used in the key (128, 192, or 256)
* @return decrypted text
*/
function decrypt($ciphertext, $password, $nBits)
{
$blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) return ''; // standard allows 128/192/256 bit keys
$ciphertext = base64_decode($ciphertext);
// use AES to encrypt password (mirroring encrypt routine)
$nBytes = $nBits / 8; // no bytes in key
$pwBytes = array();
for ($i = 0; $i < $nBytes; $i++) $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff;
$key = Aes::cipher($pwBytes, Aes::keyExpansion($pwBytes));
$key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long
// recover nonce from 1st element of ciphertext
$counterBlock = array();
$ctrTxt = substr($ciphertext, 0, 8);
for ($i = 0; $i < 8; $i++) $counterBlock[$i] = ord(substr($ctrTxt, $i, 1));
// generate key schedule
$keySchedule = Aes::keyExpansion($key);
// separate ciphertext into blocks (skipping past initial 8 bytes)
$nBlocks = ceil((strlen($ciphertext) - 8) / $blockSize);
$ct = array();
for ($b = 0; $b < $nBlocks; $b++) $ct[$b] = substr($ciphertext, 8 + $b * $blockSize, 16);
$ciphertext = $ct; // ciphertext is now array of block-length strings
// plaintext will get generated block-by-block into array of block-length strings
$plaintxt = array();
for ($b = 0; $b < $nBlocks; $b++) {
// set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff;
for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c - 4] = self::urs(($b + 1) / 0x100000000 - 1, $c * 8) & 0xff;
$cipherCntr = Aes::cipher($counterBlock, $keySchedule); // encrypt counter block
$plaintxtByte = array();
for ($i = 0; $i < strlen($ciphertext[$b]); $i++) {
// -- xor plaintext with ciphered counter byte-by-byte --
$plaintxtByte[$i] = $cipherCntr[$i] ^ ord(substr($ciphertext[$b], $i, 1));
$plaintxtByte[$i] = chr($plaintxtByte[$i]);
}
$plaintxt[$b] = implode('', $plaintxtByte);
}
// join array of blocks into single plaintext string
$plaintext = implode('', $plaintxt);
return $plaintext;
}
decrypt($data, $key,256);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.1.2 0.020 0.060 40.14 7.1.1 0.010 0.083 22.34 7.1.0 0.057 0.070 20.57 7.0.16 0.013 0.053 21.89 7.0.15 0.093 0.073 20.09 7.0.14 0.080 0.070 20.04 7.0.13 0.060 0.060 20.16 7.0.12 0.020 0.053 21.82 7.0.11 0.060 0.060 20.03 7.0.10 0.017 0.057 21.77 7.0.9 0.053 0.063 19.95 7.0.8 0.077 0.053 20.02 7.0.7 0.010 0.057 21.87 7.0.6 0.023 0.060 21.73 7.0.5 0.067 0.047 20.14 7.0.4 0.057 0.057 20.14 7.0.3 0.050 0.060 20.06 7.0.2 0.053 0.060 20.02 7.0.1 0.043 0.060 20.08 7.0.0 0.060 0.047 21.94
preferences:dark mode live preview
142.95 ms | 939 KiB | 8 Q