Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create empty string variable
- # Begin For Loop
- # Is this part of the string a letter? (A-Z, a-z)
- # Convert the letter to lower case and assign it to a variable
- # Is the (now lowercase) letter in the first half of the alphabet? ('m' is the midway point)
- # Set a variable called Distance to 13
- # Else, it's in the 2nd half
- # Set the Distance variable to -13
- # Encrypt the character (Don't really need to understand this line, or even the <= "m" stuff as Stuart gave it to us
- # Add the character to the end of our new string (We do this here so it happens for all the characters, whether we encrypted them or not)
- # End Loop
- # Return our string
- def rot13(s):
- result = ""
- for char in s:
- if char.isalpha():
- if char.lower() <= "m":
- distance = 13
- else:
- distance = -13
- char = chr(ord(char)+distance)
- result = result + char
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement