【发布时间】:2015-11-05 05:54:13
【问题描述】:
我有两个文件,一个是使用频率分析对原始文件进行加密,然后用解码后的字符串做一个新的字符串(有些字符可能不会被正确更改,但没关系,稍后会手动更改它们),但是在计算了两个文件的发生率后,我完全坚持如何做到这一点。
//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)));
现在我不知道从哪里开始,完全卡住了
编辑 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);
}
}
}
我想出了这个,但它仍然无法正常工作,它改变了加密字符串中的许多字母,但它不可读,它将大多数字符更改为只有 'j' 'd' 'e',最终字符串的示例:
" jjdebdda bw d jdbejewedwbje zjee edzjdbbddda"
【问题讨论】:
标签: php arrays encryption frequency-analysis