I have a list
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
I want to implement a Shift Cipher.
User input is a word and the number of places to shift.
Eg: If I choose the word hello and want a shift of 5, the new word would be mjqqt. The letter ‘h’ shifted by 5 letters becomes ‘m’, ‘e’ shifted by 5 letters becomes ‘j’ and so on.
I am able to do this as long as the
position of the original letter + shift amount is less than 26(len(alphabet)) at which point it reaches the end of the list and throws a list index out of range error.
So how do i get to continue counting from the beginning of the list after reaching the end.
Tried
new_letter = alphabet[len(alphabet) - (len(alphabet) - shift -1)]
which didnt give the correct letter after the shift
user26269337 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.