Beispiel #1
0
        public static int GenerateKey(string inputString, int keyNumber, int keyStretchingCount)
        {
            var md5          = System.Security.Cryptography.MD5.Create();
            var threePattern = @"(.)\1\1";
            var fivePattern  = @"(.)\1\1\1\1";

            var threeRgx = new Regex(threePattern);
            var fiveRgx  = new Regex(fivePattern);

            var index     = 0;
            var foundKeys = new List <int>();
            var triples   = new Dictionary <int, string>();

            while (foundKeys.Count < keyNumber || (foundKeys.Count > keyNumber - 1 && index < foundKeys[keyNumber - 1] + 1000))
            {
                var md5string = MD5.CalculateMd5(inputString + index.ToString(), md5);
                for (var j = 0; j < keyStretchingCount; j++)
                {
                    md5string = MD5.CalculateMd5(md5string.ToLower(), md5);
                }
                Match fiveMatch = fiveRgx.Match(md5string);
                if (fiveMatch.Success)
                {
                    foreach (var triple in triples)
                    {
                        if (triple.Key > index - 1000 &&
                            !foundKeys.Contains(triple.Key) &&
                            triple.Value == fiveMatch.Groups[0].Value.Substring(0, 3))
                        {
                            foundKeys.Add(triple.Key);
                        }
                    }
                    triples.Add(index, fiveMatch.Groups[0].Value.Substring(0, 3));
                }
                else
                {
                    Match threeMatch = threeRgx.Match(md5string);
                    if (threeMatch.Success)
                    {
                        triples.Add(index, threeMatch.Groups[0].Value);
                    }
                }

                foundKeys.Sort();
                index++;
            }
            return(foundKeys[keyNumber - 1]);
        }
Beispiel #2
0
        public string FindPassword(string doorId)
        {
            string password = "";

            int    index     = 0;
            string md5string = "";

            while (password.Length < 8)
            {
                md5string = MD5.CalculateMd5(doorId + index.ToString(), md5);
                if (md5string.Substring(0, 5) == "00000")
                {
                    password += md5string.Substring(5, 1);
                }
                index++;
            }

            return(password);
        }
Beispiel #3
0
        public string FindSecondPassword(string doorId)
        {
            char[] password = new char[8];

            int    index     = 0;
            int    found     = 0;
            string md5string = "";

            while (found < 8)
            {
                md5string = MD5.CalculateMd5(doorId + index.ToString(), md5);
                if (md5string.Substring(0, 5) == "00000")
                {
                    try {
                        int pos = int.Parse(md5string.Substring(5, 1));
                        if (pos < 8 && password[pos] == '\0')
                        {
                            char passwordChar = md5string.Substring(6, 1)[0];

                            password[pos] = passwordChar;
                            found++;
                        }
                    } catch (FormatException) {
                    }
                }
                index++;
            }

            var retPassword = "";

            foreach (var c in password)
            {
                retPassword += c;
            }

            return(retPassword);
        }