1 Star 1 Fork 1

一只程序喵/HexViewer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sum_hashes.py 2.18 KB
一键复制 编辑 原始数据 按行查看 历史
facelessuser 提交于 2020-02-08 21:14 . Update copyright
"""
Hex Viewer.
Licensed under MIT
Copyright (c) 2013-2020 Isaac Muse <isaacmuse@gmail.com>
"""
BIT8_MOD = 256
BIT16_MOD = 65536
BIT24_MOD = 16777216
BIT32_MOD = 4294967296
class sum8(object): # noqa
"""Sum8 hash."""
__name = "sum8"
__digest_size = 1
def __init__(self, arg=b""):
"""Initialize."""
self.sum = 0
self.update(arg)
@property
def name(self):
"""Name of the hash."""
return self.__name
@property
def digest_size(self):
"""Size of the digest."""
return self.__digest_size
def update(self, arg):
"""Update the hash."""
for b in arg:
self.sum += int(b)
def digest(self):
"""Get the digest."""
return self.sum % BIT8_MOD
def hexdigest(self):
"""Get the hex digest."""
return "%02x" % self.digest()
def copy(self):
"""Get the copy."""
import copy
return copy.deepcopy(self)
class sum16(sum8): # noqa
"""Sum16 hash."""
__name = "sum16"
__digest_size = 2
def digest(self):
"""Get the digest."""
return self.sum % BIT16_MOD
def hexdigest(self):
"""Get the hex digest."""
return "%04x" % self.digest()
class sum24(sum8): # noqa
"""Sum24 hash."""
__name = "sum24"
__digest_size = 3
def digest(self):
"""Get the digest."""
return self.sum % BIT24_MOD
def hexdigest(self):
"""Get the hex digest."""
return "%06x" % self.digest()
class sum32(sum8): # noqa
"""Sum32 hash."""
__name = "sum32"
__digest_size = 4
def digest(self):
"""Get the digest."""
return self.sum % BIT32_MOD
def hexdigest(self):
"""Get the hex digest."""
return "%08x" % self.digest()
class xor8(sum8): # noqa
"""Xor8 hash."""
__name = "xor8"
__digest_size = 1
def update(self, arg):
"""Update the hash."""
for b in arg:
self.sum ^= int(b) & 0xFF
def digest(self):
"""Get the digest."""
return int(self.sum)
def hexdigest(self):
"""Get the hex digest."""
return "%02x" % self.digest()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/bobneo/HexViewer.git
git@gitee.com:bobneo/HexViewer.git
bobneo
HexViewer
HexViewer
master

搜索帮助