MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / encryptMessage

Function encryptMessage

ciphers/affine_cipher.py:34–48  ·  view source on GitHub ↗

>>> 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)

Source from the content-addressed store, hash-verified

32 sys.exit('Key A %s and the symbol set size %s are not relatively prime. Choose a different key.' % (keyA, len(SYMBOLS)))
33
34def 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
50def decryptMessage(key, message):
51 '''

Callers 1

mainFunction · 0.70

Calls 3

getKeyPartsFunction · 0.85
checkKeysFunction · 0.85
findMethod · 0.80

Tested by

no test coverage detected