Skip to content

Commit 23b0def

Browse files
committed
Allow easy adjustments of threshold_validity for more control
1 parent c01ec91 commit 23b0def

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

‎xortool/args.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def parse_parameters(doc, version):
4747
"most_frequent_char": parse_char(p["char"]),
4848
"text_charset": get_charset(p["text-charset"]),
4949
"known_plain": p["known-plaintext"].encode() if p["known-plaintext"] else False,
50+
"threshold": parse_int(p["threshold"]),
5051
}
5152
except ValueError as err:
5253
raise ArgError(str(err))

‎xortool/tool_main.py‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
- guess the key (base on knowledge of most frequent char)
88
99
Usage:
10-
xortool [-x] [-m MAX-LEN] [-f] [-t CHARSET] [FILE]
11-
xortool [-x] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE]
12-
xortool [-x] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE]
10+
xortool [-x] [-r PERCENT] [-m MAX-LEN] [-f] [-t CHARSET] [FILE]
11+
xortool [-x] [-r PERCENT] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE]
12+
xortool [-x] [-r PERCENT] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE]
1313
xortool [-h | --help]
1414
xortool --version
1515
@@ -23,6 +23,7 @@
2323
-f --filter-output filter outputs based on the charset
2424
-t CHARSET --text-charset=CHARSET target text character set [default: printable]
2525
-p PLAIN --known-plaintext=PLAIN use known plaintext for decoding
26+
-r PERCENT, --threshold=PERCENT threshold validity percentage [default: 95]
2627
-h --help show this help
2728
2829
Notes:
@@ -47,10 +48,11 @@
4748
import string
4849
import sys
4950

50-
from xortool.args import (
51+
from xortool.args import(
5152
parse_parameters,
5253
ArgError,
53-
)
54+
)
55+
5456
from xortool.charset import CharsetError
5557
from xortool.colors import (
5658
COLORS,
@@ -364,7 +366,12 @@ def produce_plaintexts(ciphertext, keys, key_char_used):
364366
key_mapping.write("file_name;key_repr\n")
365367
perc_mapping.write("file_name;char_used;perc_valid\n")
366368

367-
threshold_valid = 95
369+
370+
if PARAMETERS["threshold"]:
371+
threshold_valid = PARAMETERS["threshold"]
372+
else:
373+
threshold_valid = 95
374+
368375
count_valid = 0
369376

370377
for index, key in enumerate(keys):

0 commit comments

Comments
 (0)