public static void Decryption(String bitStringForCipherText, String[] key) { var pmt = new Permutation(); var p = new Program(); var BitStringForCipherText = pmt.GenerateIP(bitStringForCipherText); String L0 = BitStringForCipherText.Substring(0, 32); String R0 = BitStringForCipherText.Substring(32, 32); String L1 = "", R1 = ""; for (var i = 0; i < 16; i++) { L1 = R0; var expansioned48BitString = p.expansionPermutation(R0); var inputForSBox = p.XOR(expansioned48BitString, key[15 - i]); var s = new SBox(inputForSBox); var sBox32BitOutputString = s.getOutput(); var pBoxPermutation32BitOutput = pmt.pBox(sBox32BitOutputString); R1 = p.XOR(L0, pBoxPermutation32BitOutput); R0 = R1; L0 = L1; } var BitStringForPlainText = R0 + L0; BitStringForPlainText = pmt.GenerateIP_1(BitStringForPlainText); Console.WriteLine("\n\nPlain Text For Given Cipher Text Bit : \t" + BitStringForPlainText); Console.Read(); }
static void Main(string[] args) { var program = new Program(); var permutation = new Permutation(); Console.WriteLine(program.BitStringToString("0000000011111111100000000110011000000000111111110111100001010101")); var K = new String[17]; var KeyOfFourtyEigntBit = new String[16]; //var M = "0000000100100011010001010110011110001001101010111100110111101111"; var M = program.StringToBitString("12345678"); Console.WriteLine("Given Plain Text \t\t\t" + M); var IP = permutation.GenerateIP(M); String L0 = IP.Substring(0, 32), R0 = IP.Substring(32, 32); K[0] = program.generateKeyOf56Bit(); //Console.WriteLine("First Key "+K[0]); String L1 = "", R1 = ""; for (int i = 0; i < 16; i++) { L1 = R0; var expansioned48BitString = ""; expansioned48BitString = program.expansionPermutation(R0); K[i + 1] = program.ShiftKey(K[i], program.KeyShiftAmount(i)); var inputForSBox = ""; KeyOfFourtyEigntBit[i] = program.PC2Permutation(K[i + 1]); inputForSBox = program.XOR(expansioned48BitString, KeyOfFourtyEigntBit[i]); var sBox32BitOutputString = ""; var s = new SBox(inputForSBox); sBox32BitOutputString = s.getOutput(); var pBoxPermutation32BitOutput = ""; pBoxPermutation32BitOutput = permutation.pBox(sBox32BitOutputString); R1 = program.XOR(L0, pBoxPermutation32BitOutput); R0 = R1; L0 = L1; } var BitStringOfCipherText = R0 + L0; BitStringOfCipherText = permutation.GenerateIP_1(BitStringOfCipherText); Console.WriteLine("\n\nCipher Text For Given Plain Text : \t" + BitStringOfCipherText); //var CipherText = program.BitStringToString(BitStringOfCipherText); //Console.WriteLine("\nThe Cipher Text : " + BitStringOfCipherText + "\n\n"); Decryption(BitStringOfCipherText, KeyOfFourtyEigntBit); Console.WriteLine(); Console.Read(); }