2014-08-14 12:11:07 +00:00
|
|
|
import hashlib
|
|
|
|
import crcmod
|
|
|
|
import mmh3
|
2016-07-15 14:58:48 +00:00
|
|
|
import ssdeep
|
2016-08-04 09:55:38 +00:00
|
|
|
import tlsh
|
2014-08-14 12:11:07 +00:00
|
|
|
|
2014-08-06 09:43:40 +00:00
|
|
|
|
|
|
|
class Hash(object):
|
|
|
|
"""docstring for Hash"""
|
|
|
|
def __init__(self, name):
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "{0}".format(self.name)
|
|
|
|
|
|
|
|
def _get_hash_name(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def _set_hash_name(self, name):
|
|
|
|
self.p_hash_name = name
|
|
|
|
|
|
|
|
def Calculate(self, string):
|
|
|
|
if self.name == "md5":
|
|
|
|
hash = hashlib.md5(string).hexdigest()
|
|
|
|
|
|
|
|
elif self.name == "sha1":
|
|
|
|
hash = hashlib.sha1(string).hexdigest()
|
|
|
|
|
|
|
|
elif self.name == "crc":
|
|
|
|
crc32 = crcmod.Crc(0x104c11db7, initCrc=0, xorOut=0xFFFFFFFF)
|
|
|
|
crc32.update(string)
|
|
|
|
hash = crc32.hexdigest()
|
|
|
|
|
|
|
|
elif self.name == "murmur":
|
|
|
|
hash = mmh3.hash(string)
|
|
|
|
|
2016-07-15 14:58:48 +00:00
|
|
|
elif self.name == "ssdeep":
|
|
|
|
hash = ssdeep.hash(string)
|
2016-07-15 06:56:16 +00:00
|
|
|
|
2016-08-04 09:55:38 +00:00
|
|
|
elif self.name == "tlsh":
|
|
|
|
hash = tlsh.hash(string)
|
|
|
|
|
2014-08-14 12:11:07 +00:00
|
|
|
return hash
|