- var_dump: documentation ( source)
<?php
/*
128-bit key = 01 23 45 67 12 34 56 78 23 45 67 89 34 56 78 9A
plaintext = 01 23 45 67 89 AB CD EF
ciphertext = 23 8B 4F E5 84 7E 44 B2
*/
$key = "\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45\x67\x89\x34\x56\x78\x9A";
$data = "\x01\x23\x45\x67\x89\xAB\xCD\xEF";
var_dump(mcrypt_encrypt('cast-128', $key, $data, 'ecb') === "\x23\x8B\x4F\xE5\x84\x7E\x44\xB2");
/*
80-bit key = 01 23 45 67 12 34 56 78 23 45
= 01 23 45 67 12 34 56 78 23 45 00 00 00 00 00 00
plaintext = 01 23 45 67 89 AB CD EF
ciphertext = EB 6A 71 1A 2C 02 27 1B
*/
$key = "\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45";
$data = "\x01\x23\x45\x67\x89\xAB\xCD\xEF";
$key .= "\x00\x00\x00\x00\x00\x00";
var_dump(mcrypt_encrypt('cast-128', $key, $data, 'ecb') === "\xEB\x6A\x71\x1A\x2C\x02\x27\x1B");
/*
40-bit key = 01 23 45 67 12
= 01 23 45 67 12 00 00 00 00 00 00 00 00 00 00 00
plaintext = 01 23 45 67 89 AB CD EF
ciphertext = 7A C8 16 D1 6E 9B 30 2E
*/
$key = "\x01\x23\x45\x67\x12";
$data = "\x01\x23\x45\x67\x89\xAB\xCD\xEF";
$key .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
var_dump(mcrypt_encrypt('cast-128', $key, $data, 'ecb') === "\x7A\xC8\x16\xD1\x6E\x9B\x30\x2E");