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.
 
 
 
 
 
 

34 lines
626 B

  1. def rotate(x, y):
  2. return (x + y) % 26
  3. def shift(letter, n):
  4. x = ord(letter) - ord('A')
  5. y = rotate(x, n)
  6. return chr(ord('A') + y)
  7. def rot13(message):
  8. message = "".join([x for x in message if x.isalpha()])
  9. message = message.upper()
  10. res = ""
  11. for c in message:
  12. res += shift(c, 13)
  13. return res
  14. def test_rotate():
  15. assert rotate(1, 3) == 4
  16. assert rotate(25, 3) == 2
  17. def test_shift():
  18. assert shift('A', 2) == 'C'
  19. assert shift('E', 2) == 'G'
  20. assert shift('Y', 3) == 'B'
  21. def test_rot13():
  22. assert rot13('hello') == 'URYYB'
  23. assert rot13('URYYB') == 'HELLO'