I am trying to solve a question that requires me to define a function that takes a positive integer T as an input and outputs a string so that
int(hashlib.sha256(string.encode()).hexdigest) = < T
is qualified. However, I do not understand how Python can output a string. I have thought of generating random strings or using str() but it seems unreasonable.
How will I be able to solve this question? Thank you very much.
hashlib wont work like that hashlib.sha256() is a class you need to update with string value for gettin hashed hex value and you cant convert hex value with just int() you need to add base parameter as 16
usage:
import hashlib
string="dumb"
hs=hashlib.sha256() # hs is element the hashlib.sha256() class
hs.update(string.encode()) # update hs with a string value
#now you can get hashed hex value
hs_hex=hs.hexdigest() #string hex hash value
hs_int=int(hs_hex,16) #int hash value
hs_int_str=str(hs_int) #string int hash value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With