def test_new_fox(self): wp1 = whirlpool.new('The quick brown fox jumps over the lazy dog') self.assertEqual(b2a_hex(wp1.digest()), results['tqbfjotld']) self.assertEqual(wp1.hexdigest(), results['tqbfjotld']) wp2 = whirlpool.new('The quick brown fox jumps over the lazy eog') self.assertEqual(b2a_hex(wp2.digest()), results['tqbfjotle']) self.assertEqual(wp2.hexdigest(), results['tqbfjotle'])
def test_new_fox(self): wp1 = whirlpool.new(data['tqbfjotld']) self.assertEqual(digest2hex(wp1.digest()), results['tqbfjotld']) self.assertEqual(wp1.hexdigest(), results['tqbfjotld']) wp2 = whirlpool.new(data['tqbfjotle']) self.assertEqual(digest2hex(wp2.digest()), results['tqbfjotle']) self.assertEqual(wp2.hexdigest(), results['tqbfjotle'])
def encrypt_password(password): """ recieves password as a variable. encoding password with utf-8, there after using a hexdigest to create a hashed password. """ text = password h1 = whirlpool.new(text.encode('utf-8')) hashed_output = h1.hexdigest() return hashed_output
def __init__(self, password): # Old implentation using SHA512 #import hashlib #self.__salt = hashlib.sha512(password.encode()).digest() # New using Whirlpool import whirlpool wp = whirlpool.new(password.encode()) self.__salt = wp.hexdigest().encode() self.key = self.derive_key(password)
def reset(email): user = UserModel.find_by_email(email) if user: newpass = str(random.randint(1000, 9999)) wp = whirlpool.new(newpass.encode('utf-8')) hashed_string = wp.hexdigest() user.password = hashed_string msg = Message(subject="42-camaguru", recipients=[email], body="your new password is %s" % newpass) mail.send(msg) user.save_to_db() return jsonify({"message": "Password reset email has been sent"}) else: return jsonify({"message": "No matched user has found"})
def credcheck(login, password): #first lookup in db and validate cursor = coll.find({"_id" : login.lower()}) if cursor.count() == 0: logger.info("looked up " + login + ", found 0 users") return False if cursor.count() > 1: logger.warning("looked up " + login + ", found multiple users!") return False userdoc = cursor[0] #now generate the hash wp = whirlpool.new("" + password + userdoc['salt']) passhash = wp.hexdigest() if passhash == userdoc['hash']: return True return False
def create_new_user(username, userpass): #TODO do I need this checks? #check for valid if username is None or userpass is None: return False if user_exists(username): return False #generate hash salt = gensalt() wp = whirlpool.new("" + userpass + salt) passhash = wp.hexdigest() #insert into db userdoc = {'_id': username.lower()} userdoc['hash'] = passhash userdoc['salt'] = salt userdoc['signupts'] = datetime.datetime.utcnow() userdoc['following'] = [] userdoc['followers'] = [] userdoc['links'] = [] coll.insert(userdoc) return True
def hash_file(filename, hashname): file = open(f"HASHBOT_FILES/TEMPFILES/{filename}", 'rb') if hashname.lower() == 'sha1': return hashlib.sha1(file.read()).hexdigest() if hashname.lower() == 'sha256': return hashlib.sha256(file.read()).hexdigest() if hashname.lower() == 'md5': return hashlib.md5(file.read()).hexdigest() if hashname.lower() == 'sha512': return hashlib.sha512(file.read()).hexdigest() if hashname.lower() == 'sha3_512': return hashlib.sha3_512(file.read()).hexdigest() if hashname.lower() == 'blake2s': return hashlib.blake2s(file.read()).hexdigest() if hashname.lower() == 'whirlpool': return whirlpool.new(file.read()).hexdigest()
def test_update_copy(self): wp1 = whirlpool.new() wp2 = wp1.copy() wp1.update('The quick brown fox') wp3 = wp1.copy() self.assertEqual(b2a_hex(wp1.digest()), results['tqbf']) self.assertEqual(wp1.hexdigest(), results['tqbf']) self.assertEqual(b2a_hex(wp2.digest()), results['empty']) self.assertEqual(wp2.hexdigest(), results['empty']) self.assertEqual(b2a_hex(wp3.digest()), results['tqbf']) self.assertEqual(wp3.hexdigest(), results['tqbf']) wp1.update(' jumps over the lazy dog') self.assertEqual(b2a_hex(wp1.digest()), results['tqbfjotld']) self.assertEqual(wp1.hexdigest(), results['tqbfjotld']) self.assertEqual(b2a_hex(wp2.digest()), results['empty']) self.assertEqual(wp2.hexdigest(), results['empty']) self.assertEqual(b2a_hex(wp3.digest()), results['tqbf']) self.assertEqual(wp3.hexdigest(), results['tqbf']) wp3.update(' jumps over the lazy eog') self.assertEqual(b2a_hex(wp1.digest()), results['tqbfjotld']) self.assertEqual(wp1.hexdigest(), results['tqbfjotld']) self.assertEqual(b2a_hex(wp2.digest()), results['empty']) self.assertEqual(wp2.hexdigest(), results['empty']) self.assertEqual(b2a_hex(wp3.digest()), results['tqbfjotle']) self.assertEqual(wp3.hexdigest(), results['tqbfjotle'])
def test_update_copy(self): wp1 = whirlpool.new() wp2 = wp1.copy() wp1.update(data['tqbf']) wp3 = wp1.copy() self.assertEqual(digest2hex(wp1.digest()), results['tqbf']) self.assertEqual(wp1.hexdigest(), results['tqbf']) self.assertEqual(digest2hex(wp2.digest()), results['empty']) self.assertEqual(wp2.hexdigest(), results['empty']) self.assertEqual(digest2hex(wp3.digest()), results['tqbf']) self.assertEqual(wp3.hexdigest(), results['tqbf']) wp1.update(data['jotld']) self.assertEqual(digest2hex(wp1.digest()), results['tqbfjotld']) self.assertEqual(wp1.hexdigest(), results['tqbfjotld']) self.assertEqual(digest2hex(wp2.digest()), results['empty']) self.assertEqual(wp2.hexdigest(), results['empty']) self.assertEqual(digest2hex(wp3.digest()), results['tqbf']) self.assertEqual(wp3.hexdigest(), results['tqbf']) wp3.update(data['jotle']) self.assertEqual(digest2hex(wp1.digest()), results['tqbfjotld']) self.assertEqual(wp1.hexdigest(), results['tqbfjotld']) self.assertEqual(digest2hex(wp2.digest()), results['empty']) self.assertEqual(wp2.hexdigest(), results['empty']) self.assertEqual(digest2hex(wp3.digest()), results['tqbfjotle']) self.assertEqual(wp3.hexdigest(), results['tqbfjotle'])
def test_block_size(self): wp = whirlpool.new() self.assertEqual(wp.block_size, 64) with self.assertRaises(AttributeError): wp.digest_size = 32
def test_new_binary(self): wp = whirlpool.new(data['binary']) self.assertEqual(digest2hex(wp.digest()), results['binary']) self.assertEqual(wp.hexdigest(), results['binary'])
def _whirlpool_new(*args): _new_funcs['whirlpool'] = _new_funcs['whirlpool'] = whirlpool.new return whirlpool.new(*args)
def HASH_WHIRLPOOL(data): return whirlpool.new(data).digest()
import hashlib, binascii from Crypto.Hash import keccak import whirlpool text = 'blockchain' data = text.encode("utf8") sha384hash=hashlib.sha384(data).digest() print("SHA384: ",binascii.hexlify(sha384hash)) sha512hash=hashlib.sha512(data).digest() print("SHA512: ",binascii.hexlify(sha512hash)) sha3_512hash=hashlib.sha3_512(data).digest() print("SHA3-512: ",binascii.hexlify(sha3_512hash)) Keccak512hash=keccak.new(data=data,digest_bits=512).digest() print("Keccak512: ",binascii.hexlify(Keccak512hash)) Whirlpool512hash=whirlpool.new(data).digest() print("SHA3-512: ",binascii.hexlify(Whirlpool512hash))
def test_block_size(self): wp = whirlpool.new() self.assertEqual(wp.block_size, 64) with self.assertRaises((AttributeError, TypeError)): wp.digest_size = 32
def test_block_size(self): wp = whirlpool.new() self.assertEqual(wp.block_size, 64) with self.assertRaisesRegexp(AttributeError, 'block_size.*not writable'): wp.block_size = 32
from Crypto.Hash import SHA256 from Crypto.Hash import SHA224 from Crypto.Hash import RIPEMD from Crypto.Hash import MD5 from Crypto.Hash import MD4 from Crypto.Hash import MD2 import whirlpool import hashlib a = raw_input("Digite uma string: ") b = SHA512.new(a).hexdigest() c = SHA384.new(a).hexdigest() d = SHA256.new(a).hexdigest() e = SHA224.new(a).hexdigest() f = RIPEMD.new(a).hexdigest() g = MD5.new(a).hexdigest() h = MD4.new(a).hexdigest() i = MD2.new(a).hexdigest() j = whirlpool.new(a).hexdigest() l = hashlib.sha1(a).hexdigest() print "SHA512 = ", b print "SHA384 = ", c print "SHA256 = ", d print "SHA224 = ", e print "RIPEMD160 = ", f print "MD5 = ", g print "MD4 = ", h print "MD2 = ", i print "Whirlpool = ", j print "SHA1 = ", l
import whirlpool hashed_string = '' count = 0 while (hashed_string[0:3] != '09f'): count = count + 1 wp = whirlpool.new(str(count)) hashed_string = wp.hexdigest() print(hashed_string) print(count)
def test_new_unicode(self): wp = whirlpool.new(data['unicode']) self.assertEqual(digest2hex(wp.digest()), results['unicode']) self.assertEqual(wp.hexdigest(), results['unicode'])
def test_new_empty(self): wp = whirlpool.new() self.assertEqual(digest2hex(wp.digest()), results['empty']) self.assertEqual(wp.hexdigest(), results['empty'])
def whirlpool_hash(fname): hash_whirlpool = whirlpool.new() with open(fname, "rb") as f: for chunk in iter(lambda: f.read(4096), b""): hash_whirlpool.update(chunk) return hash_whirlpool.hexdigest()
def digest(self): return whirlpool.new(self._data).digest()