Read first: TEA block cipher implement in PHP and Javascript
We provide some test vectors for TEA:
Test vector| Hex Test vector | Test key | Hex Test key | Hex result uirclgrp | 0x756972636c677270 | pfoqujnbcjgbsfbm | 0x70666f71756a6e62636a67627366626d | 0x436358c7d1e15fcb vnmtvkwt | 0x766e6d74766b7774 | tlbtbsbqowosvbbw | 0x746c6274627362716f776f7376626277 | 0xf048b08c4589def aqalhwrg | 0x6171616c68777267 | slwovgujpafwlred | 0x736c776f7667756a706166776c726564 | 0xf458f5a78bba7041 jcmgtckf | 0x6a636d6774636b66 | sjohpciimrhsrlqi | 0x736a6f68706369696d726873726c7169 | 0x529b7b23be68d8b8 iugltbfw | 0x6975676c74626677 | cngdolpuklclvotu | 0x636e67646f6c70756b6c636c766f7475 | 0x905e0323113ef0c6 dklhlcjq | 0x646b6c686c636a71 | wdeiarddpjvihgsu | 0x7764656961726464706a766968677375 | 0x9643907d36de830 wvlbbldq | 0x77766c62626c6471 | olnfcbvjjswocsvp | 0x6f6c6e666362766a6a73776f63737670 | 0x66f04481d6c5e46d bokwtksg | 0x626f6b77746b7367 | irqacqiwaummnjjl | 0x697271616371697761756d6d6e6a6a6c | 0x5a2e7d69a703f54c rspfbfnn | 0x7273706662666e6e | iftvgwpbowthwhln | 0x69667476677770626f77746877686c6e | 0x42eb6a6340ed260 fqievcqv | 0x6671696576637176 | weeftbcunfcgmtke | 0x77656566746263756e6663676d746b65 | 0x743c11f78bd0774a
Here is the code we use:
<?php /** * @author www.Tutorialspots.com * @copyright 2017 */ echo "Test vector| Hex Test vector | Test key | Hex Test key | Hex result"; echo "<br />"; for($i=0;$i<10;$i++){ echo $v = chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)); echo " | 0x"; echo $hv = TEA::strToHex($v); echo " | "; echo $k = chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)). chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)).chr(rand(97,119)); echo " | 0x"; echo $hk = TEA::strToHex($k); echo " | 0x"; echo implode("", array_map(function($x){return dechex($x);}, TEA::TEAencrypt(array(TEA::_str232bits(substr($v,0,4)),TEA::_str232bits(substr($v,4,4))),array(TEA::_str232bits(substr($k,0,4)),TEA::_str232bits(substr($k,4,4)),TEA::_str232bits(substr($k,8,4)),TEA::_str232bits(substr($k,12,4)))))); echo "<br />"; } ?>
Function strToHex
/** * Convert binary string to hexadecimal string */ public static function strToHex($str){ $str = unpack("H*",$str); return $str[1]; }
1 Comment
TEA block cipher implement in PHP and Javascript | Free Online Tutorials
(January 22, 2017 - 2:39 am)[…] more: Test vectors TEA XTEA block cipher implement in PHP and Javascript XXTEA block cipher implement in PHP and […]