"""SHA 512 Thingy. Get the file at http://www1.odn.ne.jp/synsyr/sha/sha512.exe cf. http://www1.odn.ne.jp/synsyr/sha/sha.html""" import sys, os, string, re, binascii, time __author__ = "Sean B. Palmer" __license__ = "Copyright (C) 2001 Sean B. Palmer. GNU GPL 2" sha512 = '/bin/sha512' # location of sha512 def timenow(): return time.strftime('%Y%m%d-%H%M%S', time.gmtime(time.time())) def flushtemp(): os.popen('rm *.sha') class SHA512: def __init__(self, *b): self.temp = '%s.sha' % timenow() self.digest_size, self.digestsize = 512, 512 open(self.temp, 'w+').write('') for x in b: open(self.temp, 'a').write(x) def update(self, *b): for x in b: open(self.temp, 'a').write(x) def view(self): return open(self.temp, 'r').read() def hexdigest(self): """Gets the hash of the temporary file.""" x = os.popen('%s %s' % (sha512, self.temp)).read() x = string.replace(x, 'SHA512 : %s' % self.temp, '') x = string.replace(x, '\r\n', '') x = string.replace(x, ' ', '') return x def digest(self): return binascii.unhexlify(self.hexdigest()) def copy(self): return new(self.view()[:]) new = SHA512 if __name__=="__main__": print __doc__