Handbook
Glossary
checksum-bytes ( bytes checksum -- value )
Factor handbook
»
Input and output
»
Checksums
Prev:
checksum
Next:
checksum-stream ( stream checksum -- value )
Vocabulary
checksums
Inputs
bytes
a sequence of bytes
checksum
a checksum specifier
Outputs
value
a
byte-array
Generic word contract
Computes the checksum of all data in a sequence.
Examples
USING: checksums checksums.crc32 prettyprint ; B{ 1 10 100 } crc32 checksum-bytes .
B{ 78 179 254 238 }
Definition
IN:
checksums
GENERIC:
checksum-bytes
( bytes checksum -- value )
Methods
USING:
checksums
checksums.adler-32
kernel
math
math.vectors
ranges
sequences
;
M:
adler-32
checksum-bytes
drop
[
sum
1
+
]
[
[
dup
length
[1..b]
<reversed>
vdot
]
[
length
]
bi
+
]
bi
[
adler-32-modulus
mod
]
bi@
16
shift
bitor
;
USING:
checksums
checksums.common
kernel
;
M:
block-checksum
checksum-bytes
[
swap
add-checksum-bytes
get-checksum
]
with-checksum-state
;
USING:
checksums
checksums.bsd
kernel
math
sequences
;
M:
bsd
checksum-bytes
drop
0
[
[
[
-1
shift
]
[
1
bitand
15
shift
]
bi
+
]
dip
+
65535
bitand
]
reduce
;
USING:
checksums
io.encodings.binary
io.streams.byte-array
kernel
;
M:
checksum
checksum-bytes
[
binary
<byte-reader>
]
dip
checksum-stream
;
USING:
checksums
checksums.crc16
sequences
;
M:
crc16
checksum-bytes
init-crc16
[
(crc16)
]
each
finish-crc16
;
inline
USING:
checksums
checksums.crc32
sequences
;
M:
crc32
checksum-bytes
init-crc32
[
(crc32)
]
each
finish-crc32
;
inline
USING:
checksums
checksums.fletcher
kernel
;
M:
fletcher-16
checksum-bytes
drop
16
fletcher
;
USING:
checksums
checksums.fletcher
kernel
;
M:
fletcher-32
checksum-bytes
drop
32
fletcher
;
USING:
checksums
checksums.fletcher
kernel
;
M:
fletcher-64
checksum-bytes
drop
64
fletcher
;
USING:
checksums
checksums.fnv1
kernel
math
sequences
;
M:
fnv1-1024
checksum-bytes
drop
fnv1-1024-basis
swap
[
swap
fnv1-1024-prime
*
bitxor
fnv1-1024-mod
bitand
]
each
;
USING:
checksums
checksums.fnv1
kernel
math
sequences
;
M:
fnv1-128
checksum-bytes
drop
fnv1-128-basis
swap
[
swap
fnv1-128-prime
*
bitxor
fnv1-128-mod
bitand
]
each
;
USING:
checksums
checksums.fnv1
kernel
math
sequences
;