Caesars Cipher using String

HEY HI, I was writing this string for Caesars cipher. I tried changing the k=18 for fun. Why is it showing out of range for 18 alone…while it works fine for rest of nos.?

Because you forgot the letter g, so the alphabet went from 26 to 25 characters :slight_smile:

4 Likes

ohh shoot…sorry didnt notice
Thanks :smile:

2 Likes

It happens to the best of us :smiley:
Please mark the post as solution so this thread will close.

4 Likes

In addition, instead of doing:

t = ""
t = t+something

you can just do

t = ""
t +=something

It might also help to clean your code if you loop through each letter in your message like this:

for letter in a:
    t += alpha[(alpha.index(letter) + k) % len(alpha)]

I also changed the constant 26 to len(alpha) because that way you can add MORE characters if you wanted.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.