>>> encryptMessage(4545, 'The affine cipher is a type of monoalphabetic substitution cipher.') 'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF{xIp~{HL}Gi'
(key, message)
| 32 | sys.exit('Key A %s and the symbol set size %s are not relatively prime. Choose a different key.' % (keyA, len(SYMBOLS))) |
| 33 | |
| 34 | def encryptMessage(key, message): |
| 35 | ''' |
| 36 | >>> encryptMessage(4545, 'The affine cipher is a type of monoalphabetic substitution cipher.') |
| 37 | 'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF{xIp~{HL}Gi' |
| 38 | ''' |
| 39 | keyA, keyB = getKeyParts(key) |
| 40 | checkKeys(keyA, keyB, 'encrypt') |
| 41 | cipherText = '' |
| 42 | for symbol in message: |
| 43 | if symbol in SYMBOLS: |
| 44 | symIndex = SYMBOLS.find(symbol) |
| 45 | cipherText += SYMBOLS[(symIndex * keyA + keyB) % len(SYMBOLS)] |
| 46 | else: |
| 47 | cipherText += symbol |
| 48 | return cipherText |
| 49 | |
| 50 | def decryptMessage(key, message): |
| 51 | ''' |
no test coverage detected