コード例 #1
0
ファイル: PasswordGeneration.cs プロジェクト: fdsc/old
        private void generatePasswordTable(string c)
        {
            var input = SimplePasswordBox.inputBytesHaotic;

            if ((input.Length / 9) < 64)
            {
                MessageBox.Show("Введите хотя бы 64 бита случайной информации", "Генерация случайного ключа", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            var  duplex = keccak.SHA3.generateRandomPwdByDerivatoKey(input, input.Length, false, 40);
            byte c1 = (byte)c.Length, c2 = c1;
            var  table = SHA3.getPasswordCypherTable(duplex, c1, c2);

            BytesBuilder.ToNull(duplex);

            int gc1 = 20, gc2 = 8, gc3 = 1;
            var b = new Bitmap((c1 + 1) * (gc1 + gc2) + gc3 * 2, (c2 + 1) * (gc1 + gc2) + gc3 * 2, this.CreateGraphics());
            var g = Graphics.FromImage(b);

            g.Clear(Color.White);

            var f      = new Font("Courier New", gc1);
            var p1     = new Pen(Color.Black, 1f);
            var p2     = new Pen(Color.Gray, 3f);
            var brush  = new SolidBrush(Color.Black);
            var brushw = new SolidBrush(Color.White);

            int x2 = 0, y2 = 0;

            for (int i = 0; i < c2; i++)
            {
                g.DrawLine((i & 1) > 0 ? p1 : p2, gc3, gc3 + (gc1 + gc2) * (i + 1), b.Width - gc3, gc3 + (gc1 + gc2) * (i + 1));
                g.DrawString(c.Substring(i, 1), f, brush, -(gc2 >> 1) + gc3 + gc2, /*-(gc2>>1) +*/ gc3 + (gc1 + gc2) * (i + 1));

                if (y2 == 0 && i > (c2 >> 1))
                {
                    y2 = gc3 + (gc1 + gc2) * (i + 1);
                }
            }

            for (int j = 0; j < c1; j++)
            {
                g.DrawLine((j & 1) > 0 ? p1 : p2, gc3 + (gc1 + gc2) * (j + 1), gc3, gc3 + (gc1 + gc2) * (j + 1), b.Height - gc3);
                g.DrawString(c.Substring(j, 1), f, brush, gc3 + (gc1 + gc2) * (j + 1), gc3 /*-(gc2>>1)*/);

                if (x2 == 0 && j > (c1 >> 1))
                {
                    x2 = gc3 + (gc1 + gc2) * (j + 1);
                }
            }

            for (int i = 0; i < c2; i++)
            {
                for (int j = 0; j < c1; j++)
                {
                    var t = table[j * c2 + i];
                    g.DrawString(c.Substring(t % c2, 1), f, brush, gc3 + (gc1 + gc2) * (i + 1), /*-(gc2>>1) +*/ gc3 + (gc1 + gc2) * (j + 1));
                }
            }

            BytesBuilder.ToNull(table);

            var b1 = b.Clone(new Rectangle(0, 0, b.Width, /*(b.Height >> 1) + gc1+gc3*/ y2 + 3), b.PixelFormat);
            var b2 = b.Clone(new Rectangle(0, /*(b.Height >> 1) - gc1+gc3*/ y2 - gc1 - gc2 - gc3, b.Width, b.Height - (y2 - gc1 - gc2 - gc3) /*(b.Height >> 1) + gc1-gc3*/), b.PixelFormat);

            var g2 = Graphics.FromImage(b2);

            g2.FillRectangle(brushw, 0, 0, b2.Width, gc1 + gc3 + gc2);
            for (int j = 0; j < c1; j++)
            {
                g2.DrawLine((j & 1) > 0 ? p1 : p2, gc3 + (gc1 + gc2) * (j + 1), gc3, gc3 + (gc1 + gc2) * (j + 1), b.Height - gc3);
                g2.DrawString(c.Substring(j, 1), f, brush, gc3 + (gc1 + gc2) * (j + 1), gc3 /*-(gc2>>1)*/);
            }

            b1.Save(System.IO.Path.Combine(Application.StartupPath, "tmp.gif"), System.Drawing.Imaging.ImageFormat.Gif);
            b2.Save(System.IO.Path.Combine(Application.StartupPath, "tmp2.gif"), System.Drawing.Imaging.ImageFormat.Gif);
            g.Clear(Color.White);
            Graphics.FromImage(b1).Clear(Color.White);
            Graphics.FromImage(b2).Clear(Color.White);

            System.Diagnostics.Process.Start(Application.StartupPath);
        }