Chapter 9 – The Transposition Cipher, Decrypting 127
- plaintext = [''] * numOfColumns
The col and row variables point to where in the grid the next
character in the encrypted message will go.
- col = 0
- row = 0
- for symbol in message:
- plaintext[col] += symbol
- col += 1 # point to next column
If there are no more columns OR we're at a shaded box, go back to
the first column and the next row.
- if (col == numOfColumns) or (col == numOfColumns - 1 and row >=
numOfRows - numOfShadedBoxes): - col = 0
- row += 1
- return ''.join(plaintext)
If transpositionDecrypt.py is run (instead of imported as a module) call
the main() function.
- if name == 'main':
- main()
When you run the above program, it produces this output:
Common sense is not so common.|
If you want to decrypt a different message, or use a different key, change the value assigned to
the myMessage and myKey variables on lines 5 and 6.
How the Program Works..........................................................................................................................................
transpositionDecrypt.py
Transposition Cipher Decryption
http://inventwithpython.com/hacking (BSD Licensed)
- import math, pyperclip
- def main():
- myMessage = 'Cenoonommstmme oo snnio. s s c'
- myKey = 8