diff --git a/basis/checksums/bsd/authors.txt b/basis/checksums/bsd/authors.txt new file mode 100644 index 0000000000..e091bb8164 --- /dev/null +++ b/basis/checksums/bsd/authors.txt @@ -0,0 +1 @@ +John Benediktsson diff --git a/basis/checksums/bsd/bsd-docs.factor b/basis/checksums/bsd/bsd-docs.factor new file mode 100644 index 0000000000..5253ab6284 --- /dev/null +++ b/basis/checksums/bsd/bsd-docs.factor @@ -0,0 +1,11 @@ +USING: help.markup help.syntax ; +IN: checksums.bsd + +HELP: bsd +{ $class-description "BSD checksum algorithm." } ; + +ARTICLE: "checksums.bsd" "BSD checksum" +"The BSD checksum algorithm implements simple and fast 16-bit checksum. It is a commonly used, legacy checksum algorithm implemented in BSD and available through the GNU " { $snippet "sum" } " utility." +{ $subsections bsd } ; + +ABOUT: "checksums.bsd" diff --git a/basis/checksums/bsd/bsd-tests.factor b/basis/checksums/bsd/bsd-tests.factor new file mode 100644 index 0000000000..0e430880da --- /dev/null +++ b/basis/checksums/bsd/bsd-tests.factor @@ -0,0 +1,5 @@ +USING: checksums.bsd checksums strings tools.test ; +IN: checksums.bsd + +{ 15816 } [ "Wikipedia" bsd checksum-bytes ] unit-test +{ 47937 } [ 10000 CHAR: a bsd checksum-bytes ] unit-test diff --git a/basis/checksums/bsd/bsd.factor b/basis/checksums/bsd/bsd.factor new file mode 100644 index 0000000000..0b61551a50 --- /dev/null +++ b/basis/checksums/bsd/bsd.factor @@ -0,0 +1,14 @@ +! Copyright (C) 2013 John Benediktsson. +! See http://factorcode.org/license.txt for BSD license. +USING: checksums kernel math sequences ; +IN: checksums.bsd + +SINGLETON: bsd + +M: bsd checksum-bytes ( bytes checksum -- value ) + drop 0 [ + [ [ -1 shift ] [ 1 bitand 15 shift ] bi + ] dip + + 0xffff bitand + ] reduce ; + +INSTANCE: bsd checksum diff --git a/basis/checksums/bsd/summary.txt b/basis/checksums/bsd/summary.txt new file mode 100644 index 0000000000..14d83b0b03 --- /dev/null +++ b/basis/checksums/bsd/summary.txt @@ -0,0 +1 @@ +BSD checksum algorithm