MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / hill_cipher

Function hill_cipher

projects/hill_cipher/encryption.py:21–37  ·  view source on GitHub ↗
(text, key_matrix)

Source from the content-addressed store, hash-verified

19
20
21def hill_cipher(text, key_matrix):
22 cipher_text = []
23 sum = 0
24 for i in range(3):
25 sum += (text[i] - 1) * key_matrix[i]
26 cipher_text.append(sum)
27
28 sum = 0
29 for i in range(3, 6):
30 sum += (text[i - 3] - 1) * key_matrix[i]
31 cipher_text.append(sum)
32
33 sum = 0
34 for i in range(6, 9):
35 sum += (text[i - 6] - 1) * key_matrix[i]
36 cipher_text.append(sum)
37 return cipher_text
38
39
40# to hill cipher the password and return the hill ciphered text

Callers 1

messageFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected