diff options
author | Marvin Borner | 2019-06-17 12:29:44 +0200 |
---|---|---|
committer | Marvin Borner | 2019-06-17 12:29:44 +0200 |
commit | 95cd9cc51a15d9e21767f2267eb385ef3d1cdc3a (patch) | |
tree | d3868a80ad13ff09cd707652c776e9ad59285bb8 | |
parent | b701f7d49ef85ec10fe42aeb5bc548a00b3735c1 (diff) |
Fixed strange array pointer behaviour
-rw-r--r-- | main.py | 25 | ||||
-rw-r--r-- | sources | 3 |
2 files changed, 15 insertions, 13 deletions
@@ -31,23 +31,24 @@ def shift_matrix(matrix): return matrix -def key_expansion(round_key): - round_keys = [round_key] - print(round_key) +def key_expansion(key_matrix): + round_keys = [key_matrix] + round_key = key_matrix[:] for r in range(0, 10): + new_key = round_key.copy() last = round_key[3] - - round_key[3] = round_last(round_key[3], r) - round_key[0] = xor_matrix(round_key[0], round_key[3]) - round_key[1] = xor_matrix(round_key[1], round_key[0]) - round_key[2] = xor_matrix(round_key[2], round_key[1]) - round_key[3] = xor_matrix(last, round_key[2]) - - print(round_key) - round_keys.append(round_key) + new_key[3] = round_last(new_key[3], r) + new_key[0] = xor_matrix(new_key[0], new_key[3]) + new_key[1] = xor_matrix(new_key[1], new_key[0]) + new_key[2] = xor_matrix(new_key[2], new_key[1]) + new_key[3] = xor_matrix(last, new_key[2]) + round_key = new_key + round_keys += [new_key] + return round_keys def xor_matrix(first, second): + first = first.copy() for i in range(4): first[i] = first[i] ^ second[i] return first @@ -1,3 +1,4 @@ http://www.moserware.com/2009/09/stick-figure-guide-to-advanced.html https://kavaliro.com/wp-content/uploads/2014/03/AES.pdf -https://en.wikipedia.org/wiki/Rijndael_S-box
\ No newline at end of file +https://en.wikipedia.org/wiki/Rijndael_S-box +http://csrc.nist.gov/archive/aes/rijndael/Rijndael-ammended.pdf
\ No newline at end of file |