def get_ball(self, tpw): """ Remember ball does not include the input password, but ball_union does. """ ball = fast_modify(tpw, apply_edits=self.transform_list) - set([tpw]) # ball = set(sorted(fast_modify(tpw, apply_edits=self.transform_list), # key=lambda pw: self.pwmodel.prob(pw), reverse=True)[:self.N]) self._max_ball_size = max(len(ball), self._max_ball_size) return ball
def get_nh(self, rpw): """ Neighborhood does not include the input password. """ # nh = set(filter(lambda tpw: rpw in self.get_ball(tpw) and tpw != rpw, # fast_modify(rpw, self.transform_list, # typo=True, pw_filter=PW_FILTER))) nh = fast_modify(rpw, self.transform_list, typo=True, pw_filter=PW_FILTER)-set([rpw]) self._max_nh_size = max(len(nh), self._max_nh_size) return nh
def policy2(self, tpw, rpw=None): """ Dont allow any password within the blacklisted set of passwords, a.k.a, ChkBl """ black_list_filter = lambda x: (len(x)>=6) and (x not in Checker.BLACK_LIST) B = fast_modify(tpw, apply_edits=self.transform_list, pw_filter=black_list_filter) B.add(tpw) if rpw: return rpw in B else: return B
def get_nh(self, rpw): """ Neighborhood does not include the input password. """ # nh = set(filter(lambda tpw: rpw in self.get_ball(tpw) and tpw != rpw, # fast_modify(rpw, self.transform_list, # typo=True, pw_filter=PW_FILTER))) nh = fast_modify( rpw, self.transform_list, typo=True, pw_filter=PW_FILTER) - set( [rpw]) self._max_nh_size = max(len(nh), self._max_nh_size) return nh
def policy2(self, tpw, rpw=None): """ Dont allow any password within the blacklisted set of passwords, a.k.a, ChkBl """ black_list_filter = lambda x: (len(x) >= 6) and (x not in Checker. BLACK_LIST) B = fast_modify(tpw, apply_edits=self.transform_list, pw_filter=black_list_filter) B.add(tpw) if rpw: return rpw in B else: return B
def policy6(self, tpw, rpw=None): """ Applies the edits and then choose self._topk from it based on self.pwmodel """ k = self._topk # pwheap = priority_dict({ # rrpw: -self.pwmodel.prob(rrpw) # for rrpw in fast_modify(tpw, apply_edits=self.transform_list) # }) B = fast_modify(tpw, apply_edits=self.transform_list) if k < len(B): B = list(B) B = set(B[i] for i in random.randints(0, len(B), n=k)) if rpw: return rpw in set(B) else: return set(B)
def policy6(self, tpw, rpw=None): """ Applies the edits and then choose self._topk from it based on self.pwmodel """ k = self._topk # pwheap = priority_dict({ # rrpw: -self.pwmodel.prob(rrpw) # for rrpw in fast_modify(tpw, apply_edits=self.transform_list) # }) B = fast_modify(tpw, apply_edits=self.transform_list) if k<len(B): B = list(B) B = set(B[i] for i in random.randints(0, len(B), n=k)) if rpw: return rpw in set(B) else: return set(B)
def policy4(self, tpw, rpw=None): """ Don't correct a tpw if the size of the ball is bigger than rpw_q, requires exact pwmodel, (Not used in the paper) """ if rpw and tpw == rpw: return True B = fast_modify(tpw, apply_edits=self.transform_list) B.add(tpw) ballmass = sum(self.pwmodel.get(tpw) for tpw in B) if self.rpw_q < 0.0: self.rpw_q = 0.0001 if ballmass > self.rpw_q: # Sorry no typo correction # print "Sorry no typo corr for: {} -> {}, (ballmass: {})".format(tpw, B, ballmass) B = set([tpw]) if rpw: return rpw in B else: return B
def policy4(self, tpw, rpw=None): """ Don't correct a tpw if the size of the ball is bigger than rpw_q, requires exact pwmodel, (Not used in the paper) """ if rpw and tpw==rpw: return True B = fast_modify(tpw, apply_edits=self.transform_list) B.add(tpw) ballmass = sum(self.pwmodel.get(tpw) for tpw in B) if self.rpw_q < 0.0: self.rpw_q = 0.0001 if ballmass > self.rpw_q: # Sorry no typo correction # print "Sorry no typo corr for: {} -> {}, (ballmass: {})".format(tpw, B, ballmass) B = set([tpw]) if rpw: return rpw in B else: return B