MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / encryptMessage

Function encryptMessage

src/gamesbyexample/affinecipher.py:98–111  ·  view source on GitHub ↗

Encrypt the message using the key.

(key, message)

Source from the content-addressed store, hash-verified

96 return True
97
98def encryptMessage(key, message):
99 """Encrypt the message using the key."""
100 checkKey(key, 'encrypt')
101 keyA, keyB = getKeyPartsFromKey(key)
102 ciphertext = ''
103 for symbol in message:
104 if symbol in SYMBOLS:
105 # encrypt this symbol
106 symIndex = SYMBOLS.find(symbol)
107 newIndex = (symIndex * keyA + keyB) % len(SYMBOLS)
108 ciphertext += SYMBOLS[newIndex]
109 else:
110 ciphertext += symbol # just append this symbol unencrypted
111 return ciphertext
112
113
114def decryptMessage(key, message):

Callers 1

mainFunction · 0.70

Calls 2

getKeyPartsFromKeyFunction · 0.85
checkKeyFunction · 0.70

Tested by

no test coverage detected