Yuuma

u/Yuuma


r/learnpython•

What I'm trying to do:

import random
import hashlib

value = random.getrandbits(256)
hash = hashlib.sha256(value)

From that, I get

TypeError: must be string or buffer, not long

I'm not quite sure what to do to value so that hashlib will hash the value as its binary value instead of as a string of characters. I basically want to make it so that something like the following passes:

value = 65

doSomething(value)

hashlib.sha256(value).hexdigest() == hashlib.sha256("A").hexdigest()
# returns true

...or something along those lines, except for reaaaaaaaaally large numbers. What would I have to do for that?

410





You've reached the end of this feed.