1 ! Copyright (C) 2010 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: checksums grouping io.binary kernel math sequences ;
8 SINGLETON: internet ! RFC 1071
10 INSTANCE: internet checksum
12 M: internet checksum-bytes
13 drop 2 <groups> [ le> ] map-sum
14 [ -16 shift ] [ 0xffff bitand ] bi +
15 [ -16 shift ] keep + bitnot 2 >le ;