public static BinaryNumber operator +(BinaryNumber lhs, BinaryNumber rhs)
 {
     BinaryNumber res = new BinaryNumber();
     res.Add(lhs);
     res.Add(rhs);
     return res;
 }
 public List<BinaryNumber> Divide(int n)
 {
     List<BinaryNumber> parts = new List<BinaryNumber>();
     BinaryNumber part = new BinaryNumber();
     for (int i = 0; i < Length; i++)
     {
         part.Add(binary[i]);
         if ((i + 1)%(Length/n) == 0)
         {
             parts.Add(new BinaryNumber(part));
             part.Clear();
         }
     }
     return parts;
 }
Exemple #3
0
 private BinaryNumber SBlock(BinaryNumber input, int id)
 {
     BinaryNumber row = new BinaryNumber();
     row.Add(input[0]);
     row.Add(input.Last);
     BinaryNumber col = new BinaryNumber();
     for(int i = 1; i < input.Length - 1; i++)
         col.Add(input[i]);
     return ToBinaryNumber(S[id][row.ToInt()][col.ToInt()], 4);
 }
Exemple #4
0
 private BinaryNumber Function(BinaryNumber input, int stepId)
 {
     BinaryNumber eOut = Block(E, input);
     List<BinaryNumber> sInputs = (eOut ^ GetKey(stepId)).Divide(8);
     BinaryNumber sOut = new BinaryNumber();
     for(int i = 0; i < sInputs.Count; i++)
     {
         sOut.Add(SBlock(sInputs[i], i));
     }
     return Block(P, sOut);
 }
Exemple #5
0
 private BinaryNumber Block(int[][] block, BinaryNumber input)
 {
     BinaryNumber output = new BinaryNumber();
     for (int i = 0; i < block.Length; i++)
     {
         for (int j = 0; j < block[0].Length; j++)
         {
             output.Add(input[block[i][j] - 1]);
         }
     }
     return output;
 }
Exemple #6
0
        public string Encript(string message)
        {
            mode = DESMode.Encription;
            byte[] byteMessage = PreprocessMessage(message);
            List<BinaryNumber> ipInput = new List<BinaryNumber>();
            BinaryNumber temp = new BinaryNumber();
            for (int i = 0; i < byteMessage.Length; i++)
            {
                temp.Add(ToBinaryNumber(byteMessage[i], 8));
                if ((i + 1)%8 == 0)
                {
                    ipInput.Add(new BinaryNumber(temp));
                    temp.Clear();
                }
            }
               encrypted = new List<BinaryNumber>();
            for (int i = 0; i < ipInput.Count; i++)
            {
                encrypted.Add(Process(ipInput[i]));
            }

            StringBuilder sb = new StringBuilder();
            foreach (var binaryNumber in encrypted)
            {
                sb.Append(binaryNumber);
            }
            return sb.ToString();
        }