示例#1
0
        // Updates the password by iterating the MD5 hashes, like the previous problem.  But, now the 6th character tells you the
        // digit of the password to update with the 7th character.
        public string DetermineSecurityDoorPasswordPartTwo(string input)
        {
            string result = "--------";

            long counter = -1;

            MD5 md5Hash = MD5.Create();

            // Loop until we have our full password, i.e. one that no longer has -'s in it
            do
            {
                ++counter;

                string hashInput  = input + counter;
                string resultHash = Md5Utility.GetMd5Hash(md5Hash, hashInput);

                // Check to see if the resultHash is valid - i.e. starts with 5 zeros
                if (resultHash.Substring(0, 5) == "00000")
                {
                    // Then add the sixth character to accumulating password
                    result = HandleResultUpdate(result, resultHash);
                }
            } while (result.IndexOf('-') != -1);

            return(result);
        }
示例#2
0
        // Determine the security door password by iterating through MD5 hashs looking for hashes that begin with "00000"
        // Then use the next character to collect the password
        public string DetermineSecurityDoorPassword(string input)
        {
            string result = "";

            long counter = -1;

            MD5 md5Hash = MD5.Create();

            // Loop until we have our full password of 8 characters
            do
            {
                ++counter;

                string hashInput  = input + counter;
                string resultHash = Md5Utility.GetMd5Hash(md5Hash, hashInput);

                // Check to see if the resultHash is valid - i.e. starts with 5 zeros
                if (resultHash.Substring(0, 5) == "00000")
                {
                    // Then add the sixth character to accumulating password
                    result += resultHash.Substring(5, 1);
                }
            } while (result.Length < 8);

            return(result);
        }
        public string CreateMd5Hash(MD5 md5Hash, long counter, string salt)
        {
            string combined = $"{salt}{counter}";
            string hash     = Md5Utility.GetMd5Hash(md5Hash, combined);

            return(hash);
        }
        public string CreateStretchedMd5Hash(MD5 md5Hash, long counter, string salt)
        {
            string iterativeHash = $"{salt}{counter}";

            for (int i = 0; i < 2017; i++)
            {
                string hash = Md5Utility.GetMd5Hash(md5Hash, iterativeHash);
                iterativeHash = hash;
            }
            return(iterativeHash);
        }
示例#5
0
        // Creates a series of characters that follow compass - [0] = North, [1] = South, [2] = Left, [3] = East
        public List <char> OpenDoorsForRoom(string passcode, MD5 md5Hash)
        {
            List <char> result = new List <char>();

            string      hash = Md5Utility.GetMd5Hash(md5Hash, passcode);
            List <char> dirs = hash.Substring(0, 4).ToList <char>();

            for (int i = 0; i < 4; i++)
            {
                char dir = dirs[i];
                if (VALID_CHARS.Contains(dir))
                {
                    result.Add('O');
                }
                else
                {
                    result.Add('C');
                }
            }

            return(result);
        }