factor/extra/crypto/xor/xor.factor

13 lines
347 B
Factor
Raw Permalink Normal View History

2008-10-02 19:45:51 -04:00
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math sequences fry ;
2007-10-07 00:01:26 -04:00
IN: crypto.xor
2008-10-02 19:45:51 -04:00
: mod-nth ( n seq -- elt ) [ length mod ] [ nth ] bi ;
2007-10-07 00:01:26 -04:00
2008-10-02 19:45:51 -04:00
ERROR: empty-xor-key ;
: xor-crypt ( seq key -- seq' )
[ empty-xor-key ] when-empty
[ dup length <iota> ] dip '[ _ mod-nth bitxor ] 2map ;