Paste: internet checksum (RFC 1071)

Author: mrjbq7
Mode: factor
Date: Thu, 5 Aug 2010 03:30:54
Plain Text |
! Copyright (C) 2010 John Benediktsson
! See http://factorcode.org/license.txt for BSD license

USING: checksums io.binary kernel math sequences ;

IN: checksums.internet

SINGLETON: internet ! RFC 1071

INSTANCE: internet checksum

M: internet checksum-bytes
    drop 0 swap [ dup empty? ] [
        2 short cut-slice [ le> + ] dip
    ] until drop
    [ -16 shift ] [ HEX: ffff bitand ] bi +
    [ -16 shift ] keep + bitnot 2 >le ;

Annotation: cleaner

Author: mrjbq7
Mode: factor
Date: Thu, 5 Aug 2010 03:38:04
Plain Text |
M: internet checksum-bytes
    drop 0 swap 2 <sliced-groups> [ le> + ] each
    [ -16 shift ] [ HEX: ffff bitand ] bi +
    [ -16 shift ] keep + bitnot 2 >le ;

New Annotation

Summary:
Author:
Mode:
Body: