<commit_before>xortool.py
====================

A tool to do some xor analysis:

  - guess the key length (based on count of equal chars)
  - guess the key (base on knowledge of most frequent char)

Usage
---------------------

<pre>
  xortool [-h|--help] [OPTIONS] [<filename>]
Options:
  -l,--key-length     length of the key
  -c,--char           most frequent char
  -x,--hex            input is hex-encoded str
  -m,--max-keylen     maximum key length to probe
</pre>

Example
---------------------

<pre>
# xor is some external script to encrypt files
tests $ xor -f /bin/ls -s "secret_key" > binary_xored

tests $ python ../xortool.py binary_xored
Probable key lengths:
   2:   5.0 %
   5:   8.7 %
   8:   4.9 %
  10:   15.4 %
  12:   4.8 %
  15:   8.5 %
  18:   4.8 %
  20:   15.1 %
  22:   4.7 %
  25:   8.4 %
  28:   4.7 %
  30:   14.9 %
Key-length can be 5*n
Most possible char is needed to guess the key!

# 00 is the most frequent byte in binaries
tests $ python ../xortool.py binary_xored -l 10 -c 00
...
1 possible key(s) of length 10:
secret_key

# decrypted ciphertexts are placed in ./xortool/Number_<key repr>
# ( have no better idea )
tests $ md5sum xortool/0_secret_key /bin/ls
29942e290876703169e1b614d0b4340a  xortool/0_secret_key
29942e290876703169e1b614d0b4340a  /bin/ls
</pre>

The most common use is just pass the encrypted file and
the most frequent character (usually 00 for binaries and 20 for text files):

<pre>
tests $ xortool tool_xored -c 20
Probable key lengths:
   2:   5.6 %
   5:   7.8 %
   8:   6.0 %
  10:   11.7 %
  12:   5.6 %
  15:   7.6 %
  18:   5.4 %
  20:   19.8 %
  22:   5.4 %
  25:   7.8 %
  28:   5.7 %
  30:   11.4 %
Key-length can be 5*n
1 possible key(s) of length 20:
an0ther s3cret \xdd key
</pre>

Author: hellman ( <EMAIL> )
License: GNU General Public License v2 (http://opensource.org/licenses/gpl-2.0.php)
<commit_msg>sorry for 5 pushes, my fail :/<commit_after>xortool.py
====================

A tool to do some xor analysis:

  - guess the key length (based on count of equal chars)
  - guess the key (base on knowledge of most frequent char)

Usage
---------------------

<pre>
  xortool [-h|--help] [OPTIONS] [&lt;filename&gt;]
Options:
  -l,--key-length     length of the key
  -c,--char           most frequent char
  -x,--hex            input is hex-encoded str
  -m,--max-keylen     maximum key length to probe
</pre>

Example
---------------------

<pre>
# xor is some external script to encrypt files
tests $ xor -f /bin/ls -s "secret_key" > binary_xored

tests $ python ../xortool.py binary_xored
Probable key lengths:
   2:   5.0 %
   5:   8.7 %
   8:   4.9 %
  10:   15.4 %
  12:   4.8 %
  15:   8.5 %
  18:   4.8 %
  20:   15.1 %
  22:   4.7 %
  25:   8.4 %
  28:   4.7 %
  30:   14.9 %
Key-length can be 5*n
Most possible char is needed to guess the key!

# 00 is the most frequent byte in binaries
tests $ python ../xortool.py binary_xored -l 10 -c 00
...
1 possible key(s) of length 10:
secret_key

# decrypted ciphertexts are placed in ./xortool/Number_<key repr>
# ( have no better idea )
tests $ md5sum xortool/0_secret_key /bin/ls
29942e290876703169e1b614d0b4340a  xortool/0_secret_key
29942e290876703169e1b614d0b4340a  /bin/ls
</pre>

The most common use is just pass the encrypted file and
the most frequent character (usually 00 for binaries and 20 for text files):

<pre>
tests $ xortool tool_xored -c 20
Probable key lengths:
   2:   5.6 %
   5:   7.8 %
   8:   6.0 %
  10:   11.7 %
  12:   5.6 %
  15:   7.6 %
  18:   5.4 %
  20:   19.8 %
  22:   5.4 %
  25:   7.8 %
  28:   5.7 %
  30:   11.4 %
Key-length can be 5*n
1 possible key(s) of length 20:
an0ther s3cret \xdd key
</pre>

Author: hellman ( <EMAIL> )

License: GNU General Public License v2 (http://opensource.org/licenses/gpl-2.0.php)

{'fraction_non_alphanumeric': 0.14349894291754756, 'fraction_numerical': 0.09328752642706131, 'mean_word_length': 2.277056277056277, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 22, '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': '7070273', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1466, 'n_words': 490}