0

I have created a python loop that should be passing the output of the digest back into the msg portion of the digest command, however i am ending up with exact same has no matter how many times i run the loop

from __future__ import print_function;
import hmac;
import hashlib;
import base64;

mydigest = base64.b64encode(hmac.new(b"salt", msg="mymessage", digestmod=hashlib.sha256).digest()).decode();

for x in range(0, 10000):
  mydigest = base64.b64encode(hmac.new(b"salt", msg="(mydigest)", digestmod=hashlib.sha256).digest()).decode();
  print (mydigest);

1 Answer 1

2

You probably want

mydigest = base64.b64encode(hmac.new(b"salt", msg=mydigest, digestmod=hashlib.sha256).digest()).decode();

There's no string interpolation in "ordinary" strings in Python (strings with interpolation — the so-called f-strings — recently appeared in Python 3.6), so "(mydigest)" is a fixed string that has nothing with variable mydigest.

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.