Example #1
0
    def test_spatial_guesses(self):

        # Case
        match = {
            "token": "zxcvbn",
            "graph": "qwerty",
            "turns": 1,
            "shifted_count": 0
        }

        base_guesses = (
            scoring.KEYBOARD_STARTING_POSITIONS *
            scoring.KEYBOARD_AVERAGE_DEGREE *
            # - 1 term because: not counting spatial patterns of length 1
            # eg for length==6, multiplier is 5 for needing to try len2,len3,..,len6
            (len(match["token"]) - 1)
        )
        msg = "with no turns or shifts, guesses is starts * degree * (len-1)"
        self.assertEqual(scoring.spatial_guesses(match), base_guesses, msg)

        # Case
        match["guesses"] = None
        match["token"] = "ZxCvbn"
        match["shifted_count"] = 2
        shifted_guesses = base_guesses * (binom(6, 2) + binom(6, 1))
        msg = "guesses is added for shifted keys, similar to capitals in dictionary matching"
        self.assertEqual(scoring.spatial_guesses(match), shifted_guesses, msg)

        # Case
        match["guesses"] = None
        match["token"] = "ZXCVBN"
        match["shifted_count"] = 6
        shifted_guesses = base_guesses * 2
        msg = "when everything is shifted, guesses are doubled"
        self.assertEqual(scoring.spatial_guesses(match), shifted_guesses, msg)

        # Case
        match = {
            "token": "zxcft6yh",
            "graph": "qwerty",
            "turns": 3,
            "shifted_count": 0,
        }
        guesses = 0
        L = len(match["token"])
        s = scoring.KEYBOARD_STARTING_POSITIONS
        d = scoring.KEYBOARD_AVERAGE_DEGREE
        for i in range(2, L + 1):
            for j in range(1, min(match["turns"], i - 1) + 1):
                guesses += binom(i-1, j-1) * s * math.pow(d, j)
        msg = "spatial guesses accounts for turn positions, directions and starting keys"
        self.assertEqual(scoring.spatial_guesses(match), guesses, msg)
Example #2
0
    def test_spatial_guesses(self):

        # Case
        match = {
            "token": "zxcvbn",
            "graph": "qwerty",
            "turns": 1,
            "shifted_count": 0
        }

        base_guesses = (
            scoring.KEYBOARD_STARTING_POSITIONS *
            scoring.KEYBOARD_AVERAGE_DEGREE *
            # - 1 term because: not counting spatial patterns of length 1
            # eg for length==6, multiplier is 5 for needing to try len2,len3,..,len6
            (len(match["token"]) - 1)
        )
        msg = "with no turns or shifts, guesses is starts * degree * (len-1)"
        self.assertEqual(scoring.spatial_guesses(match), base_guesses, msg)

        # Case
        match["guesses"] = None
        match["token"] = "ZxCvbn"
        match["shifted_count"] = 2
        shifted_guesses = base_guesses * (binom(6, 2) + binom(6, 1))
        msg = "guesses is added for shifted keys, similar to capitals in dictionary matching"
        self.assertEqual(scoring.spatial_guesses(match), shifted_guesses, msg)

        # Case
        match["guesses"] = None
        match["token"] = "ZXCVBN"
        match["shifted_count"] = 6
        shifted_guesses = base_guesses * 2
        msg = "when everything is shifted, guesses are doubled"
        self.assertEqual(scoring.spatial_guesses(match), shifted_guesses, msg)

        # Case
        match = {
            "token": "zxcft6yh",
            "graph": "qwerty",
            "turns": 3,
            "shifted_count": 0,
        }
        guesses = 0
        L = len(match["token"])
        s = scoring.KEYBOARD_STARTING_POSITIONS
        d = scoring.KEYBOARD_AVERAGE_DEGREE
        for i in range(2, L + 1):
            for j in range(1, min(match["turns"], i - 1) + 1):
                guesses += binom(i-1, j-1) * s * math.pow(d, j)
        msg = "spatial guesses accounts for turn positions, directions and starting keys"
        self.assertEqual(scoring.spatial_guesses(match), guesses, msg)
