application/octet-stream
•
829 B
•
14 lines
[export hash [defn hash [data]
[def a 1]
[def b 0]
[when [string? data] [set! data [string->buffer data]]]
[when [not= [type-of data] :buffer] [exception :type-error "Can only hash buffers or strings"]]
[def v [buffer/view/u8* data]]
[dotimes [i [buffer/length data]]
[set! a [mod/int [add/int a [buffer/view/ref v i]] 65521]]
[set! b [mod/int [add/int a b] 65521]]]
[bit-or a [bit-shift-left b 16]]]]
[deftest "00620062" [fmt "{:08X}" [crypto/adler32/hash "a"]]]
[deftest "0F9D02BC" [fmt "{:08X}" [crypto/adler32/hash "asdQWE123"]]]
[deftest "796B110D" [fmt "{:08X}" [crypto/adler32/hash "DiesIstEinTestDerNujelAdler32Implementierung"]]]