hashers.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:corpushash 作者: NAMD 项目源码 文件源码
def _encode_token(self, token):
        """
        takes a token as input, if token is in encoding dictionary, looks its 
        hash up and returns it. else, hashes it, checks it for collisions 
        (overkill) while updating en(de)coding dictionaries.
        :param token: str: token.
        :return: str: hashed token
        """
        if token in self.encode_dictionary:
            return self.encode_dictionary[token]
        else:
            hashed_token, salt = hash_token(token, 
                                            hash_function=self.hash_function, 
                                            salt_length=self.salt_length,
                                            salt=self.one_salt)
            while hashed_token in self.decode_dictionary:
                hashed_token, salt = hash_token(token, 
                                               hash_function=self.hash_function,
                                               salt_length=self.salt_length,
                                               salt=None)
            self.decode_dictionary[hashed_token] = (token, 
                                                    base64.b85encode(salt).decode())
            self.encode_dictionary[token] = hashed_token
        return hashed_token
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号