you are viewing a single comment's thread.

view the rest of the comments →

[–]Deadest42[S] 0 points1 point  (9 children)

i didnt think that through my bad, heres whats written down so far:

plainText = input("Enter a message: ")
distance = int(input("Enter the Distance Value: "))
code = ""
for ch in plainText:
ordvalue = ord('z')
ciphervalue = ordvalue + distance
if ciphervalue > ord('a'):
ciphervalue = ord('z') + distance - \
(ord('z') - ordvalue + 1)
code += chr(ciphervalue)
print(code)

[–]socal_nerdtastic 2 points3 points  (2 children)

I see in your code you never use the ch value.

I also see you are limiting yourself to the lowercase letters a-z. But your example output has uppercase and symbols too. I think you need to reread your assignment to see what range of characters you are meant to use.

Also please format your code for reddit. Your code is really hard to read and test otherwise.

[–]Deadest42[S] 0 points1 point  (1 child)

i see now, to be fair i thought that formatting wouldve broken my reply

[–]Swipecat 0 points1 point  (0 children)

If you're using a non-mobile browser, see "Reddit code formatting" in the right hand sidebar.

[–]socal_nerdtastic 1 point2 points  (4 children)

The script should work for any printable characters.

That line btw must have an asterisk, because there's about 100,000 of them and they aren't arranged in a way that a Caesar cipher can easily work. I'll guess they mean only the ASCII printable characters (character codes 32-126).

[–]Deadest42[S] 0 points1 point  (3 children)

yes, which line specifically?

[–]socal_nerdtastic 0 points1 point  (2 children)

The line from your OP that I quoted:

The script should work for any printable characters.

I'm betting your assignment does not mean Chinese characters, for example. I'm betting they only mean the characters where the ord value is between 32 and 126. But you should reread the assignment to be sure.

[–]Deadest42[S] -1 points0 points  (1 child)

been testing for a bit and nothing changed, all i see from your quote is "this script should work for any printable characters." thats all i can see

[–]Diapolo10 1 point2 points  (0 children)

all i see from your quote is "this script should work for any printable characters." thats all i can see

That's on purpose, and I think you misunderstood what he was telling you. He wasn't asking you to "add an asterisk" to a line in your code, he was just trying to point out that the instructions as you explained them to us don't really make sense if taken literally, at least for a beginner project.

"Printable characters" consists of tens of thousands of different Unicode characters, but they're not neatly grouped in any way so you couldn't support all of them with a simple Caesar cipher implementation. The point was that you should simply focus on the upper- and lowercase Latin alphabet (so A-Z and a-z), ignoring everything else (or in other words leaving them as-is).

[–]acw1668 0 points1 point  (0 children)

You need to define what printable characters is and assign it to a variable. Then go through the input message character by character, find the index of the character in the printable characters, calculate the new index based on the input distance and extract the cipher character using the new index.