4

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.

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.