private List <Tuple <PlainCipherPair32, PlainCipherPair32> > BuildGoodPair( DifferentialCharacteristic characteristic) { var cipher = new OneRoundSimpleCipher.OneRoundSimpleCipher(); var result = new List <Tuple <PlainCipherPair32, PlainCipherPair32> >(); for (var i = 0; i < 16; ++i) { var firstPlain = i; var firstPlainBytes = BitConverter.GetBytes(firstPlain); Array.Reverse(firstPlainBytes); var secondPlain = firstPlain ^ characteristic.InputDifferential; var secondPlainBytes = BitConverter.GetBytes(secondPlain); Array.Reverse(secondPlainBytes); if (characteristic.InputDifferential == 4 && characteristic.OutputDifferential == 7) { if (i == 11) { Console.WriteLine($"LOL {firstPlain} {secondPlain}"); } } var firstCipherBytes = cipher.Encrypt(firstPlainBytes, key); var secondCipherBytes = cipher.Encrypt(secondPlainBytes, key); firstCipherBytes[0] = firstCipherBytes[1] = firstCipherBytes[2] = 0; secondCipherBytes[0] = secondCipherBytes[1] = secondCipherBytes[2] = 0; firstCipherBytes[3] &= 0b00001111; secondCipherBytes[3] &= 0b00001111; Array.Reverse(firstCipherBytes); Array.Reverse(secondCipherBytes); var firstCipher = BitConverter.ToInt32(firstCipherBytes, 0); var secondCipher = BitConverter.ToInt32(secondCipherBytes, 0); if (characteristic.InputDifferential == 4 && characteristic.OutputDifferential == 7) { if (i == 11) { Console.WriteLine($"LOL {firstCipher} {secondCipher}"); } } if ((firstCipher ^ secondCipher) == characteristic.OutputDifferential) { var item1 = new PlainCipherPair32(firstPlain, firstCipher); var item2 = new PlainCipherPair32(secondPlain, secondCipher); result.Add(Tuple.Create(item1, item2)); } } return(result); }
private List <Tuple <int, int> > GetPossibleSuitableInputs( DifferentialCharacteristic differentialCharacteristic) { var result = new List <Tuple <int, int> >(); for (var i = 0; i < 16; ++i) { var secondValue = i ^ differentialCharacteristic.InputDifferential; if ((sBox[i] ^ sBox[secondValue]) == differentialCharacteristic.OutputDifferential) { result.Add(Tuple.Create(i, secondValue)); } } return(result); }