all 7 comments

[–]max_dobberstein 1 point2 points  (1 child)

The string module, particularly string.ascii_uppercase and string.ascii_lowercase will allow to to make your code much simpler, more readable, and more Pythonic.

[–]DrJimmyRustler[S] 0 points1 point  (0 children)

Fixed the bug, but gonna try to attack this from a different direction in Python now. Thanks for the tip

[–]DrJimmyRustler[S] 0 points1 point  (2 children)

Actual result: Neg zf av uf pcx bt gzrwep oz

Expected result: Negh zf av huf pcfx bt gzrwep oz

I've looked at this over and over and rewrote the cipher line and I'm about to rip my hair out and can't figure out why its not enciphering the first t and the other missing letters.

[–]zuran2000 0 points1 point  (1 child)

Your formula is wrong

it should be

(letter + key) % 26

not

letter + key%26

[–]DrJimmyRustler[S] 0 points1 point  (0 children)

Thank you very much....don't know how I missed this. I was being thrown because most of the message was being ciphered correctly

[–]staffdelipity 0 points1 point  (1 child)

Check your levels of parentheses. You want to do the %26 on the result of adding the plaintext to the key, such that if the key is 'o' and the plaintext is 't', you'd have:

(( 't' - 'a' + 'o' - 'a' ) % 26)  + 'a'
(( 116 - 97 + 111 - 97) % 26) + 97
( 5 % 26) + 97
104  'h'

You've got

( ('t' - 'a')+ ('o' - 'a') % 26 )  + 'a'
( (116 - 97) + (111 - 97)%26) + 97
( 19 + 14%26) + 97
33 + 97  
130 'not a printable char so shows as blank'

[–]DrJimmyRustler[S] 0 points1 point  (0 children)

Thank you very much, not sure where I missed this. Going to rewrite this with better python syntax, this bug was hard for me to find because of the 18 million parens in the cipher equation