Skip to content

Instantly share code, notes, and snippets.

@atucom
Created January 15, 2020 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atucom/b4adc9cae195e4a6ac5b2ee86386c51c to your computer and use it in GitHub Desktop.
Save atucom/b4adc9cae195e4a6ac5b2ee86386c51c to your computer and use it in GitHub Desktop.
Solution to Cryptopals Challenge 4
import langdetect
from langdetect import detect
def ascii_hex_to_bytes(hex_input):
return bytearray.fromhex(hex_input)
with open('Downloads/cryptopals-challenge4.txt') as f:
xorinput=f.readlines()
xor2 = [line.strip() for line in xorinput]
xorinput = xor2
for line in xorinput:
input_bytes=ascii_hex_to_bytes(line)
for integer in range(0,256):
candidate_xor = []
for byte in input_bytes:
candidate_xor.append(byte ^ integer)
decoded="".join([chr(element) for element in candidate_xor])
try:
if 'en' in detect(decoded) and decoded.isascii():
print(decoded)
except langdetect.lang_detect_exception.LangDetectException:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment