Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def rot13(s):
- """"
- Takes a string and applies rot13. Returns rotated string.
- Uses arrays of each letter + two dictionaries.
- The arrays are used to check if the letter is upper or lower.
- If the letter is upper or lowercase, the appropriate value is found in the dictionary,
- and 12 is added.
- If temp is over 26, 26 is subtracted.
- """
- lower = ['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']
- upper = ['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']
- string = ''
- ldict = {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4, 'g': 7, 'f': 6, 'i': 9, 'h': 8, 'k': 11, 'j': 10, 'm': 13, 'l': 12, 'o': 15, 'n': 14, 'q': 17, 'p': 16, 's': 19, 'r': 18, 'u': 21, 't': 20, 'w': 23, 'v': 22, 'y': 25, 'x': 24, 'z': 26}
- updict = {'A': 1, 'C': 3, 'B': 2, 'E': 5, 'D': 4, 'G': 7, 'F': 6, 'I': 9, 'H': 8, 'K': 11, 'J': 10, 'M': 13, 'L': 12, 'O': 15, 'N': 14, 'Q': 17, 'P': 16, 'S': 19, 'R': 18, 'U': 21, 'T': 20, 'W': 23, 'V': 22, 'Y': 25, 'X': 24, 'Z': 26}
- for letter in s:
- if letter in lower:
- temp = ldict[letter] + 12
- if temp <= 25:
- string += lower[temp]
- else:
- string += lower[temp - 26]
- elif letter in upper:
- temp = updict[letter] + 12
- if temp <= 25:
- string += upper[temp]
- else:
- string += upper[temp - 26]
- else:
- string += letter
- return string
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement