Ejemplo n.º 1
0
    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'])
Ejemplo n.º 2
0
    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'])
Ejemplo n.º 3
0
    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'])
Ejemplo n.º 4
0
    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
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
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"})
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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()
Ejemplo n.º 11
0
    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'])
Ejemplo n.º 12
0
    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'])
Ejemplo n.º 13
0
    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'])
Ejemplo n.º 14
0
    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'])
Ejemplo n.º 15
0
 def test_block_size(self):
     wp = whirlpool.new()
     self.assertEqual(wp.block_size, 64)
     with self.assertRaises(AttributeError):
         wp.digest_size = 32
Ejemplo n.º 16
0
 def test_new_binary(self):
     wp = whirlpool.new(data['binary'])
     self.assertEqual(digest2hex(wp.digest()), results['binary'])
     self.assertEqual(wp.hexdigest(), results['binary'])
Ejemplo n.º 17
0
def _whirlpool_new(*args):
    _new_funcs['whirlpool'] = _new_funcs['whirlpool'] = whirlpool.new
    return whirlpool.new(*args)
Ejemplo n.º 18
0
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))
Ejemplo n.º 20
0
 def test_block_size(self):
     wp = whirlpool.new()
     self.assertEqual(wp.block_size, 64)
     with self.assertRaises((AttributeError, TypeError)):
         wp.digest_size = 32
Ejemplo n.º 21
0
 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
Ejemplo n.º 22
0
def HASH_WHIRLPOOL(data):
    return whirlpool.new(data).digest()
Ejemplo n.º 23
0
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
Ejemplo n.º 24
0
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)
Ejemplo n.º 25
0
 def test_new_unicode(self):
     wp = whirlpool.new(data['unicode'])
     self.assertEqual(digest2hex(wp.digest()), results['unicode'])
     self.assertEqual(wp.hexdigest(), results['unicode'])
Ejemplo n.º 26
0
 def test_new_empty(self):
     wp = whirlpool.new()
     self.assertEqual(digest2hex(wp.digest()), results['empty'])
     self.assertEqual(wp.hexdigest(), results['empty'])
Ejemplo n.º 27
0
 def test_new_empty(self):
     wp = whirlpool.new()
     self.assertEqual(digest2hex(wp.digest()), results['empty'])
     self.assertEqual(wp.hexdigest(), results['empty'])
Ejemplo n.º 28
0
 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
Ejemplo n.º 29
0
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()
Ejemplo n.º 30
0
 def digest(self):
     return whirlpool.new(self._data).digest()
Ejemplo n.º 31
0
 def test_new_unicode(self):
     wp = whirlpool.new(data['unicode'])
     self.assertEqual(digest2hex(wp.digest()), results['unicode'])
     self.assertEqual(wp.hexdigest(), results['unicode'])
Ejemplo n.º 32
0
 def test_new_binary(self):
     wp = whirlpool.new(data['binary'])
     self.assertEqual(digest2hex(wp.digest()), results['binary'])
     self.assertEqual(wp.hexdigest(), results['binary'])