Skip to content

Commit

Permalink
Update rail_fence_cipher_decrypt.py
Browse files Browse the repository at this point in the history
Corrected bug when using messages with odd number of letters.
  • Loading branch information
rlvaugh authored Oct 25, 2019
1 parent 36b1840 commit 44ade66
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Chapter_4/rail_fence_cipher_decrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ def prep_ciphertext(ciphertext):
def split_rails(message):
"""Split message in two, always rounding UP for 1st row."""
row_1_len = math.ceil(len(message)/2)
row1 = (message[:row_1_len])
row2 = (message[row_1_len:])
row1 = (message[:row_1_len]).lower()
row2 = (message[row_1_len:]).lower()
return row1, row2

def decrypt(row1, row2):
"""Build list with every other letter in 2 strings & print."""
plaintext = []
for r1, r2 in itertools.zip_longest(row1, row2):
plaintext.append(r1.lower())
plaintext.append(r2.lower())
plaintext.append(r1)
plaintext.append(r2)
if None in plaintext:
plaintext.pop()
print("rail 1 = {}".format(row1))
Expand Down

0 comments on commit 44ade66

Please sign in to comment.