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 = '26CPpe20dELYZeMhpR8wjkw1%2BtGKfw3%2B1wnJejLf7Ds%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; echo "---res: " . $res; # 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=test'); $adHex = strToHex('id=admin'); 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.4.1 - 8.4.2
Parse error: syntax error, unexpected token "{" in /in/sinru on line 30
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.15
Fatal error: Array and string offset access syntax with curly braces is no longer supported in /in/sinru 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/sinru on line 30 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/sinru on line 30 ciipher hex: 323643507065323064454C595A654D68705238776A6B773125324274474B66773325324231776E4A656A4C66374473253344 hexToBase: 26CPpe20dELYZeMhpR8wjkw1%2BtGKfw3%2B1wnJejLf7Ds%3D ciher base: 26CPpe20dELYZeMhpR8wjkw1%2BtGKfw3%2B1wnJejLf7Ds%3D cipher text dec: ۠���tB�e�!�0�L5�F)�7�p���-�óp ciher dec in hexDBA08FA5EDB47442D865E321A51F308E4C35D81B4629FC37D81D709C97A32DFEC3B370 ---iv: ۠���tB�e�!�0�---res: L5�F)�7�p���-�ópiv dec: ۠���tB�e�!�0� on the right: L5�F)�7�p���-�óp change string to hex (iv): DBA08FA5EDB47442D865E321A51F308E w druga manke: ۠���tB�e�!�0� onRight in hex: 4C35D81B4629FC37D81D709C97A32DFEC3B370 w druga manke: L5�F)�7�p���-�óp testHex: 69643D74657374 adHex: 69643D61646D696E xta: 690D595C10081A1A ivHex2: D865E321A51F308E ivHex1: DBA08FA5EDB47442 xivxta: B168BA7DB5172A1A cmpHex: DBA08FA5EDB47442B168BA7DB5172A1A4C35D81B4629FC37D81D709C97A32DFEC3B370 cmpStr: ۠���tB�h�}�*L5�F)�7�p���-�óp cmpB: 26CPpe20dEKxaLp9tRcqGkw12BtGKfw32B1wnJejLf7Ds3A=
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
ciipher hex: 323643507065323064454C595A654D68705238776A6B773125324274474B66773325324231776E4A656A4C66374473253344 hexToBase: 26CPpe20dELYZeMhpR8wjkw1%2BtGKfw3%2B1wnJejLf7Ds%3D ciher base: 26CPpe20dELYZeMhpR8wjkw1%2BtGKfw3%2B1wnJejLf7Ds%3D cipher text dec: ۠���tB�e�!�0�L5�F)�7�p���-�óp ciher dec in hexDBA08FA5EDB47442D865E321A51F308E4C35D81B4629FC37D81D709C97A32DFEC3B370 ---iv: ۠���tB�e�!�0�---res: L5�F)�7�p���-�ópiv dec: ۠���tB�e�!�0� on the right: L5�F)�7�p���-�óp change string to hex (iv): DBA08FA5EDB47442D865E321A51F308E w druga manke: ۠���tB�e�!�0� onRight in hex: 4C35D81B4629FC37D81D709C97A32DFEC3B370 w druga manke: L5�F)�7�p���-�óp testHex: 69643D74657374 adHex: 69643D61646D696E xta: 690D595C10081A1A ivHex2: D865E321A51F308E ivHex1: DBA08FA5EDB47442 xivxta: B168BA7DB5172A1A cmpHex: DBA08FA5EDB47442B168BA7DB5172A1A4C35D81B4629FC37D81D709C97A32DFEC3B370 cmpStr: ۠���tB�h�}�*L5�F)�7�p���-�óp cmpB: 26CPpe20dEKxaLp9tRcqGkw12BtGKfw32B1wnJejLf7Ds3A=

preferences:
100.54 ms | 414 KiB | 5 Q