Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def caesar_cipher(_str, shift):
- alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
- numbers = [str(x) for x in range(10)] # creates an array of numbers 0-9
- _str = list(_str.lower()) # makes input string a list
- for i in range(len(_str)):
- if _str[i] in alphabet:
- helper(alphabet, i, shift, _str)
- elif _str[i] in numbers:
- helper(numbers, i, shift, _str)
- return ''.join(_str)
- def helper(arr, i, shift, _arr):
- index = arr.index(_arr[i])
- while index+shift > len(arr)-1:
- shift -= len(arr)
- while index+shift < 0:
- shift += len(arr)
- _arr[i] = arr[index+shift]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement