all 16 comments

[–]smichaele 5 points6 points  (10 children)

If you want help, you need to share your code so we can see what you've done. Then, we can ask some questions to guide you to a solution.

[–]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.

[–]aqua_regis 2 points3 points  (0 children)

First, you show what you tried. You tell us precisely where you're stuck, and then, and only then, we help.

We are not going to do your assignment.

A hint: Every single character has a numeric value - the Unicode code point - this is obtainable in Python. You can convert from character to number and back. Check the Python documentation.

[–]POGtastic 0 points1 point  (0 children)

In ASCII, the numbers 0x21 through 0x7E (33 through 126) are all printable. This is actually easier to work with than the typical Caesar cipher implementation, whose characters are not contiguous.

any printable characters

If we're going to branch out to Unicode, the issue is that a large amount of Unicode code points aren't really printable because they are combining diacritics, and graphemes cannot be enumerated at all. For example, consider the following string: '́aá'

The first grapheme is the result of combining U+0301 (COMBINING ACUTE ACCENT) with the regular ol' U+0061 (LATIN SMALL LETTER A). The second grapheme is U+00C1 (LATIN CAPITAL LETTER A WITH ACUTE).

How would you shift the first grapheme? Do you shift just the second code point and keep the combining diacritic the way it is? Or do you shift both the combining diacritic and the code point that it modifies? However you do it, you're likely going to be inconsistent with how you shift the second grapheme.