checksums.fletcher: adding Fletcher's checksum in 16/32/64-bits.
parent
7c9e0f3017
commit
52498a9f67
|
@ -0,0 +1 @@
|
||||||
|
John Benediktsson
|
|
@ -0,0 +1,17 @@
|
||||||
|
USING: help.markup help.syntax ;
|
||||||
|
IN: checksums.fletcher
|
||||||
|
|
||||||
|
HELP: fletcher-16
|
||||||
|
{ $class-description "Fletcher's 16-bit checksum algorithm." } ;
|
||||||
|
|
||||||
|
HELP: fletcher-32
|
||||||
|
{ $class-description "Fletcher's 32-bit checksum algorithm." } ;
|
||||||
|
|
||||||
|
HELP: fletcher-64
|
||||||
|
{ $class-description "Fletcher's 64-bit checksum algorithm." } ;
|
||||||
|
|
||||||
|
ARTICLE: "checksums.fletcher" "Fletcher's checksum"
|
||||||
|
"The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John G. Fletcher at Lawrence Livermore Labs in the late 1970s."
|
||||||
|
{ $subsections fletcher-16 fletcher-32 fletcher-64 } ;
|
||||||
|
|
||||||
|
ABOUT: "checksums.fletcher"
|
|
@ -0,0 +1,10 @@
|
||||||
|
USING: checksums kernel sequences tools.test ;
|
||||||
|
IN: checksums.fletcher
|
||||||
|
|
||||||
|
{
|
||||||
|
{ 51440 3948201259 14034561336514601929 }
|
||||||
|
} [
|
||||||
|
"abcde" { fletcher-16 fletcher-32 fletcher-64 }
|
||||||
|
[ checksum-bytes ] with map
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
! Copyright (C) 2013 John Benediktsson
|
||||||
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
|
|
||||||
|
USING: checksums grouping io.binary kernel locals math sequences
|
||||||
|
;
|
||||||
|
|
||||||
|
IN: checksums.fletcher
|
||||||
|
|
||||||
|
SINGLETON: fletcher-16
|
||||||
|
SINGLETON: fletcher-32
|
||||||
|
SINGLETON: fletcher-64
|
||||||
|
|
||||||
|
INSTANCE: fletcher-16 checksum
|
||||||
|
INSTANCE: fletcher-32 checksum
|
||||||
|
INSTANCE: fletcher-64 checksum
|
||||||
|
|
||||||
|
:: fletcher ( seq k -- n )
|
||||||
|
k 16 / :> chars
|
||||||
|
k 2 / 2^ :> base
|
||||||
|
base 1 - :> modulo
|
||||||
|
0 0 seq chars <groups> [
|
||||||
|
be> + modulo mod [ + modulo mod ] keep
|
||||||
|
] each [ base * ] [ + ] bi* ; inline
|
||||||
|
|
||||||
|
M: fletcher-16 checksum-bytes drop 16 fletcher ;
|
||||||
|
M: fletcher-32 checksum-bytes drop 32 fletcher ;
|
||||||
|
M: fletcher-64 checksum-bytes drop 64 fletcher ;
|
|
@ -0,0 +1 @@
|
||||||
|
Fletcher's checksum algorithm
|
Loading…
Reference in New Issue