Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to allow adjustments to threshold_valid #45

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ xortool

Usage:
xortool [-x] [-m MAX-LEN] [-f] [-t CHARSET] [FILE]
xortool [-x] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE]
xortool [-x] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE]
xortool [-x] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [-r PERCENT] [FILE]
xortool [-x] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [-r PERCENT] [FILE]
xortool [-h | --help]
xortool --version

Expand All @@ -43,6 +43,7 @@ Options:
-f --filter-output filter outputs based on the charset
-t CHARSET --text-charset=CHARSET target text character set [default: printable]
-p PLAIN --known-plaintext=PLAIN use known plaintext for decoding
-r PERCENT, --threshold=PERCENT threshold validity percentage [default: 95]
-h --help show this help

Notes:
Expand All @@ -61,6 +62,7 @@ Examples:
xortool -x -c ' ' file.hex
xortool -b -f -l 23 -t base64 message.enc
xortool -b -p "xctf{" message.enc
xortool -r 80 -p "flag{" -c ' ' message.enc
```

Example 1
Expand Down
1 change: 1 addition & 0 deletions xortool/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def parse_parameters(doc, version):
"most_frequent_char": parse_char(p["char"]),
"text_charset": get_charset(p["text-charset"]),
"known_plain": p["known-plaintext"].encode() if p["known-plaintext"] else False,
"threshold": parse_int(p["threshold"]),
}
except ValueError as err:
raise ArgError(str(err))
16 changes: 12 additions & 4 deletions xortool/tool_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

Usage:
xortool [-x] [-m MAX-LEN] [-f] [-t CHARSET] [FILE]
xortool [-x] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE]
xortool [-x] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE]
xortool [-x] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [-r PERCENT] [FILE]
xortool [-x] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [-r PERCENT] [FILE]
xortool [-h | --help]
xortool --version

Expand All @@ -23,6 +23,7 @@
-f --filter-output filter outputs based on the charset
-t CHARSET --text-charset=CHARSET target text character set [default: printable]
-p PLAIN --known-plaintext=PLAIN use known plaintext for decoding
-r PERCENT, --threshold=PERCENT threshold validity percentage [default: 95]
-h --help show this help

Notes:
Expand All @@ -40,17 +41,19 @@
xortool -l 11 -c 20 file.bin
xortool -x -c ' ' file.hex
xortool -b -f -l 23 -t base64 message.enc
xortool -r 80 -p "flag{{" -c ' ' message.enc
"""

from operator import itemgetter
import os
import string
import sys

from xortool.args import (
from xortool.args import(
parse_parameters,
ArgError,
)

from xortool.charset import CharsetError
from xortool.colors import (
COLORS,
Expand Down Expand Up @@ -364,7 +367,12 @@ def produce_plaintexts(ciphertext, keys, key_char_used):
key_mapping.write("file_name;key_repr\n")
perc_mapping.write("file_name;char_used;perc_valid\n")

threshold_valid = 95

if PARAMETERS["threshold"]:
threshold_valid = PARAMETERS["threshold"]
else:
threshold_valid = 95

count_valid = 0

for index, key in enumerate(keys):
Expand Down