// verified private ListOfDiffPairs GetChosenPlaintexts(UInt64 diff) { var result = new ListOfDiffPairs(); var plains = new UInt64[] { 8293413307042899260, 2417420169597379724, 7391341682234711011, 1294612218368839102, 3427586664725945798, 8120399254031000395, 4954062227563315182, 7287792347285229213, 6369026791565508293, 3497943451105456066, 635651540614717595, 466693664381143020 }; for (var i = 0; i < numberOfPlain; ++i) { var firstPlain = randomNumberGenerator.GetNextUInt64(); var secondPlain = firstPlain ^ diff; var firstCipher = feal4Encryptor.Encrypt(firstPlain, subKeys); var secondCipher = feal4Encryptor.Encrypt(secondPlain, subKeys); var first = new PlainCipherPair64(firstPlain, firstCipher); var second = new PlainCipherPair64(secondPlain, secondCipher); result.Add(Tuple.Create(first, second)); } return(result); }
// verified private static ListOfDiffPairs UndoLastRound(ListOfDiffPairs diffPairs, UInt32 subKey) { var result = new ListOfDiffPairs(); for (var i = 0; i < numberOfPlain; ++i) { UInt32 firstCipherLeft = Feal4Helper.GetLeftHalf(diffPairs[i].Item1.Cipher); UInt32 firstCipherRight = Feal4Helper.GetRightHalf(diffPairs[i].Item1.Cipher); UInt32 secondCipherLeft = Feal4Helper.GetLeftHalf(diffPairs[i].Item2.Cipher); UInt32 secondCipherRight = Feal4Helper.GetRightHalf(diffPairs[i].Item2.Cipher); firstCipherLeft = firstCipherRight; secondCipherLeft = secondCipherRight; firstCipherRight = Feal4Helper.Fbox(firstCipherLeft ^ subKey) ^ (Feal4Helper.GetLeftHalf(diffPairs[i].Item1.Cipher)); secondCipherRight = Feal4Helper.Fbox(secondCipherLeft ^ subKey) ^ (Feal4Helper.GetLeftHalf(diffPairs[i].Item2.Cipher)); var firstObj = new PlainCipherPair <UInt64>(diffPairs[i].Item1.Plain, Feal4Helper.Combine32BitHalfs(firstCipherLeft, firstCipherRight)); var secondObj = new PlainCipherPair <UInt64>(diffPairs[i].Item2.Plain, Feal4Helper.Combine32BitHalfs(secondCipherLeft, secondCipherRight)); result.Add(Tuple.Create(firstObj, secondObj)); } return(result); }
// verified private UInt32 CrackLastRound(UInt32 outDiff, ListOfDiffPairs chosenPlaintexts) { Console.WriteLine("CRACK LAST ROUND"); for (UInt32 fakeK = 0; ; ++fakeK) { var score = GetScore(outDiff, chosenPlaintexts, fakeK); if (score == numberOfPlain) { return(fakeK); } if (fakeK == UInt32.MaxValue) { break; } } throw new ArgumentException(); }
// verified private static int GetScore(UInt32 outDiff, ListOfDiffPairs chosenPlaintexts, UInt32 fakeK32) { var score = 0; for (var i = 0; i < numberOfPlain; ++i) { var cipherLeft = Feal4Helper.GetLeftHalf(chosenPlaintexts[i].Item1.Cipher) ^ Feal4Helper.GetLeftHalf(chosenPlaintexts[i].Item2.Cipher); var cipherRight = Feal4Helper.GetRightHalf(chosenPlaintexts[i].Item1.Cipher) ^ Feal4Helper.GetRightHalf(chosenPlaintexts[i].Item2.Cipher); var y = cipherRight; var z = cipherLeft ^ outDiff; var firstFakeLeft = Feal4Helper.GetLeftHalf(chosenPlaintexts[i].Item1.Cipher); var firstFakeRight = Feal4Helper.GetRightHalf(chosenPlaintexts[i].Item1.Cipher); var secondFakeLeft = Feal4Helper.GetLeftHalf(chosenPlaintexts[i].Item2.Cipher); var secondFakeRight = Feal4Helper.GetRightHalf(chosenPlaintexts[i].Item2.Cipher); var y0 = firstFakeRight; var y1 = secondFakeRight; var fakeInput0 = y0 ^ fakeK32; var fakeInput1 = y1 ^ fakeK32; var fakeOut0 = Feal4Helper.Fbox(fakeInput0); var fakeOut1 = Feal4Helper.Fbox(fakeInput1); var fakeDiff = fakeOut0 ^ fakeOut1; if (fakeDiff == z) { ++score; } else { break; } } return(score); }
// verified private ListOfDiffPairs UndoFinalOperation(ListOfDiffPairs data) { var result = new ListOfDiffPairs(); foreach (var item in data) { var firstLeftCipher = Feal4Helper.GetLeftHalf(item.Item1.Cipher); var firstRightCipher = Feal4Helper.GetRightHalf(item.Item1.Cipher) ^ firstLeftCipher; var secondLeftCipher = Feal4Helper.GetLeftHalf(item.Item2.Cipher); var secondRightCipher = Feal4Helper.GetRightHalf(item.Item2.Cipher) ^ secondLeftCipher; var firstRecombined = Feal4Helper.Combine32BitHalfs(firstLeftCipher, firstRightCipher); var secondRecombined = Feal4Helper.Combine32BitHalfs(secondLeftCipher, secondRightCipher); var firstObj = new PlainCipherPair64(item.Item1.Plain, firstRecombined); var secondObj = new PlainCipherPair64(item.Item2.Plain, secondRecombined); result.Add(Tuple.Create(firstObj, secondObj)); } return(result); }