I'm trying to convert a string into SHA1 checksum, which is what is used in Anki's csum field.
sfld: 'Bonjour' - Card front content without html (first part of flds, filtered).
csum: 4077833205 - A string SHA1 checksum of sfld, limited to 8 digits. PHP: (int)(hexdec(getFirstNchars(sha1($sfld), 8)))
So what I want to do here is convert the string Bonjour
and get 4077833205
.
However, although I tried following this post, I could not get the correct value.
int(hashlib.sha1(b"Bonjour").hexdigest(), 16) % (10**8) # 48831164
abs(hash(s)) % (10 ** 8) # 70576291
Also the digit is also not matched, and the csum value is 10 digit, although the doc says it is 8 digits. So I think I misunderstand it.
I checked my Anki database and found that the value of the column csum
is 7 to 10 digits, though 10 digit is the most common.
My question is, what is the equivalent of PHP's (int)(hexdec(getFirstNchars(sha1($sfld), 8)))
in Python and why is the answer above not matched to the correct value?