I want to convert the below function to Python but I guess the hashlib/Crypto library works differently to crypto-js:
class captha {
constructor() {
this.RECAPTCHA_ENCRYPT_SECRET = CryptoJS.MD5("token"); // Chave secreta como WordArray
console.log(this.RECAPTCHA_ENCRYPT_SECRET)
}
encryptToken(z) {
return CryptoJS.TripleDES.encrypt(z, this.RECAPTCHA_ENCRYPT_SECRET, {
mode: CryptoJS.mode.ECB
}).toString();
}
}
I tried
from Crypto.Hash import MD5
hash_obj = MD5.new(data=b"token")
hash_bytes = hash_obj.digest()
words = [int.from_bytes(hash_bytes[i:i+4], byteorder='little', signed=True) for i in range(0, len(hash_bytes), 4)]
sigBytes = len(hash_bytes)
print("Words:", words)
print("SigBytes:", sigBytes)
but it didn’t work.