Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def caesar_encrypt(str, n):
- res = list(str)
- str_char_set = set(str)
- for i in str_char_set:
- if i.isalpha():
- new_char = ''
- if i.islower():
- new_char = chr(ord('a') + (((ord(i) - ord('a')) + n) % 26))
- else:
- new_char = chr(ord('A') + (((ord(i) - ord('A')) + n) % 26))
- for j in find(str, i):
- res[j] = new_char
- return ''.join(res)
- def find(s, ch):
- return [i for i, ltr in enumerate(s) if ltr == ch]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement