3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function strToHex($string){ $hex = ''; for ($i=0; $i<strlen($string); $i++){ $ord = ord($string[$i]); $hexCode = dechex($ord); $hex .= substr('0'.$hexCode, -2); } return strToUpper($hex); } function hexToStr($hex){ $string=''; for ($i=0; $i < strlen($hex)-1; $i+=2){ $string .= chr(hexdec($hex[$i].$hex[$i+1])); } return $string; } function fxor($key, $text){ // Our output text $outText = ''; // Iterate through each character for($i=0;$i<strlen($text);) // Dont need to increment here { for($j=0;$j<strlen($key);$j++,$i++) { $outText .= $text{$i} ^ $key{$j}; } } return $outText; } $ciphertext_base64 = 'sf7PwIfhqofFlKAIgYMKEbExOoVzSj9A0KDwKMJY62k%3D'; $ciphertextHex = strToHex($ciphertext_base64); echo "ciipher hex: " . $ciphertextHex . "\n"; $hexToBase = hexToStr($ciphertextHex); echo "hexToBase: " . $hexToBase . "\n"; echo "ciher base: " . $ciphertext_base64 . "\n"; $ciphertext_dec = base64_decode($ciphertext_base64); # --- DECRYPTION --- echo "cipher text dec: " . $ciphertext_dec . "\n"; echo "ciher dec in hex" . strToHex($ciphertext_dec) . "\n"; $iv = substr($ciphertext_dec,0, 16); $res = substr($ciphertext_dec, 16, strlen($ciphertext_dec)-16); echo "---iv: " . $iv . "\n"; echo "---res: " . $res . "\n"; # retrieves the IV, iv_size should be created using mcrypt_get_iv_size() $iv_dec = substr($ciphertext_dec, 0, 16); echo "iv dec: " . $iv_dec . "\n"; # retrieves the cipher text (everything except the $iv_size in the front) $ciphertext_dec = substr($ciphertext_dec, 16); echo "on the right: " . $ciphertext_dec . "\n"; $ivHex = strToHex($iv_dec); echo "change string to hex (iv): " .$ivHex . "\n"; echo "w druga manke: " . hexToStr($ivHex) . "\n"; $onRightHex = strToHex($ciphertext_dec); echo "onRight in hex: " . $onRightHex . "\n"; echo "w druga manke: " . hexToStr( strToHex($ciphertext_dec) ) . "\n"; $testHex = strToHex('id=1'); $adHex = strToHex('id=2'); echo "testHex: " . $testHex . "\n"; echo "adHex: " . $adHex . "\n"; $xta = strToUpper( dechex(hexdec($testHex) ^ hexdec($adHex)) ); $myXor = fxor($testHex, $adHex ); echo "xta: " . $xta . "\n"; echo "myXor: " . $myXor . "\n"; $ivHex2 = substr($ivHex, 16, 32); $ivHex1 = substr($ivHex, 0, 16); echo "ivHex2: " . $ivHex2 . "\n"; echo "ivHex1: " . $ivHex1 . "\n"; $xivxta = strToUpper( dechex(hexdec($xta) ^ hexdec($ivHex2)) ); echo "xivxta: " . $xivxta . "\n"; $cmpHex = $ivHex1 . $xivxta . $onRightHex; echo "cmpHex: " . $cmpHex . "\n"; $cmpStr = hexToStr($cmpHex); echo "cmpStr: " . $cmpStr . "\n"; $cmpB = base64_encode($cmpStr); echo "cmpB: " . $cmpB; ?>
based on RdqJY
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.1.7
ciipher hex: 7366375077496668716F66466C4B414967594D4B456245784F6F567A536A3941304B44774B4D4A5936326B253344 hexToBase: sf7PwIfhqofFlKAIgYMKEbExOoVzSj9A0KDwKMJY62k%3D ciher base: sf7PwIfhqofFlKAIgYMKEbExOoVzSj9A0KDwKMJY62k%3D cipher text dec: ����᪇Ŕ��� �1:�sJ?@Р�(�X�i7 ciher dec in hexB1FECFC087E1AA87C594A00881830A11B1313A85734A3F40D0A0F028C258EB6937 ---iv: ����᪇Ŕ���  ---res: �1:�sJ?@Р�(�X�i7 iv dec: ����᪇Ŕ���  on the right: �1:�sJ?@Р�(�X�i7 change string to hex (iv): B1FECFC087E1AA87C594A00881830A11 w druga manke: ����᪇Ŕ���  onRight in hex: B1313A85734A3F40D0A0F028C258EB6937 w druga manke: �1:�sJ?@Р�(�X�i7 testHex: 69643D31 adHex: 69643D32 xta: 3 myXor:  ivHex2: C594A00881830A11 ivHex1: B1FECFC087E1AA87 xivxta: C594A00881830803 cmpHex: B1FECFC087E1AA87C594A00881830803B1313A85734A3F40D0A0F028C258EB6937 cmpStr: ����᪇Ŕ����1:�sJ?@Р�(�X�i7 cmpB: sf7PwIfhqofFlKAIgYMIA7ExOoVzSj9A0KDwKMJY62k3