Sha1 different results

I’m using: SWI-Prolog version 9.0.4 (and 7.6.4)

I want the code to: calculate sha1 of a file

But what I’m getting is: two different results, depending on how I do it

My code looks like this:

?- file_sha1('./tom', Sum).
Sum = f572d396fae9206628714fb2ce00f72e94f2258f.

?- read_file_to_codes('./tom', Codes, []), variant_sha1(Codes, Sum).
Codes = [104, 101, 108, 108, 111, 10],
Sum = d7c7523f9bc4307dba513dcd0bd4f82e1d117774.

variant_sha1/ works at the term level. It computes the hash from a canonical serialization of the term, i.e., Codes in this case. That is something completely different than the hash of the bytes in a file.

1 Like