factor/basis/checksums/internet/internet.factor

16 lines
386 B
Factor
Raw Normal View History

! Copyright (C) 2010 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: checksums grouping io.binary kernel math sequences ;
IN: checksums.internet
SINGLETON: internet ! RFC 1071
INSTANCE: internet checksum
M: internet checksum-bytes
2014-02-27 17:03:00 -05:00
drop 2 <groups> [ le> ] map-sum
2011-11-23 21:49:33 -05:00
[ -16 shift ] [ 0xffff bitand ] bi +
[ -16 shift ] keep + bitnot 2 >le ;