Python 256bit Hash function with number output

前端 未结 2 1553
南方客
南方客 2021-02-05 15:20

I need a Hash function with a 256bit output (as long int).

First I thought I could use SHA256 from the hashlib but it has an String Output and I need a number to calcula

相关标签:
2条回答
  • 2021-02-05 15:42

    How about:

    >>> import hashlib
    >>> h = hashlib.sha256('something to hash')
    >>> h.hexdigest()
    'a3899c4070fc75880fa445b6dfa44207cbaf924a450ce7175cd8500e597d3ec1'
    >>> n = int(h.hexdigest(),base=16)
    >>> print n
    73970130776712578303406724846815845410916448611708558169000368019946742824641
    
    0 讨论(0)
  • 2021-02-05 16:03

    python 3.x update

    import hashlib
    value = 'something to hash'
    t_value = value.encode('utf8')
    h = hashlib.sha256(t_value)
    h.hexdigest()
    n = int(h.hexdigest(),base=16)
    print(n)
    
    0 讨论(0)
提交回复
热议问题