Ejemplo n.º 1
0
        private void BtnAuto_Click(object sender, EventArgs e)
        {
            Stopwatch stopwatch;
            string    fileheader = new StringBuilder().AppendLine("Key length;Hmax;H;Encryption time").ToString();

            File.WriteAllText("hill.csv", fileheader);
            File.WriteAllText("gamma.csv", fileheader);
            File.WriteAllText("1permutation.csv", fileheader);
            for (int k = 2; k <= 11; k++)
            {
                StringBuilder hcs = new StringBuilder();
                StringBuilder gcs = new StringBuilder();
                StringBuilder pcs = new StringBuilder();
                for (int j = 0; j < 10; j++)
                {
                    Gamma <int> gc = new Gamma <int>(bmp, random.Next(0, 256), k);
                    SinglePermutation <int[]> pc = new SinglePermutation <int[]>(bmp, SinglePermutation <int> .GenKey(k));
                    if (k > 100 & k % 100 == 0)
                    {
                        HillCipher <Matrix> hc = new HillCipher <Matrix>(
                            bmp,
                            HillCipher <Matrix> .GenNewKey(k / 100)[KeyType.ENCRYPT],
                            HillCipher <Matrix> .GenNewKey(k / 100)[KeyType.ENCRYPT]);
                        stopwatch = new Stopwatch();
                        stopwatch.Start();
                        hc = hc.Encrypt();
                        stopwatch.Stop();
                        hcs.AppendLine(String.Format("{0};{1};{2};{3}",
                                                     k,
                                                     hc.ImageInfo.Hmax,
                                                     hc.ImageInfo.H,
                                                     stopwatch.ElapsedMilliseconds));
                    }
                    stopwatch = new Stopwatch();
                    stopwatch.Start();
                    gc = gc.Encrypt();
                    stopwatch.Stop();
                    gcs.AppendLine(String.Format("{0};{1};{2};{3}",
                                                 k,
                                                 gc.ImageInfo.Hmax,
                                                 gc.ImageInfo.H,
                                                 stopwatch.ElapsedMilliseconds));
                    stopwatch = new Stopwatch();
                    stopwatch.Start();
                    pc = pc.Encrypt();
                    stopwatch.Stop();
                    pcs.AppendLine(String.Format("{0};{1};{2};{3}",
                                                 k,
                                                 pc.ImageInfo.Hmax,
                                                 pc.ImageInfo.H,
                                                 stopwatch.ElapsedMilliseconds));
                }
                File.AppendAllText("hill.csv", hcs.ToString());
                File.AppendAllText("gamma.csv", gcs.ToString());
                File.AppendAllText("1permutation.csv", pcs.ToString());
            }
            MessageBox.Show("Done");
        }
Ejemplo n.º 2
0
        private void Btne_Click(object sender, EventArgs e)
        {
            if (radioHill.Checked) //hill
            {
                lastRB = radioHill;
                int rnd = random.Next(0, 10);
                if (k < 11)
                {
                    hillCipher = new HillCipher <Matrix>(cypheredImage.Image,
                                                         HillCipher <Matrix> .GetKeys(k, rnd)[KeyType.ENCRYPT],
                                                         HillCipher <Matrix> .GetKeys(k, rnd)[KeyType.DECRYPT]);
                    btnd.Enabled = true;
                }
                else
                {
                    hillCipher = new HillCipher <Matrix>(cypheredImage.Image,
                                                         HillCipher <Matrix> .GenNewKey(k)[KeyType.ENCRYPT],
                                                         HillCipher <Matrix> .GenNewKey(k)[KeyType.DECRYPT]);
                    btnd.Enabled = false;
                }
                var tmp = hillCipher.Message;
                hillCipher         = hillCipher.Encrypt();
                hillCipher.Message = tmp;

                cypheredImage = hillCipher.ImageInfo;
            }
            else if (radioPermut.Checked) //1perutation
            {
                lastRB = radioPermut;
                perm1  = new SinglePermutation <int[]>(
                    cypheredImage.Image, SinglePermutation <int> .GenKey(k));
                perm1         = perm1.Encrypt();
                cypheredImage = perm1.ImageInfo;
            }
            else if (radioGamm.Checked) //gamma
            {
                lastRB = radioGamm;
                gamma  = new Gamma <int>(cypheredImage.Image,
                                         random.Next(0, 256), k);
                var tmp = gamma.Message;
                gamma         = gamma.Encrypt();
                gamma.Message = tmp;
                cypheredImage = gamma.ImageInfo;
            }
            else
            {
                SystemSounds.Exclamation.Play();
            }
            Hcypher.Text      = "H = " + cypheredImage.H;
            pictureBox2.Image = cypheredImage.Image;
        }