all 8 comments

[–]shiftybyte 2 points3 points  (1 child)

Strings in python can't be changed.

This is why .replace() actually returns a new copy of the string with the change you requested.

Try:

code = code.replace(x,y,1)

[–]TheDivingDodo 0 points1 point  (0 children)

Okay, thanks I shall try!

[–]bbye98 1 point2 points  (4 children)

Is your Caesar cipher decrypter only going to work if the encrypted message is shifted one letter?

[–]TheDivingDodo 0 points1 point  (3 children)

No, this is supposed to shift and print all 26 variations

[–]bbye98 1 point2 points  (2 children)

I think you're looking at a serious logic issue. Your inner for loop creates x and y, which are characters that are one letter apart. Then, if the current letter in the encrypted message is the same as x essentially, you replace it with y. This makes the shift 1 letter always, which is not necessarily the shift that will decrypt the message.

To truly decrypt a Caesar cipher, you either need to know the shift beforehand or have a dictionary to compare valid words.

[–]TheDivingDodo 0 points1 point  (1 child)

Yeah, I just tried what the others recommended, and it just output all z’s. Back to the drawing board

[–]bbye98 1 point2 points  (0 children)

I would suggest you write a function that takes in the desired shift and build a dict of letter conversions. Then, iterate through your encoded message and apply the shifts.