<?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;
?>
preferences:
25.48 ms | 412 KiB | 5 Q