3v4l.org

run code in 300+ PHP versions simultaneously
<?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; ?>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.24, 8.3.0 - 8.3.12
Fatal error: Array and string offset access syntax with curly braces is no longer supported in /in/fg7o1 on line 30
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/fg7o1 on line 30 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/fg7o1 on line 30 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
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
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

preferences:
100.53 ms | 413 KiB | 5 Q