Advertisement
CSenshi

Cryptography - HW1.3 (Challenge-03)

Jan 10th, 2020
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. import re
  2.  
  3.  
  4. def decode(s):
  5.     # from bytes to string
  6.     plain_text_bytes = bytes.fromhex(s)
  7.  
  8.     # iterate over all characters
  9.     for ind in range(256):
  10.         # xor each char
  11.         result = ''
  12.         for t in plain_text_bytes:
  13.             r = t ^ ind
  14.             result += chr(r)
  15.  
  16.         # if given text is built with regex return answer
  17.         if re.search("^[a-zA-Z0-9. -_?]*$", result):
  18.             return result
  19.  
  20.  
  21. if __name__ == "__main__":
  22.     s = input()
  23.     result = decode(s)
  24.     print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement