#! /usr/bin/python3.4

# Main file for AES
import subBytes, mixColumns, aes_base, shiftRows, segmess, addRoundKey


# !!! Bug !!! ShiftRows renvoie simplement le message passé en paramètre (regarde dans les print de DEBUG)
# AddRoundKey bug, je comprend pas trop =/

def aes():

	M_SIZE = 4
	msg = "plain.txt"
	key_size = 256
	key = [[184, 18, 29, 158], [123, 45, 253, 202], [254, 124, 64, 32], [86, 54, 48, 68]]

	m = segmess.segmess(msg)
	m_size = len(m)

	print("Encrytpion for %s" % (msg))
	print(m)

	# Tempo array definition
	c1 = m
	c2 = m
	c3 = m
	c4 = m

	# SubBytes:
	for cpt in range(m_size):
		c1[cpt] = subBytes.subBytes(m[cpt])

	# ShiftRows:
	for cpt in range(m_size):
		c2[cpt] = shiftRows.shiftRows(c1[cpt], key_size)
	
	# MixColumns:
	for cpt in range(m_size):
		c3[cpt] = mixColumns.mixColumns(c2[cpt])

	# AddRoundKey:
	for cpt in range(m_size):
		c4[cpt] = addRoundKey.addRoundKey(c3[cpt], key)

	print("Encrypted message:")
	print(c4)

	# Inversion:
	mc1 = m
	mc2 = m
	mc3 = m
	mc4 = m

	# InvAddRoundKey:
	for cpt in range(m_size):
		mc1[cpt] = addRoundKey.addRoundKey(c4[cpt], key)
	
	# InvMixColumns:
	for cpt in range(m_size):
		mc2[cpt] = mixColumns.invMixColumns(c1[cpt])

	# InvShiftRows:
	for cpt in range(m_size):
		mc3[cpt] = shiftRows.invShiftRows(mc2[cpt], key_size)
	
	# InvSubBytes:
	for cpt in range(m_size):
		mc4[cpt] = subBytes.invSubBytes(mc3[cpt])

	print("Uncrypted message:")
	print(mc4)

@@ -268,16 +268,38 @@
 def 
-aes(
+crypt(filename, k_size, pwd
 ):%0A
-%0A
 %09M_S
@@ -317,19 +317,16 @@
 g = 
-%22plain.txt%22
+filename
 %0A%09ke
@@ -338,11 +338,14 @@
 e = 
-256
+k_size
 %0A%09ke
@@ -976,22 +976,105 @@
 c4)%0A
+%09
 %0A%09# 
-Inversion:
+==================== Test: Inversion ===================%0A%09print(%22%5CnDecryption checking...%22)%0A
 %0A%09mc
@@ -1501,10 +1501,750 @@
 nt(%22
-Un
+Decrypted message:%22)%0A%09print(mc4)%0A%09%0A%0Adef decrypt(filename, k_size, pwd):%0A%0A%09M_SIZE = 4%0A%09msg = filename%0A%09key_size = k_size%0A%09key = %5B%5B184, 18, 29, 158%5D, %5B123, 45, 253, 202%5D, %5B254, 124, 64, 32%5D, %5B86, 54, 48, 68%5D%5D%0A%0A%09m = segmess.segmess(msg)%0A%09m_size = len(m)%0A%0A%09print(%22Decrytpion for %25s%22 %25 (msg))%0A%09print(m)%0A%0A%09# Inversion:%0A%09mc1 = m%0A%09mc2 = m%0A%09mc3 = m%0A%09mc4 = m%0A%0A%09# InvAddRoundKey:%0A%09for cpt in range(m_size):%0A%09%09mc1%5Bcpt%5D = addRoundKey.addRoundKey(m%5Bcpt%5D, key)%0A%09%0A%09# InvMixColumns:%0A%09for cpt in range(m_size):%0A%09%09mc2%5Bcpt%5D = mixColumns.invMixColumns(mc1%5Bcpt%5D)%0A%0A%09# InvShiftRows:%0A%09for cpt in range(m_size):%0A%09%09mc3%5Bcpt%5D = shiftRows.invShiftRows(mc2%5Bcpt%5D, key_size)%0A%09%0A%09# InvSubBytes:%0A%09for cpt in range(m_size):%0A%09%09mc4%5Bcpt%5D = subBytes.invSubBytes(mc3%5Bcpt%5D)%0A%0A%09print(%22De
 cryp

clear code