Exemplo n.º 1
0
        private void btnCrypt_Click(object sender, EventArgs e)
        {
            if (tbEncodeFile.Text == "")
            {
                tbEncodeFile.Text = tbSorceFile.Text + ".encode";
            }

            PermCounter Counter = new PermCounter();

            Counter.Start();
            DESCrypt.Encode(tbSorceFile.Text, tbEncodeFile.Text, UInt64.Parse(tbKey.Text));
            tbEncodeTime.Text = Counter.Finish().ToString("F03");

            MessageBox.Show("File successfully encoded");
        }
Exemplo n.º 2
0
        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            if (tbDecodeFile.Text == "")
            {
                string str  = tbEncodeFile.Text;
                int    ind1 = str.LastIndexOf('.');
                int    ind2 = str.LastIndexOf('.', ind1 - 1);
                tbDecodeFile.Text = tbEncodeFile.Text + str.Substring(ind2, ind1 - ind2);
            }
            PermCounter Counter = new PermCounter();

            Counter.Start();
            DESCrypt.Decode(tbEncodeFile.Text, tbDecodeFile.Text, UInt64.Parse(tbKey.Text));
            tbDecodeTime.Text = Counter.Finish().ToString("F03");

            StreamReader Reader = new StreamReader(tbSorceFile.Text);

            byte[] OrigArray = new byte[Reader.BaseStream.Length];
            Reader.BaseStream.Read(OrigArray, 0, (int)Reader.BaseStream.Length);
            Reader.Close();
            Reader = new StreamReader(tbDecodeFile.Text);
            byte[] DecodeArray = new byte[Reader.BaseStream.Length];
            Reader.BaseStream.Read(DecodeArray, 0, (int)Reader.BaseStream.Length);
            Reader.Close();

            OrigArray   = SHA1.Create().ComputeHash(OrigArray);
            DecodeArray = SHA1.Create().ComputeHash(DecodeArray);
            if (OrigArray.SequenceEqual(DecodeArray))
            {
                MessageBox.Show("Original and decoded files identical!!! Decoding success");
            }
            else
            {
                MessageBox.Show("Original and decoded files are not identical. Decoding fail");
            }
        }