Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- # score for being an english word
- def score(x):
- # calculate how many characters are english chars
- score = [(1) if (c.isalpha()) else(0) for c in x]
- # multiply result by number of words
- score *= len(x.split(' '))
- return score
- def decode(s):
- res = []
- # convert to string
- plain_text_bytes = bytes.fromhex(s)
- # iterate over each character
- for ind in range(256):
- result = ''
- # xor to char
- for t in plain_text_bytes:
- r = t ^ ind
- result += chr(r)
- # check if accomplishes regex
- if re.search("^[a-zA-Z0-9. -_?]*$", result):
- res += [result]
- return res
- if __name__ == "__main__":
- # number of strings
- n = int(input())
- # array of strings that are most likely to be words
- found = []
- for i in range(n):
- s = input()
- # decoded array of given input (most likely to be words)
- found += decode(s)
- # sort arr
- decrypted_word = max(found, key=lambda x: score(x))
- # print result
- print(decrypted_word)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement