private string Decryption(char[] encyptedMessage) { string OriginalMessage = ""; this.SetBlocksOfencyptedMessage(encyptedMessage); bool[] msgtIP; bool[] LHalf = new bool[32]; bool[] RHalf = new bool[32]; bool[] REtable; bool[] inpXORmsg; bool[] sboxOutput = new bool[32]; bool[] sboxCellInput = new bool[6]; bool[] sboxP; bool[] RXorL = null; bool[] encyMsg = new bool[64]; bool[] encyMsgP = new bool[64]; byte[] encyMsgByte; for (int i = 0; i < this.blocks.GetLength(0); i++) { msgtIP = this.Permutation(this.IP, this.blocks[i]); Array.Copy(msgtIP, 0, LHalf, 0, LHalf.Length); Array.Copy(msgtIP, LHalf.Length, RHalf, 0, RHalf.Length); for (int j = 0; j < 16; j++) { REtable = this.Permutation(this.ETable, RHalf); inpXORmsg = BitManipulator.XOR(REtable, this.allKeys[16 - j - 1]); for (int k = 0, l = 0; k < inpXORmsg.Length; k += 6, l++) { Array.Copy(inpXORmsg, k, sboxCellInput, 0, sboxCellInput.Length); bool[] temp = this.Sbox(sboxCellInput, this.sboxes[l]); Array.Copy(temp, 0, sboxOutput, 4 * l, 4); } sboxP = this.Permutation(this.P, sboxOutput); RXorL = BitManipulator.XOR(sboxP, LHalf); LHalf = RHalf; RHalf = RXorL; } RHalf = LHalf; LHalf = RXorL; Array.Copy(LHalf, 0, encyMsg, 0, LHalf.Length); Array.Copy(RHalf, 0, encyMsg, LHalf.Length, RHalf.Length); encyMsgP = this.Permutation(this.IP1, encyMsg); encyMsgByte = BitManipulator.BoolToByte(encyMsgP); Array.Reverse(encyMsgByte); OriginalMessage += Encoding.ASCII.GetString(encyMsgByte); } return(OriginalMessage); }
private char[] Encryption(string Msg) { this.SetBlocksOfPlainText(Msg); bool[] msgtIP; bool[] LHalf = new bool[32]; bool[] RHalf = new bool[32]; bool[] REtable; bool[] inpXORmsg; bool[] sboxOutput = new bool[32]; bool[] sboxCellInput = new bool[6]; bool[] sboxP; bool[] RXorL = null; bool[] encyMsg = new bool[64]; bool[] encyMsgP = new bool[64]; byte[] encyMsgByte; char[] encyMsgChar = new char[this.blocks.GetLength(0) * 8]; for (int i = 0; i < this.blocks.GetLength(0); i++) { msgtIP = this.Permutation(this.IP, this.blocks[i]); Array.Copy(msgtIP, 0, LHalf, 0, LHalf.Length); Array.Copy(msgtIP, LHalf.Length, RHalf, 0, RHalf.Length); for (int j = 0; j < 16; j++) { REtable = this.Permutation(this.ETable, RHalf); inpXORmsg = BitManipulator.XOR(REtable, this.allKeys[j]); for (int k = 0, l = 0; k < inpXORmsg.Length; k += 6, l++) { Array.Copy(inpXORmsg, k, sboxCellInput, 0, sboxCellInput.Length); bool[] temp = this.Sbox(sboxCellInput, this.sboxes[l]); Array.Copy(temp, 0, sboxOutput, 4 * l, 4); } sboxP = this.Permutation(this.P, sboxOutput); RXorL = BitManipulator.XOR(sboxP, LHalf); LHalf = RHalf; RHalf = RXorL; } RHalf = LHalf; LHalf = RXorL; Array.Copy(LHalf, 0, encyMsg, 0, LHalf.Length); Array.Copy(RHalf, 0, encyMsg, LHalf.Length, RHalf.Length); encyMsgP = this.Permutation(this.IP1, encyMsg); encyMsgByte = BitManipulator.BoolToByte(encyMsgP); Array.Copy(this.ToCharArray(encyMsgByte), 0, encyMsgChar, i * 8, 8); } return(encyMsgChar); }