aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarvin Borner2019-06-17 12:29:44 +0200
committerMarvin Borner2019-06-17 12:29:44 +0200
commit95cd9cc51a15d9e21767f2267eb385ef3d1cdc3a (patch)
treed3868a80ad13ff09cd707652c776e9ad59285bb8
parentb701f7d49ef85ec10fe42aeb5bc548a00b3735c1 (diff)
Fixed strange array pointer behaviour
-rw-r--r--main.py25
-rw-r--r--sources3
2 files changed, 15 insertions, 13 deletions
diff --git a/main.py b/main.py
index 3de4da8..ac8d267 100644
--- a/main.py
+++ b/main.py
@@ -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
diff --git a/sources b/sources
index 9cc23ca..d913ed8 100644
--- a/sources
+++ b/sources
@@ -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