>>> decryptMessage(4545, 'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF{xIp~{HL}Gi') 'The affine cipher is a type of monoalphabetic substitution cipher.'
(key, message)
| 48 | return cipherText |
| 49 | |
| 50 | def decryptMessage(key, message): |
| 51 | ''' |
| 52 | >>> decryptMessage(4545, 'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF{xIp~{HL}Gi') |
| 53 | 'The affine cipher is a type of monoalphabetic substitution cipher.' |
| 54 | ''' |
| 55 | keyA, keyB = getKeyParts(key) |
| 56 | checkKeys(keyA, keyB, 'decrypt') |
| 57 | plainText = '' |
| 58 | modInverseOfkeyA = cryptoMath.findModInverse(keyA, len(SYMBOLS)) |
| 59 | for symbol in message: |
| 60 | if symbol in SYMBOLS: |
| 61 | symIndex = SYMBOLS.find(symbol) |
| 62 | plainText += SYMBOLS[(symIndex - keyB) * modInverseOfkeyA % len(SYMBOLS)] |
| 63 | else: |
| 64 | plainText += symbol |
| 65 | return plainText |
| 66 | |
| 67 | def getRandomKey(): |
| 68 | while True: |
no test coverage detected