コード例 #1
0
        /// <summary>
        /// Each policy actually describes two positions in the password,
        /// where 1 means the first character, 2 means the second character, and so on.
        /// (Be careful; Toboggan Corporate Policies have no concept of "index zero"!)
        /// Exactly one of these positions must contain the given letter.
        /// Other occurrences of the letter are irrelevant for the purposes of policy enforcement.
        /// </summary>
        /// <param name="passwordWithSpec"></param>
        /// <returns></returns>
        internal bool CheckPasswordOnSpecPart2(PasswordWithSpec passwordWithSpec)
        {
            var charToCheck        = passwordWithSpec.Spec.Character;
            var firstPosZeroBased  = passwordWithSpec.Spec.First - 1;
            var secondPosZeroBased = passwordWithSpec.Spec.Second - 1;

            var checkFirstChar  = passwordWithSpec.Password[firstPosZeroBased] == charToCheck;
            var checkSecondChar = passwordWithSpec.Password[secondPosZeroBased] == charToCheck;
            var xor             = checkFirstChar ^ checkSecondChar;

            return(xor);
        }
コード例 #2
0
        private PasswordWithSpec SplitUp(string line)
        {
            var pwWithSpec = line.Split(':');

            var specSplit = pwWithSpec[0].Split(' ');
            var occ       = specSplit[0].Split('-');

            var pwSpec = new PasswordWithSpec
            {
                Password = pwWithSpec[1].Trim(),
                Spec     = new Spec
                {
                    Character = specSplit[1].First(),
                    First     = int.Parse(occ[0]),
                    Second    = int.Parse(occ[1])
                }
            };

            return(pwSpec);
        }
コード例 #3
0
        internal bool CheckPasswordOnSpecPart1(PasswordWithSpec passwordWithSpec)
        {
            var nrOfOccurances = passwordWithSpec.Password.Count(c => c == passwordWithSpec.Spec.Character);

            return(nrOfOccurances >= passwordWithSpec.Spec.First && nrOfOccurances <= passwordWithSpec.Spec.Second);
        }