Skip to content

Commit a857836

Browse files
authored
Merge pull request #33 from JafarAkhondali/master
Enable Xortool to accept known plaintext for filtering output
2 parents 0a09680 + a18d840 commit a857836

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

‎README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ xortool
2929
3030
Usage:
3131
xortool [-x] [-m MAX-LEN] [-f] [-t CHARSET] [FILE]
32-
xortool [-x] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [FILE]
33-
xortool [-x] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [FILE]
32+
xortool [-x] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE]
33+
xortool [-x] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE]
3434
xortool [-h | --help]
3535
xortool --version
3636
@@ -43,6 +43,7 @@ Options:
4343
-o --brute-printable same as -b but will only check printable chars
4444
-f --filter-output filter outputs based on the charset
4545
-t CHARSET --text-charset=CHARSET target text character set [default: printable]
46+
-p PLAIN --known-plaintext=PLAIN use known plaintext for decoding
4647
-h --help show this help
4748
4849
Notes:
@@ -60,6 +61,7 @@ Examples:
6061
xortool -l 11 -c 20 file.bin
6162
xortool -x -c ' ' file.hex
6263
xortool -b -f -l 23 -t base64 message.enc
64+
xortool -b -p "xctf{" message.enc
6365
```
6466

6567
Example 1

‎xortool/args.py‎

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

‎xortool/xortool‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ xortool
77
88
Usage:
99
xortool [-x] [-m MAX-LEN] [-f] [-t CHARSET] [FILE]
10-
xortool [-x] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [FILE]
11-
xortool [-x] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [FILE]
10+
xortool [-x] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE]
11+
xortool [-x] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE]
1212
xortool [-h | --help]
1313
xortool --version
1414
@@ -21,6 +21,7 @@ Options:
2121
-o --brute-printable same as -b but will only check printable chars
2222
-f --filter-output filter outputs based on the charset
2323
-t CHARSET --text-charset=CHARSET target text character set [default: printable]
24+
-p PLAIN --known-plaintext=PLAIN use known plaintext for decoding
2425
-h --help show this help
2526
2627
Notes:
@@ -372,6 +373,9 @@ def produce_plaintexts(ciphertext, keys, key_char_used):
372373
file_name = os.path.join(DIRNAME, key_index + ".out")
373374

374375
dexored = dexor(ciphertext, key)
376+
# ignore saving file when known plain is provided and output doesn't contain it
377+
if PARAMETERS["known_plain"] and PARAMETERS["known_plain"] not in dexored:
378+
continue
375379
perc = round(100 * percentage_valid(dexored))
376380
if perc > threshold_valid:
377381
count_valid += 1
@@ -388,6 +392,8 @@ def produce_plaintexts(ciphertext, keys, key_char_used):
388392
perc_mapping.close()
389393

390394
fmt = "Found {C_COUNT}{:d}{C_RESET} plaintexts with {C_COUNT}{:d}{C_RESET}%+ valid characters"
395+
if PARAMETERS["known_plain"]:
396+
fmt += " which contained '{}'".format(PARAMETERS["known_plain"].decode('ascii'))
391397
print(fmt.format(count_valid, round(threshold_valid), **COLORS))
392398
print("See files {}, {}".format(fn_key_mapping, fn_perc_mapping))
393399

0 commit comments

Comments
 (0)