You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

decrypt.py 1.2 KiB

5 vuotta sitten
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import sys
  2. import string
  3. def rotate(x, y):
  4. return (x - y) % 26
  5. def shift(letter, n):
  6. x = ord(letter) - ord("A")
  7. y = rotate(x, n)
  8. return chr(ord("A") + y)
  9. def rot13(message):
  10. message = "".join([x for x in message if x.isalpha()])
  11. message = message.upper()
  12. res = ""
  13. for c in message:
  14. res += shift(c, 13)
  15. return res
  16. def decrypt(key, message):
  17. message = "".join([x for x in message if x.isalpha()])
  18. message = message.upper()
  19. res = ""
  20. i = 0
  21. for c in message:
  22. x = ord(key[i % len(key)]) - ord("A")
  23. res += shift(c, x)
  24. i += 1
  25. return res
  26. def try_with_key(key, message):
  27. res = decrypt(key, message)
  28. if "PLEKSZYGLADZ" in res:
  29. return res
  30. def main():
  31. message = sys.argv[1]
  32. print(decrypt('N', message))
  33. """
  34. message = sys.argv[1]
  35. letters = string.ascii_uppercase
  36. for a in letters:
  37. for b in letters:
  38. for c in letters:
  39. key = a + b + c
  40. res = try_with_key(key, message)
  41. if res:
  42. print(res)
  43. print("key:", key)
  44. return
  45. """
  46. if __name__ == "__main__":
  47. main()