<commit_before><?php

require 'letterScore.php';

$input = hex2bin("<KEY>");
$inputLength = strlen($input);
$scores = [];

function sb_xor($encryptedString, $xor_key) {
  $decryptedString = '';

  for ($i = 0; $i < strlen($encryptedString); $i++) {
    $decryptedString .= $encryptedString{$i} ^ chr($xor_key);
  }

  return $decryptedString;
}

for ($kv=0; $kv < 256; $kv++) {
  $charScore = 0;

  $plainText = sb_xor($input, $kv);

  $charScore = englishLetterWeight($plainText, 0.5);

  $scores[chr($kv)] = $charScore;

}

arsort($scores);

$keyCount = 0;
foreach ($scores as $key => $value) {
  if ($keyCount < 5) {
    $decrypt = '';

    for ($i=0; $i < $inputLength; $i++) {
      $decrypt .= $input{$i} ^ $key;
    }

    echo "'$key' (" . ord($key) . ") : " . $decrypt . "\n";
  } else {
    break;
  }

  $keyCount++;

}

?>
<commit_msg>Change final decrypt to use function<commit_after><?php

require 'letterScore.php';

$input = hex2bin("<KEY>");
$inputLength = strlen($input);
$scores = [];

function sb_xor($encryptedString, $xor_key) {
  $decryptedString = '';

  for ($i = 0; $i < strlen($encryptedString); $i++) {
    $decryptedString .= $encryptedString{$i} ^ $xor_key;
  }

  return $decryptedString;
}

for ($kv=0; $kv < 256; $kv++) {
  $charScore = 0;

  $plainText = sb_xor($input, chr($kv));

  $charScore = englishLetterWeight($plainText, 0.5);

  $scores[chr($kv)] = $charScore;

}

arsort($scores);

$keyCount = 0;
foreach ($scores as $key => $value) {
  if ($keyCount < 5) {
    $decrypt = sb_xor($input, $key);

    echo "'$key' (" . ord($key) . ") : " . $decrypt . "\n";
  } else {
    break;
  }

  $keyCount++;

}

?>

{'fraction_non_alphanumeric': 0.22255912674348088, 'fraction_numerical': 0.013947847180109158, 'mean_word_length': 3.5580110497237567, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1989655', 'n_tokens_mistral': 688, 'n_tokens_neox': 637, 'n_words': 131}