I have two files, one is the encryption of the original using frequency analysis, and just do a new string with the decoded string(some chars probably wont be correctilly changed, but its ok, ill change them manually later), but im completelly stuck on how to do this after counting the incidences on both files.
//gets string from both text files and converts in a array
$reference = file_get_contents('reference_file.txt', true);
$encrypted = file_get_contents('encrypted_file.txt', true);
$refarray = str_split($reference, '1');
$encarray = str_split($encrypted, '1');
//counts ocurrences in both strings and saves them as an array : "Character" ==> "Number of Ocurrences"
$refarray1 = array_count_values(str_split(file_get_contents('reference_file.txt', true)));
$refarray2 = array_count_values(str_split(file_get_contents('encrypted_file.txt', true)));
Now i dont know where to go from here, totally stuck
EDIT 1:
foreach ($refarray1 as $key => $val) {
print "$key = $val <br \>";
$aux69 = $key;
foreach ($refarray2 as $key2 => $val2) {
if ($val == $val2) {
$encrypted = str_replace($key2, $key, $encrypted);
}
}
}
I came up with this, but its still not working, it changes lots of letters in the encrypted string, but its unreadable, it changed most chars to only 'j' 'd' 'e', example of final string:
" jjdebdda bw d jdbejewedwbje zjee edzjdbbddda "