public void MiniAESEncryption(HexMat hexMat) { //Console.WriteLine("ENCRYPTION"); //Console.WriteLine(); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.AddMiniRoundKey(subKeys[0].hexMat); //hexMat.DebugDraw(); //Console.WriteLine(); for (int i = 1; i < 3; i++) { //Console.WriteLine("ROUND " + (i + 1)); //Console.WriteLine(); hexMat.MiniSubBytes(); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.ShiftRows(); // hexMat.DebugDraw(); //Console.WriteLine(); hexMat.MiniMixColumns(); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.AddMiniRoundKey(subKeys[i].hexMat); //hexMat.DebugDraw(); //Console.WriteLine(); } }
public void XORWord(int x, HexMat toAdd, int toAddx) { for (int y = 0; y < size; y++) { hexMat[x, y] = Cypher.XOR(hexMat[x, y], toAdd.hexMat[toAddx, y]); } }
public void MiniAESDecryption(HexMat hexMat) { //Console.WriteLine("DECRYPTION"); //Console.WriteLine(); //hexMat.DebugDraw(); //Console.WriteLine(); for (int i = 2; i > 0; i--) { //Console.WriteLine("ROUND " + (i + 1)); //Console.WriteLine(); hexMat.AddMiniRoundKey(subKeys[i].hexMat); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.MiniMixColumns(); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.InvShiftRows(); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.InvMiniSubBytes(); //hexMat.DebugDraw(); //Console.WriteLine(); } hexMat.AddMiniRoundKey(subKeys[0].hexMat); //hexMat.DebugDraw(); //Console.WriteLine(); }
public void AESsetup(string hexText, string cypherKey) { mul2 = new string[16, 16]; MakeMulLookUpTable(mul2, preMul2); mul3 = new string[16, 16]; MakeMulLookUpTable(mul3, preMul3); mul9 = new string[16, 16]; MakeMulLookUpTable(mul9, preMul9); mul11 = new string[16, 16]; MakeMulLookUpTable(mul11, preMul11); mul13 = new string[16, 16]; MakeMulLookUpTable(mul13, preMul13); mul14 = new string[16, 16]; MakeMulLookUpTable(mul14, preMul14); this.cypherKey = new HexMat(cypherKey, 4, 2); subKeys = new HexMat[10]; GenerateSubKeys(); MakeHexMatsTable(hexText, 4, 2); }
public void MiniAESsetup(string hexText, string cypherKey) { //mul2 = new string[16, 16]; //MakeMulLookUpTable(mul2, preMul2); //mul3 = new string[16, 16]; //MakeMulLookUpTable(mul3, preMul3); //mul9 = new string[16, 16]; //MakeMulLookUpTable(mul9, preMul9); //mul11 = new string[16, 16]; //MakeMulLookUpTable(mul11, preMul11); //mul13 = new string[16, 16]; //MakeMulLookUpTable(mul13, preMul13); //mul14 = new string[16, 16]; //MakeMulLookUpTable(mul14, preMul14); this.cypherKey = new HexMat(cypherKey, 2, 1); GenerateMiniSubKeys(); MakeHexMatsTable(hexText, 2, 1); }
public HexMat MakeSubKey(HexMat keyBase, string rcon) { HexMat newKey = new HexMat(keyBase.size); for (int y = 0; y < keyBase.size; y++) { newKey.hexMat[0, y] = keyBase.hexMat[3, y]; } newKey.RotateWordOver(0); newKey.SubWordBytes(0); newKey.XORWord(0, keyBase, 0); newKey.hexMat[0, 0] = XOR(newKey.hexMat[0, 0], rcon); for (int x = 1; x < keyBase.size; x++) { for (int y = 0; y < keyBase.size; y++) { newKey.hexMat[x, y] = keyBase.hexMat[x, y]; } newKey.XORWord(x, newKey, x - 1); } return(newKey); }
public void MakeHexMatsTable(string text, int matSize, int tileSize) { int hexesSize = matSize * matSize * tileSize; int size = text.Length / hexesSize; if (text.Length % hexesSize != 0) { size += 1; } hexText = new HexMat[size]; for (int i = 0; i < size; i++) { string hex = ""; for (int s = i * hexesSize; s < (i + 1) * hexesSize; s++) { if (s < text.Length) { hex += text[s]; } else { hex += "0"; } } hexText[i] = new HexMat(hex, matSize, tileSize); } }
public HexMat(HexMat hexMatBase) { size = hexMatBase.size; hexMat = new string[size, size]; for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { hexMat[x, y] = hexMatBase.hexMat[x, y]; } } }
public HexMat MakeMiniSubKey(HexMat keyBase, string rcon) { HexMat newKey = new HexMat(keyBase.size); string hex = Cypher.MiniSubByte(keyBase.hexMat[1, 1]); hex = Cypher.MiniXOR(hex, keyBase.hexMat[0, 0]); hex = Cypher.MiniXOR(hex, rcon); newKey.hexMat[0, 0] = hex; newKey.hexMat[1, 0] = Cypher.MiniXOR(keyBase.hexMat[1, 0], hex); newKey.hexMat[0, 1] = Cypher.MiniXOR(keyBase.hexMat[0, 1], newKey.hexMat[1, 0]); newKey.hexMat[1, 1] = Cypher.MiniXOR(keyBase.hexMat[1, 1], newKey.hexMat[0, 1]); return(newKey); }
public void AESDecryption(HexMat hexMat) { //Console.WriteLine("DECRYPTION"); //Console.WriteLine(); //Console.WriteLine("FIRST ROUND"); //Console.WriteLine(); hexMat.AddRoundKey(subKeys[9].hexMat); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.InvShiftRows(); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.InvSubBytes(); //hexMat.DebugDraw(); //Console.WriteLine(); for (int i = 8; i >= 0; i--) { //Console.WriteLine("ROUND " + (10 - i)); //Console.WriteLine(); hexMat.AddRoundKey(subKeys[i].hexMat); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.InvMixColumns(); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.InvShiftRows(); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.InvSubBytes(); // hexMat.DebugDraw(); //Console.WriteLine(); } }
public void AESEncryption(HexMat hexMat) { //Console.WriteLine("ENCRYPTION"); //Console.WriteLine(); for (int i = 0; i < 9; i++) { //Console.WriteLine("ROUND " + (i + 1)); //Console.WriteLine(); hexMat.SubBytes(); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.ShiftRows(); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.MixColumns(); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.AddRoundKey(subKeys[i].hexMat); //hexMat.DebugDraw(); //Console.WriteLine(); } //Console.WriteLine("FINAL ROUND"); //Console.WriteLine(); hexMat.SubBytes(); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.ShiftRows(); //hexMat.DebugDraw(); //Console.WriteLine(); hexMat.AddRoundKey(subKeys[9].hexMat); //hexMat.DebugDraw(); //Console.WriteLine(); }