private byte[] InverseSecondRound(byte[] cipherText, byte[] roundKey) { var inversedRoundKey = Aes16Helper.AddRoundKey(cipherText, roundKey); var inversedShiftRow = Aes16Helper.ShiftRow(inversedRoundKey); var inversedNibbleSubstitution = Aes16Helper.InverseNibbleSubstitution(inversedShiftRow); return(inversedNibbleSubstitution); }
private byte[] GetThirdSubKey(byte[] key) { var secondSubKey = GetSecondSubKey(key); var firstByte = (byte)(secondSubKey[0] ^ 0b00110000 ^ Aes16Helper.SubNib(Aes16Helper.RotNib(secondSubKey[1]))); var secondByte = (byte)(firstByte ^ secondSubKey[1]); return(new[] { firstByte, secondByte }); }
private byte[] InverseFirstRound(byte[] firstRoundCipherText, byte[] roundKey) { var inversedRoundKey = Aes16Helper.AddRoundKey(firstRoundCipherText, roundKey); var inversedMixColumns = Aes16Helper.InverseMixColumns(inversedRoundKey); var inversedShiftRow = Aes16Helper.ShiftRow(inversedMixColumns); var inversedNibbleSubstitution = Aes16Helper.InverseNibbleSubstitution(inversedShiftRow); return(inversedNibbleSubstitution); }
private byte[] GetSecondRoundResult(byte[] firstRoundResult, byte[] subKey) { var nibbled = Aes16Helper.NibbleSubstitution(firstRoundResult); var secondFourBitsOfFirstByte = (byte)(nibbled[0] & 0b00001111); var secondFourBitsOfSecondByte = (byte)(nibbled[1] & 0b00001111); var newFirstByte = (byte)((nibbled[0] & 0b11110000) | secondFourBitsOfSecondByte); var newSecondByte = (byte)((nibbled[1] & 0b11110000) | secondFourBitsOfFirstByte); var shiftedBytes = new[] { newFirstByte, newSecondByte }; return(Aes16Helper.AddRoundKey(shiftedBytes, subKey)); }
private byte[] GetFirstRoundResult(byte[] zeroRoundResult, byte[] roundKey) { // Nibble substitution var nibbled = Aes16Helper.NibbleSubstitution(zeroRoundResult); // Shift row var shiftedRowBytes = Aes16Helper.ShiftRow(nibbled); var mixedBytes = Aes16Helper.MixColumns(shiftedRowBytes); return(Aes16Helper.AddRoundKey(new[] { mixedBytes[0], mixedBytes[1] }, roundKey)); }
private byte[] GetSecondSubKey(byte[] key) { var firstSubKey = GetFirstSubKey(key); var a = (byte)(firstSubKey[0] ^ 0b10000000); var c = Aes16Helper.RotNib(firstSubKey[1]); var b = Aes16Helper.SubNib(c); var firstByte = (byte)(a ^ b); var secondByte = (byte)(firstByte ^ firstSubKey[1]); return(new[] { firstByte, secondByte }); }
private byte[] InverseZeroRound(byte[] zeroRoundCipherText, byte[] roundKey) { var inversedRoundKey = Aes16Helper.AddRoundKey(zeroRoundCipherText, roundKey); return(inversedRoundKey); }
private byte[] GetZeroRoundResult(byte[] plainText, byte[] roundKey) { return(Aes16Helper.AddRoundKey(plainText, roundKey)); }