rlvaugh / Impractical_Python_Projects

Code & supporting files for chapters in book
408 stars 270 forks source link

Chapter 4: Project 9 #4

Closed dwanneruchi closed 4 years ago

dwanneruchi commented 5 years ago

I noticed that when working with a ciphertext of odd numbers we receive an error with the rail_fence_cipher_decrypt.py file. I copied your code from this github, but could be missing something.

For a reproducible example you could update line 22 to:

ciphertext = HLOEL

Running rail_fence_cipher_decrypt.py should output Hello but instead we get an error due to attempting touse .lower() on a NoneType object (due to the itertools.zip_longest adding a None in the odd situation).

Do you get the same error? I am guessing a solution could be to add some logic to skip past Nonetype.

I put together a little solution that is working, but would be curious of a better approach. Overview: If r2 is None, then I overwrite the value with a letter and also update variable "odd" to be True. Then, changed your logic test to be a test where if odd = true then run the .pop() on the plaintext to remove the arbitrary letter.

bandage

This allows me to get a plaintext output of Hello, but again curious if there are better approaches! Still loving the book, had to slow down a bit due to work but learning a bunch!

rlvaugh commented 4 years ago

Thank you for catching this and apologies for the late response. You can also just change where the .lower() is applied (lines marked with ###):

Capture