identify checksum type?

Scott David Daniels Scott.Daniels at Acm.Org
Tue Jun 30 11:00:44 EDT 2009

Christian Heimes wrote:
> PK schrieb:
>> Given a checksum value, whats the best way to find out what type it is?
>> meaning. I can use hashlib module and compute a md5 or sha1 for a given data
>> etc..but given a checksum value say "d2bda52ee39249acc55a75a0f3566105" whats
>> the best way for me to identify if its a sha1 or md5 or anyother sum type
>> for that matter?
>> is there a nice way to do this in python?
> As far as I know there is no way to identify a checksum by its value. A
> checksum is just a number. You can try an educated guess based on the
> length of the checksum. Or you can try all hash algorithms until you get
> a hit but that may lead to security issues.
> Some applications prefix the hash value with an identifier like "{MD5}"
> or "{SHA1}".
> Christian
fortunately, the hashlib checksums can be distinguished by their length
On the newly minted 3.1:
     import hashlib
     text = b'BDFL forever; FLUFL for frequently'
     for name in 'md5 sha1 sha224 sha256 sha384 sha512'.split():
         result = getattr(hashlib, name)(text).hexdigest()
         print('%6s:%3d %s' % (name, len(result), result))

    md5: 32 457484d2817fbe475ab582bff2014e82
   sha1: 40 242076dffbd432062b439335438f08ba53387897
sha224: 56 89c0439b1cf3ec7489364a4b8e50b3ba196706eecdb5e5aec6d6290f
sha256: 64 e10938435e4b5b54c9276c05d5f5d7c4401997fbd7f27f4d4...807d
sha384: 96 3fe7c7bf3e83d70dba7d59c3b79f619cf821a798040be2177...edb7
sha512:128 fe50d9f0c5780edb8a8a41e317a6936ec6305d856c78ccb8e...1fa0

You'll have to guess for adler32 vs. crc32 vs. seeded crc32, ...

--Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-list mailing list