solved the first 5 problems
This commit is contained in:
parent
5f28587c15
commit
8211d16af3
9 changed files with 8235 additions and 5 deletions
28
04.py
Normal file
28
04.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
import helper, cryptlib
|
||||
|
||||
def bruteforce_xor(hexstring_list):
|
||||
plaintext_candidates = []
|
||||
|
||||
for i in range(len(hexstring_list)):
|
||||
hexstring = hexstring_list[i]
|
||||
for key in range(256):
|
||||
decrypt = cryptlib.single_byte_xor(hexstring, key)
|
||||
english_score = cryptlib.score_english_lang(decrypt)
|
||||
result = {
|
||||
'line': i+1,
|
||||
'key': key,
|
||||
'score': english_score,
|
||||
'plaintext': decrypt.strip(),
|
||||
'cipertext': hexstring
|
||||
}
|
||||
plaintext_candidates.append(result)
|
||||
return plaintext_candidates
|
||||
|
||||
def main():
|
||||
content = helper.read_file("data/04.txt")
|
||||
hexstring_list = content.splitlines()
|
||||
plaintext_candidates = bruteforce_xor(hexstring_list)
|
||||
print(sorted(plaintext_candidates, key=lambda c: c['score'], reverse=True)[0])
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue