Last active
December 19, 2015 02:08
-
-
Save TomDeBeauchamp/5880401 to your computer and use it in GitHub Desktop.
This was my code for the Secret Messages problem from MIT's OCW Gentle Intro to Comp Sci via Python class, the first problem set, optional material.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
letter = "a" | |
# converts a letter to ascii code | |
ascii_code = ord(letter) | |
# converts ascii code to a letter | |
letter_res = chr(ascii_code) | |
encoded_phrase = "" | |
phrase = raw_input("Type the phrase you'd like to see encoded. ") | |
shift = int(raw_input("Type the shift value. ")) | |
for c in phrase: | |
if c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": | |
c = ((ord(c)-65 + shift)%26) | |
c = chr(c%26+65) | |
elif c in "abcdefghijklmnopqrstuvwxyz": | |
c = ((ord(c)-97 + shift)%26) | |
c = chr(c%26+97) | |
encoded_phrase = encoded_phrase + c | |
print encoded_phrase |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment