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

Function decryptMessage

ciphers/affine_cipher.py:50–65  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

48 return cipherText
49
50def 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
67def getRandomKey():
68 while True:

Callers 1

mainFunction · 0.70

Calls 3

getKeyPartsFunction · 0.85
checkKeysFunction · 0.85
findMethod · 0.80

Tested by

no test coverage detected