0

Caesar cipher

Apparently, I’m trying to recreate the Caesar cipher in python. However, the “shift” function isn’t working. It’s supposed to add the same key to every letter in the message. (excluding spaces) https://sololearn.com/compiler-playground/c2Iz12HWaez5/?ref=app

7th May 2024, 9:27 PM
Annihilate
Annihilate - avatar
9 ответов
+ 2
Annihilate If you want to update an element in a list, you must provide the index of the element. l=list(lst) for i in l: if i not in alphabet: l[i]=" " continue else: l[i]=alphabet.index(i) In this part of code, the "i" in l[i] is a string...
10th May 2024, 11:52 PM
Wong Hei Ming
Wong Hei Ming - avatar
+ 4
Annihilate Welcome back to Python. There are many caesar cipher code in Code Bits for you to study. I also created one a month ago (well... Caesar is misspelled in the name...) As Wilbur Jaywright suggested, using a alphabet variable can save many lines of code and add readability. And in your code, you forget to handle "space" character which is in your "shift" to-do list. Maybe this little code helps you recall what you learned. https://sololearn.com/compiler-playground/cm7JC4N4AqfP/?ref=app
8th May 2024, 3:40 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 3
You didn’t indent any code under shift, so the function does nothing. Also, generally you should not be using more than five or so if statements in a row. You could make this code far more space efficient with an ALPHABET variable set to a string of the alphabet in order, and calling its index method.
8th May 2024, 12:42 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
+ 1
Wilbur Jaywright I'm replying to the question as OP updated his code and mentioned the "let_to_num" function is not working...
10th May 2024, 3:57 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
Wong Hei Ming Nice, but I want to break it down into these functions
9th May 2024, 8:52 PM
Annihilate
Annihilate - avatar
0
Also, now the let_to_num function isn’t working
9th May 2024, 10:52 PM
Annihilate
Annihilate - avatar
0
Wong Hei Ming please ask that in a new question post, as it does not seem related to this one.
10th May 2024, 2:59 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
Wong Hei Ming i is holding each character in the message. (including spaces)
10th May 2024, 9:40 PM
Annihilate
Annihilate - avatar
0
Wong Hei Ming Ok, got it
14th May 2024, 9:24 PM
Annihilate
Annihilate - avatar