public stateBlock(stateBlock other) { _data = new byte[4, 4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { _data[i, j] = other._data[i, j]; } } }
public List <stateBlock> addRoundKey(List <stateBlock> _datas, stateBlock Key) { foreach (stateBlock item in _datas) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { item._data[i, j] ^= Key._data[i, j]; } } } return(_datas); }
internal void subByte(stateBlock item) { int i, j, ri, ci; i = j = ri = ci = 0; for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { ri = item._data[i, j] >> 4; ci = item._data[i, j] & 0x0F; item._data[i, j] = S_BOX[ri, ci]; } } }
public void subLocationRev(stateBlock b) { int ri, ci; ri = 0; ci = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { ri = b._data[i, j] >> 4; ci = b._data[i, j] & 0x0F; b._data[i, j] = INVERSE_S_BOX[ri, ci]; } } }
public List <stateBlock> mixColumns(List <stateBlock> _datas) { List <stateBlock> result = new List <stateBlock>(); foreach (stateBlock item in _datas) { stateBlock T = new stateBlock(item); for (int c = 0; c < 4; c++) { T._data[0, c] = (Byte)(_Rijndael.mixCol(0x02, item._data[0, c]) ^ _Rijndael.mixCol(0x03, item._data[1, c]) ^ item._data[2, c] ^ item._data[3, c]); T._data[1, c] = (Byte)(item._data[0, c] ^ _Rijndael.mixCol(0x02, item._data[1, c]) ^ _Rijndael.mixCol(0x03, item._data[2, c]) ^ item._data[3, c]); T._data[2, c] = (Byte)(item._data[0, c] ^ item._data[1, c] ^ _Rijndael.mixCol(0x02, item._data[2, c]) ^ _Rijndael.mixCol(0x03, item._data[3, c])); T._data[3, c] = (Byte)(_Rijndael.mixCol(0x03, item._data[0, c]) ^ item._data[1, c] ^ item._data[2, c] ^ _Rijndael.mixCol(0x02, item._data[3, c])); } result.Add(T); } return(result); }
public void HackProcAes1(string fileName, string chiper, string output) { AESEncrypte aesDyc = new AESEncrypte(); List <stateBlock> _temp = createDataState(createByteArr(fileName)); List <stateBlock> testChiper = createDataState(createByteArr(chiper)); Stopwatch stopwatch = new Stopwatch(); _temp = aesDyc.mixColumns(aesDyc.shiftRow(aesDyc.subByte(_temp))); stopwatch.Start(); byte[] block = new byte[16]; List <stateBlock> TheKey = new List <stateBlock>(); for (int countState = 0; countState < 1; countState++) { stateBlock s = new stateBlock(block); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { s._data[i, j] = (byte)(testChiper[countState]._data[i, j] ^ _temp[countState]._data[i, j]); } } TheKey.Add(s); } stopwatch.Stop(); Console.WriteLine("Total Time to Hacking: " + stopwatch.Elapsed.ToString()); byte[] curr = BuildKey(TheKey); File.WriteAllBytes(output, curr); }
public void HackProcAes3(string fileName, string chiper, string output) { Stopwatch stopwatch = new Stopwatch(); List <stateBlock> _temp = createDataState(createByteArr(fileName)); List <stateBlock> testChiper = createDataState(createByteArr(chiper)); byte[] Key = new byte[16]; stateBlock Null_State = new stateBlock(Key); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { Null_State._data[i, j] = (byte)(255); } } stateBlock theKey = new stateBlock(Key); int[] res; for (int i = 0; i < 4; i++) { res = noMoveChiper(_temp[0]._data[0, i], testChiper[0]._data[0, i]); theKey._data[0, i] = (byte)res[2]; } res = noMoveChiper(_temp[0]._data[1, 0], testChiper[0]._data[1, 1]); theKey._data[1, 1] = (byte)res[2]; res = noMoveChiper(_temp[0]._data[1, 1], testChiper[0]._data[1, 2]); theKey._data[1, 2] = (byte)res[2]; res = noMoveChiper(_temp[0]._data[1, 2], testChiper[0]._data[1, 3]); theKey._data[1, 3] = (byte)res[2]; res = noMoveChiper(_temp[0]._data[1, 3], testChiper[0]._data[1, 0]); theKey._data[1, 0] = (byte)res[2]; res = noMoveChiper(_temp[0]._data[2, 0], testChiper[0]._data[2, 2]); theKey._data[2, 2] = (byte)res[2]; res = noMoveChiper(_temp[0]._data[2, 1], testChiper[0]._data[2, 3]); theKey._data[2, 3] = (byte)res[2]; res = noMoveChiper(_temp[0]._data[2, 2], testChiper[0]._data[2, 0]); theKey._data[2, 0] = (byte)res[2]; res = noMoveChiper(_temp[0]._data[2, 3], testChiper[0]._data[2, 1]); theKey._data[2, 1] = (byte)res[2]; res = noMoveChiper(_temp[0]._data[3, 0], testChiper[0]._data[3, 3]); theKey._data[3, 3] = (byte)res[2]; res = noMoveChiper(_temp[0]._data[3, 1], testChiper[0]._data[3, 0]); theKey._data[3, 0] = (byte)res[2]; res = noMoveChiper(_temp[0]._data[3, 2], testChiper[0]._data[3, 1]); theKey._data[3, 1] = (byte)res[2]; res = noMoveChiper(_temp[0]._data[3, 3], testChiper[0]._data[3, 2]); theKey._data[3, 2] = (byte)res[2]; List <stateBlock> Pk = new List <stateBlock>(); Pk.Add(Null_State); Pk.Add(Null_State); Pk.Add(theKey); byte[] ToWrite = BuildKey(Pk); File.WriteAllBytes(output, ToWrite); }