Пример #1
0
        public int EncryptBlock()
        {
            byte[] readByte = reader.ReadBytes(8);
            byte[] newByte;
            if (readByte.Length != 8)
            {
                newByte = new byte[8];
                for (int i = 0; i < readByte.Length; ++i)
                {
                    newByte[i] = readByte[i];
                }
                newByte[7] = (byte)((7 - readByte.Length) * 8);
            }
            else
            {
                newByte = readByte;
            }
            Bitset processData = new Bitset(newByte);

            lastAnswer = DES.Encrypt(processData.Xor(lastAnswer), key);
            byte[] writeByte = lastAnswer.ToByteArray();
            writer.Write(writeByte);
            return(readByte.Length);
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Bitset key = new Bitset("00010011 00110100 01010111 01111001 10011011 10111100 11011111 11110001");

            DES.GenerateSubKeys(key);
            for (int i = 0; i < 6; ++i)
            {
                Logger.Text += DES.subKeys[i].ToString() + Environment.NewLine;
            }
            Logger.Text += Environment.NewLine;
            //Bitset input = new Bitset("0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111");
            Bitset input = new Bitset(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 });

            Logger.Text += input.ToString() + Environment.NewLine;
            Bitset result = DES.Encrypt(input, key);

            Logger.Text += result.ToString();
            //MessageBox.Show(DES.Encrypt(input, key).ToString());
        }