Example #3
0
    def test_uppercase_variations(self):

        # Case
        pattern_list = [['', 1], ['a', 1], ['A', 2], ['abcdef', 1],
                        ['Abcdef', 2], ['abcdeF', 2], ['ABCDEF', 2],
                        ['aBcdef', binom(6, 1)],
                        ['aBcDef', binom(6, 1) + binom(6, 2)],
                        ['ABCDEf', binom(6, 1)],
                        ['aBCDEf', binom(6, 1) + binom(6, 2)],
                        ['ABCdef',
                         binom(6, 1) + binom(6, 2) + binom(6, 3)]]
        for word, variants in pattern_list:
            msg = "guess multiplier of {} is {}".format(word, variants)
            self.assertEqual(scoring.uppercase_variations({"token": word}),
                             variants, msg)
Example #4
0
    def test_l33t_variations(self):

        # Case
        match = {"l33t": False}
        self.assertEqual(scoring.l33t_variations(match), 1,
                         "1 variant for non-l33t matches")

        # Case
        pattern_list = [['', 1, {}], ['a', 1, {}], ['4', 2, {
            '4': 'a'
        }], ['4pple', 2, {
            '4': 'a'
        }], ['abcet', 1, {}], ['4bcet', 2, {
            '4': 'a'
        }], ['a8cet', 2, {
            '8': 'b'
        }], ['abce+', 2, {
            '+': 't'
        }], ['48cet', 4, {
            '4': 'a',
            '8': 'b'
        }], ['a4a4aa', binom(6, 2) + binom(6, 1), {
            '4': 'a'
        }], ['4a4a44', binom(6, 2) + binom(6, 1), {
            '4': 'a'
        }],
                        [
                            'a44att+',
                            (binom(4, 2) + binom(4, 1)) * binom(3, 1), {
                                '4': 'a',
                                '+': 't'
                            }
                        ]]
        for word, variants, sub in pattern_list:
            match = {"token": word, "sub": sub, "l33t": not is_empty(sub)}
            msg = "extra l33t guesses of {} is {}".format(word, variants)
            self.assertEqual(scoring.l33t_variations(match), variants, msg)

        # Case
        match = {"token": 'Aa44aA', "l33t": True, "sub": {'4': 'a'}}
        variants = binom(6, 2) + binom(6, 1)
        msg = "capitalization doesn't affect extra l33t guesses calc"
        self.assertEqual(scoring.l33t_variations(match), variants, msg)
Example #5
0
    def test_uppercase_variations(self):

        # Case
        pattern_list = [
            ['', 1],
            ['a', 1],
            ['A', 2],
            ['abcdef', 1],
            ['Abcdef', 2],
            ['abcdeF', 2],
            ['ABCDEF', 2],
            ['aBcdef', binom(6, 1)],
            ['aBcDef', binom(6, 1) + binom(6, 2)],
            ['ABCDEf', binom(6, 1)],
            ['aBCDEf', binom(6, 1) + binom(6, 2)],
            ['ABCdef', binom(6, 1) + binom(6, 2) + binom(6, 3)]
        ]
        for word, variants in pattern_list:
            msg = "guess multiplier of {} is {}".format(word, variants)
            self.assertEqual(scoring.uppercase_variations({"token": word}), variants, msg)
Example #6
0
    def test_l33t_variations(self):

        # Case
        match = {"l33t": False}
        self.assertEqual(scoring.l33t_variations(match), 1, "1 variant for non-l33t matches")

        # Case
        pattern_list = [
            ['',  1, {}],
            ['a', 1, {}],
            ['4', 2, {'4': 'a'}],
            ['4pple', 2, {'4': 'a'}],
            ['abcet', 1, {}],
            ['4bcet', 2, {'4': 'a'}],
            ['a8cet', 2, {'8': 'b'}],
            ['abce+', 2, {'+': 't'}],
            ['48cet', 4, {'4': 'a', '8': 'b'}],
            ['a4a4aa',  binom(6, 2) + binom(6, 1), {'4': 'a'}],
            ['4a4a44',  binom(6, 2) + binom(6, 1), {'4': 'a'}],
            ['a44att+', (binom(4, 2) + binom(4, 1)) * binom(3, 1), {'4': 'a', '+': 't'}]
        ]
        for word, variants, sub in pattern_list:
            match = {
                "token": word,
                "sub": sub,
                "l33t": not is_empty(sub)
            }
            msg = "extra l33t guesses of {} is {}".format(word, variants)
            self.assertEqual(scoring.l33t_variations(match), variants, msg)

        # Case
        match = {
            "token": 'Aa44aA',
            "l33t": True,
            "sub": {'4': 'a'}
        }
        variants = binom(6, 2) + binom(6, 1)
        msg = "capitalization doesn't affect extra l33t guesses calc"
        self.assertEqual(scoring.l33t_variations(match), variants, msg)