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.
 
 
 
 
 
 

44 lines
764 B

  1. import sys
  2. def rotate(x, y):
  3. return (x + y) % 26
  4. def shift(letter, n):
  5. x = ord(letter) - ord("A")
  6. y = rotate(x, n)
  7. return chr(ord("A") + y)
  8. def rot13(message):
  9. message = "".join([x for x in message if x.isalpha()])
  10. message = message.upper()
  11. res = ""
  12. for c in message:
  13. res += shift(c, 13)
  14. return res
  15. def encrypt(key, message):
  16. message = "".join([x for x in message if x.isalpha()])
  17. message = message.upper()
  18. res = ""
  19. i = 0
  20. for c in message:
  21. x = ord(key[i % len(key)]) - ord("A")
  22. res += shift(c, x)
  23. i += 1
  24. return res
  25. def main():
  26. cle = sys.argv[1]
  27. message = sys.argv[2]
  28. res = encrypt(cle, message)
  29. print(res)
  30. if __name__ == "__main__":
  31. main()