Caesar shift
Caesar shift, aka Caesar cipher, is a simple encrypting algorithm that takes any letter from the alphabet and instead replaces it with the (default) 3rd next letter in the alphabet. The number can be changed. If the shift in number causes it to go past the last letter in the alphabet, it will simply start back from the start again.
All that had to be done is to put the alphabet into a list, put the given sentence into a list, find the individual letter's indexes in the alphabet, and add 3 to that index to get the shifted letter, then append it to the output string. For the search of the letter from the input in the alphabet list, I imported and used my linear search from before:
from Searches import linear
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
alphabet_list = []
for x in range(0, len(alphabet)):
alphabet_list.append(alphabet[x])
get = input("Enter your sentence: ").upper()
output = ""
for x in range(0, len(get)):
value = linear(alphabet_list, get[x])
if value == None:
output += get[x]
else:
value += 3
if value > 26:
value -= 26
output += alphabet_list[value]
print(output)
Comments
Post a Comment