Hashlib-like truncated sha512/256 object
This commit is contained in:
parent
936371a7ec
commit
8d26a572dd
1 changed files with 17 additions and 14 deletions
|
@ -44,20 +44,23 @@ def random(length=64, encoding="hex"):
|
||||||
return hashlib.sha512(os.urandom(256)).hexdigest()[0:length]
|
return hashlib.sha512(os.urandom(256)).hexdigest()[0:length]
|
||||||
|
|
||||||
|
|
||||||
|
# Sha512 truncated to 256bits
|
||||||
|
class Sha512t:
|
||||||
|
def __init__(self, data):
|
||||||
|
if data:
|
||||||
|
self.sha512 = hashlib.sha512(data)
|
||||||
|
else:
|
||||||
|
self.sha512 = hashlib.sha512()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def hexdigest(self):
|
||||||
import cStringIO as StringIO
|
return self.sha512.hexdigest()[0:64]
|
||||||
a = StringIO.StringIO()
|
|
||||||
a.write("hello!")
|
|
||||||
a.seek(0)
|
|
||||||
print hashlib.sha1("hello!").hexdigest()
|
|
||||||
print sha1sum(a)
|
|
||||||
|
|
||||||
import time
|
def digest(self):
|
||||||
s = time.time()
|
return self.sha512.digest()[0:32]
|
||||||
print sha1sum(open("F:\\Temp\\bigfile")),
|
|
||||||
print time.time() - s
|
|
||||||
|
|
||||||
s = time.time()
|
def update(self, data):
|
||||||
print sha512sum(open("F:\\Temp\\bigfile")),
|
return self.sha512.update(data)
|
||||||
print time.time() - s
|
|
||||||
|
|
||||||
|
def sha512t(data=None):
|
||||||
|
return Sha512t(data)
|
||||||
|
|
Loading…
Reference in a new issue