solved the first 5 problems

This commit is contained in:
Joshua Flores 2025-04-26 22:37:02 -04:00
parent 5f28587c15
commit 8211d16af3
No known key found for this signature in database
GPG key ID: CE41E342DBBBB9B7
9 changed files with 8235 additions and 5 deletions

28
04.py Normal file
View 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()