-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise_08
executable file
·39 lines (27 loc) · 1.09 KB
/
exercise_08
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
# Copyright 2014 Carl Winbäck. See the COPYING file at the top-level directory
# of this distribution.
from binascii import hexlify
from operator import itemgetter
from libpals.util import ecb_or_cbc
def get_candidates(input_list):
candidate_list = []
for input_line in enumerate(input_list, start=1):
candidate = {
'line_number': input_line[0],
'ciphertext': bytes.fromhex(input_line[1])
}
candidate_list.append(candidate)
return candidate_list
def display_result(winner_list):
for winner in winner_list:
hex_string = str(object=hexlify(winner['ciphertext']),
encoding='utf-8')
print("""%""")
print("""Line number: {}""".format(winner['line_number']))
print("""Ciphertext (hex): {}""".format(hex_string))
indata = [line.rstrip() for line in open('data/8.txt')]
candidate_list = get_candidates(indata)
winners = [x for x in candidate_list if ecb_or_cbc(x['ciphertext']) == 'ecb']
print("""SET 01 CHALLENGE 08: Detect AES in ECB mode""")
display_result(winners)