Created
November 7, 2020 07:43
-
-
Save BiatuAutMiahn/59e6d26de5e49584ef5842373f3eb6b8 to your computer and use it in GitHub Desktop.
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
# Programming in Python 3.x | |
encoded = "IHPSLY PZ H NVVK IVF HUK OL'Z NVA H AVF" # Your encoded string | |
encoded_as_list = list(encoded) # Convert string to list of characters. | |
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
alphabet_as_list = list(alphabet) | |
decoded_as_list=[] # Create an empty list for our decoded characters. | |
decoded="" # Create an empty string for our decoded message. | |
for character in encoded_as_list: # Do something for each character. | |
if character.isalpha(): # Do something only if character is from the slphabet. | |
character_index = alphabet_as_list.index(character) # Get the numerical location of the character in the alphabet list. | |
character_index = character_index - 7 # Subtract 7 from that index. | |
if character_index < 0: # Do something if the index is less than zero. | |
character_index = character_index + 26 # Add 26 so that way we esentially wrap to the end of the alphabet. | |
# 26+(-7) is equal to 26-7. | |
new_character=alphabet_as_list[character_index] # Get the character at the new index | |
decoded_as_list.append(new_character) # Add that new character to our decoded list | |
else: # We get here is the character was never in the alphabet, like a space or punctuation. | |
decoded_as_list.append(character) # Add that non-alpha character to our decoded list. | |
# Finally convert our list of decoded characters into a string. | |
decoded=''.join(decoded_as_list) | |
# Now we will display that message in the commapt prompt | |
print(decoded) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment