This here is an attempt to a Hill Cipher, so far so good until multiplication of the 2nd and 3rd trigram. I really don't understand where my mistake is. Basicly what I have to do is a list multiplication.
with this code I create a list of list
key=[k[x:x+3] for x in xrange(0, len(k), 3)]
message=[m[x:x+1] for x in xrange(0, len(m), 1)]
key=[[16, 4, 11], [8, 6, 18], [15, 19, 15]]
message=[[0], [12], [8], [6], [15], [2], [15], [13], [3], [21], [2], [20], [15], [18], [8]]
My goal is to multiply every sublist or column in the key list
by the first three lists in the message list
UPDATE: I have made a nested loop as suggested and also I have divided the message list into chunks but still I can't make it work.
Nested loop
result = [[0,],
[0,],
[0],]
#Divide the matrizm into chunks
n = 3
chunks = (matrizm[x:x+n] for x in range(0,len(matrizm), n))
#Matrix multiplication
for triagram in chunks:
# iterate through rows of X
for i in range(len(matrizk)):
# iterate through columns of Y
for j in range(len(triagram[1])):
# iterate through rows of Y
for k in range(len(matrizk)):
result[i][j] += matrizk[i][k] * triagram[k][j]
With my current code I just can multiply the first 3 triagrams that by the way gives me a incorrect result.
My question is, having this two list how could I multiply the first 3 triagrams and then another 3 and so on until the end of matrizk list
matrizk = [[16, 4, 11], [8, 6, 18], [15, 19, 15]]
matrizk = [[0], [12], [8], [6], [15], [2], [15], [13], [3], [21], [2], [20], [15], [18], [3]]