Created
February 21, 2012 10:51
-
-
Save Jim-Holmstroem/1875766 to your computer and use it in GitHub Desktop.
Hash numpy.array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hashlib import sha1 | |
import numpy | |
arr=numpy.zeros((256,256,4)) | |
sha1(arr) |
Also, make sure your array is C-contigious, otherwise hashing will not work.
Simple fix:
if not x.flags['C_CONTIGUOUS']:
x = np.ascontiguousarray(x)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Warning, do not use sha1 with password or anything where security relies on it
Sha1 cryptographic hash is dead because thanks to the submission of the first known instance of a fatal exploit known as a "hash collision brute force attack" users can find multiple hash inputs that will generate identical outputs. Do not use sha1 for passwords. No hash function from this library is safe in a security minded area without salts and multiple rounds of hashing.
Documentation: https://docs.python.org/2/library/hashlib.html
But if you can be sure the hashes can't be poisoned, and maliciously crafted collisions don't matter, then you can get the hash object's digest using:
Make sure to take into account the remote possibility that two different inputs will generate identical hash outputs.