ceasar.py 480 B

1234567891011121314151617181920212223242526
  1. # coding: utf-8
  2. def ceasar(str, n):
  3. res = ''
  4. for c in str:
  5. res += shift(c, n)
  6. return res
  7. def shift(c, n):
  8. if c >= 'a' and c <= 'z':
  9. base = ord('a')
  10. elif c >= 'A' and c <= 'Z':
  11. base = ord('A')
  12. else:
  13. base = None
  14. if base is None:
  15. return c
  16. else:
  17. return chr((ord(c) + n - base) % 26 + base)
  18. str = input('the ceasar code u want to decode: ')
  19. for i in range(26):
  20. print(ceasar(str, i + 1), '\n\n')