hashlib.md5 returns a weird object and indexing is also strange

Advertisements So I wanted to get to know how hashlib.md5 works and produced the following code: import hashlib a = b’yolo’ h = hashlib.md5(a).digest() b = h[6:10] print(h) print(b) Don’t mind the fact that I used "yolo" as a string. This is just for testing. Now when running this code, it produces b’O\xde\xd1FG6\xe7xe\xdf#,\xbc\xb4\xcd\x19′ b’\xe7xe\xdf’ which… Read More hashlib.md5 returns a weird object and indexing is also strange

Need Equivalent Python Script from JS

Advertisements Please help me convert below JS code to Python. const di_digest = CryptoJS.SHA1(di_plainTextDigest).toString(CryptoJS.enc.Base64); di_plainTextDigest is a String. I tried a few Python methods, but they do not work: result = hashlib.sha1(di_plainTextDigest.encode()) hexd = result.hexdigest() hexd_ascii = hexd.encode("ascii") dig2 = base64.b64encode(hexd_ascii) dig3 = dig2.decode("ascii") print(dig3 ) >Solution : To replicate the functionality of the JavaScript… Read More Need Equivalent Python Script from JS

MD5: Why am I getting different results for the same string?

Advertisements I expected the following code to return the same result in each case since the string values are the same but instead got a different result each time. What can I do (if anything) to address this? import hashlib a = ‘some text’ b = ‘some text’ hashA = hashlib.md5(b'{a}’).hexdigest()[:8] hashB = hashlib.md5(b'{b}’).hexdigest()[:8] hashT… Read More MD5: Why am I getting different results for the same string?

jsSHA and Python hashlib give different results for same input

Advertisements The following snippets use Nodejs and Python to calculate a hash from the same input content, but they give different results. It’s weird. // npm install jssha const jssha = require("jssha"); var s = new jssha("SHA-1", "TEXT"); s.setHMACKey("abc", "TEXT") s.update("123") console.log(s.getHMAC("B64")) The result is vpEGplDt4B9KMf3iOB0G9ftz5hI= import hmac import hashlib import base64 hashed = hmac.new(b"abc",… Read More jsSHA and Python hashlib give different results for same input