Locally trying to decrypt a binary file with the given ciper. The data separated with 0A in hexadecimal. In the decrypting phase my array works like an int, and I do not know why. Is there a proper solution to it?
php version:8.0.11
tried to reinstall xampp
tried castings
<?php if(count($_POST)>0) { $ciper = array(5, -14, 31, -9, 3); $dec_arr = []; $ind = 0; $handle = fopen("secret.txt", "r"); if ($handle) { while (!feof($handle)) { $hex = bin2hex(fread ($handle , 1 )); $dec_arr[$ind] = hexdec($hex); $ind ; } fclose($handle); } unset($dec_arr[(count($dec_arr)-1)]); $raw_data = ""; for($i = 0, $k = 0; $i < count($dec_arr); $i )//Warning: Trying to access array offset on value of type int { if($dec_arr[$i]==10) { $dec_arr[$i] = 59; $k = 0; } else { $dec_arr = ((($dec_arr[$i] 256) - $ciper[$k])%256);//Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, int given } $raw_data .= chr($dec_arr[$i]); $k = (($k 1)%5); } }?>
CodePudding user response:
Like @aynber mentioned you are assigning an int value to the $dev_arr. Your line should be
$dec_arr[$i] = ((($dec_arr[$i] 256) - $ciper[$k])%256);
Also you could replace
unset($dec_arr[(count($dec_arr)-1)]);
with
array_pop($dec_arr);
