Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. def caesar_encrypt(str, n):
  2. res = list(str)
  3. str_char_set = set(str)
  4. for i in str_char_set:
  5. if i.isalpha():
  6. new_char = ''
  7. if i.islower():
  8. new_char = chr(ord('a') + (((ord(i) - ord('a')) + n) % 26))
  9. else:
  10. new_char = chr(ord('A') + (((ord(i) - ord('A')) + n) % 26))
  11. for j in find(str, i):
  12. res[j] = new_char
  13. return ''.join(res)
  14.  
  15. def find(s, ch):
  16. return [i for i, ltr in enumerate(s) if ltr == ch]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement