Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1.     # Create empty string variable
  2.     # Begin For Loop
  3.         # Is this part of the string a letter? (A-Z, a-z)
  4.              # Convert the letter to lower case and assign it to a variable
  5.              # Is the (now lowercase) letter in the first half of the alphabet? ('m' is the midway point)
  6.                   # Set a variable called Distance to 13
  7.              # Else, it's in the 2nd half
  8.                   # Set the Distance variable to -13
  9.              # Encrypt the character (Don't really need to understand this line, or even the <= "m" stuff as Stuart gave it to us
  10.         # 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)
  11.     # End Loop
  12.     # Return our string
  13.  
  14. def rot13(s):
  15.     result = ""
  16.     for char in s:
  17.         if char.isalpha():
  18.             if char.lower() <= "m":
  19.                 distance = 13
  20.             else:
  21.                 distance = -13
  22.             char = chr(ord(char)+distance)
  23.         result = result + char
  24.     return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement