コード例 #1
0
        static BitArray MainFunction(BitArray vector, Key key)
        {
            vector = Tables.Transformation(vector, Tables.ListE, 48); //функция расширения E

            //сложение по модулю 2 с ключом
            BitArray        B       = vector.Xor(key.Value);
            List <BitArray> ListOfB = Bits.Splitting(B);

            //преобразование S
            int             i = 1;
            List <BitArray> ListOfChangedB = new List <BitArray>();

            foreach (BitArray b in ListOfB)
            {
                BitArray changedb = Tables.TransformationByTable(b, i);
                ListOfChangedB.Add(changedb);
                i++;
            }
            vector = Bits.Association(ListOfChangedB);

            // Перестановка P
            vector = Tables.Transformation(vector, Tables.ListP, 32);

            return(vector);
        }
コード例 #2
0
        static internal BitArray GetKeyForEncrypt(int index)
        {
            Bits.LeftShift(ref C);
            Bits.LeftShift(ref D);
            if ((index != 0) && (index != 1) && (index != 8) && (index != 15))
            {
                Bits.LeftShift(ref C);
                Bits.LeftShift(ref D);
            }
            BitArray common = Bits.Association(C, D, 56);
            BitArray key    = Tables.Transformation(common, Tables.ListKey, 48);

            return(key);
        }
コード例 #3
0
        public string Decrypt(int index)
        {
            Message.content = Tables.Transformation(Message.content, Tables.ListIP, 64); // Начальная перестановка

            Message.GetLeftAndRight();                                                   // Разбиение на 2 части

            KeyList[index].GenCAndD();

            // Циклы дешифрования
            for (int i = 0; i < 16; i++)
            {
                Key intermediateKey = new Key(Key.GetKeyForDecrypt(i));
                Message.Decryption(intermediateKey);
            }
            Message.content = Bits.Association(Message.LeftSide, Message.RightSide, 64);

            Message.content = Tables.Transformation(Message.content, Tables.ListPI, 64); // Конечная перестановка

            return(Bits.ToStr(Message.content));
        }