function scoreSingleByteXORStrings(array $strings, array $weights, $penalty = 0) { $topScores = []; $topChars = []; foreach ($strings as $pos => $string) { $scores = scoreSingleByteXOR($string, $weights, $penalty); arsort($scores); $topScores[$pos] = current($scores); $topChars[$pos] = key($scores); } return [$topScores, $topChars]; }
$char = $trial[$j]; if (isset($weights[$char])) { $score += $weights[$char]; } else { $score -= $penalty; } } $scores[$i] = $score; } return $scores; } // don't output if we're included into another script. if (!debug_backtrace()) { $encrypted = hex2bin('454f42442e37696771343b31696b62353169624f4f303b3a343152'); $encryptedLen = strlen($encrypted); $scores = scoreSingleByteXOR($encrypted, $englishLanguageWeights); arsort($scores); print "Highest scoring character codes:\n"; $i = 0; foreach ($scores as $k => $v) { print "{$k} - {$v}\n"; if (++$i === 3) { break; } } print "\nDecrypted strings:\n"; $i = 0; foreach ($scores as $k => $v) { $decypted = $encrypted ^ str_repeat(chr($k), $encryptedLen); print "{$k}: {$decypted}\n"; if (++$i === 3) {