jeudi 31 août 2017

Give Value to Console Window than try to guess given value, but it is instant giving me the right value. But there are around 1000 of possibilitys

My Code is this and at my first run it all worked fine, than i tried to make it faster , doesnt worked to make it faster, changed it back and now Iam getting instant after 0,0027... seconds the right value. That cant be possible if u think on all the possibilitys. It is like the Programm is passing the String Password direct to PasswordTry. Can u help me fix it, in the first run it took 58 seconds to guess 2 letters.

    static List<char> Chars = new List<char>();
    static Random rnd = new Random();
    static int Periods;
    static string Password;
    static string PasswordTry;
    static Stopwatch sw = new Stopwatch();
    static List<string> Strings = new List<string>();

    static void Main(string[] args)
    {
        AddChars();
        Console.Write("Periods: ");
        Periods = Convert.ToInt32(Console.ReadLine());
        Console.Write("Password: ");
        Password = Console.ReadLine();

        sw.Start();
        while (Password != PasswordTry)
        {
            int i = 0;
            for (i = 0; i < Periods; i++)
            {
                PasswordTry += (char)rnd.Next((char)Chars[0], (char)Chars[Chars.Count - 1]);

                if (PasswordTry.Length == Periods)
                {
                    if (Strings.Contains(PasswordTry))
                    {
                        PasswordTry = String.Empty;
                        i = 0;
                    }
                }
            }

            if (PasswordTry == Password)
            {
                Console.WriteLine("Password: " + Password);
                Console.WriteLine(sw.Elapsed);
                sw.Stop();
                Console.ReadLine();
            }
            else
            {
                Strings.Add(PasswordTry);
                PasswordTry = String.Empty;
            }

            //if (PasswordTry.Length == Periods)
            //{
            //    PasswordTry = String.Empty;
            //}                
        }
    }

    private static void AddChars()
    {
        Chars.Add('a');
        Chars.Add('b');
        Chars.Add('c');
        Chars.Add('d');
        Chars.Add('e');
        Chars.Add('f');
        Chars.Add('g');
        Chars.Add('h');
        Chars.Add('i');
        Chars.Add('j');
        Chars.Add('k');
        Chars.Add('l');
        Chars.Add('m');
        Chars.Add('n');
        Chars.Add('o');
        Chars.Add('p');
        Chars.Add('q');
        Chars.Add('r');
        Chars.Add('s');
        Chars.Add('t');
        Chars.Add('u');
        Chars.Add('v');
        Chars.Add('w');
        Chars.Add('x');
        Chars.Add('y');
        Chars.Add('z');
        Chars.Add('ß');
        Chars.Add('A');
        Chars.Add('B');
        Chars.Add('C');
        Chars.Add('D');
        Chars.Add('E');
        Chars.Add('F');
        Chars.Add('G');
        Chars.Add('H');
        Chars.Add('I');
        Chars.Add('J');
        Chars.Add('K');
        Chars.Add('L');
        Chars.Add('M');
        Chars.Add('N');
        Chars.Add('O');
        Chars.Add('P');
        Chars.Add('Q');
        Chars.Add('R');
        Chars.Add('S');
        Chars.Add('T');
        Chars.Add('U');
        Chars.Add('V');
        Chars.Add('W');
        Chars.Add('X');
        Chars.Add('Y');
        Chars.Add('Z');
        Chars.Add('ẞ');
        Chars.Add('1');
        Chars.Add('2');
        Chars.Add('3');
        Chars.Add('4');
        Chars.Add('5');
        Chars.Add('6');
        Chars.Add('7');
        Chars.Add('8');
        Chars.Add('9');
        Chars.Add('!');
        Chars.Add('"');
        Chars.Add('§');
        Chars.Add('$');
        Chars.Add('%');
        Chars.Add('&');
        Chars.Add('/');
        Chars.Add('(');
        Chars.Add(')');
        Chars.Add('=');
        Chars.Add('?');
        Chars.Add('´');
        Chars.Add('@');
        Chars.Add('²');
        Chars.Add('³');
        Chars.Add('€');
        Chars.Add('{');
        Chars.Add('[');
        Chars.Add(']');
        Chars.Add('}');
        Chars.Add('\"');
        Chars.Add('`');
        Chars.Add('+');
        Chars.Add('*');
        Chars.Add('~');
        Chars.Add('#');
        Chars.Add('^');
        Chars.Add('°');
        Chars.Add('-');
        Chars.Add('_');
        Chars.Add('.');
        Chars.Add(':');
        Chars.Add(',');
        Chars.Add(';');
        Chars.Add(' ');
        Chars.Add('<');
        Chars.Add('>');
        Chars.Add('|');
    }
}

}




Aucun commentaire:

Enregistrer un commentaire