>>> decryptMessage(6, 'Hlia rDsahrij') 'Harshil Darji'
(key, message)
| 28 | return ''.join(cipherText) |
| 29 | |
| 30 | def decryptMessage(key, message): |
| 31 | """ |
| 32 | >>> decryptMessage(6, 'Hlia rDsahrij') |
| 33 | 'Harshil Darji' |
| 34 | """ |
| 35 | numCols = math.ceil(len(message) / key) |
| 36 | numRows = key |
| 37 | numShadedBoxes = (numCols * numRows) - len(message) |
| 38 | plainText = [""] * numCols |
| 39 | col = 0; row = 0; |
| 40 | |
| 41 | for symbol in message: |
| 42 | plainText[col] += symbol |
| 43 | col += 1 |
| 44 | |
| 45 | if (col == numCols) or (col == numCols - 1) and (row >= numRows - numShadedBoxes): |
| 46 | col = 0 |
| 47 | row += 1 |
| 48 | |
| 49 | return "".join(plainText) |
| 50 | |
| 51 | if __name__ == '__main__': |
| 52 | import doctest |