]> gitweb.factorcode.org Git - factor.git/commitdiff
Added bitroll.
authorDoug Coleman <erg@trifocus.net>
Sat, 27 Aug 2005 19:54:31 +0000 (19:54 +0000)
committerDoug Coleman <erg@trifocus.net>
Sat, 27 Aug 2005 19:54:31 +0000 (19:54 +0000)
contrib/crypto/common.factor

index 163b8cb42d3a61a3fd5e9131b3cba5d99adbe541..e93711310369410e7ebe45053b5939487951a831 100644 (file)
@@ -5,6 +5,20 @@ unparser test parser lists ;
 : rot4 ( a b c d -- b c d a )
     >r rot r> swap ;
 
+: (shift-mod) ( n s w -- n )
+     >r shift r> 1 swap shift mod ;
+
+: bitroll ( n s w -- n )
+     #! Roll n by s bits to the left, wrapping around after
+     #! w bits.
+     [ mod ] keep
+     over 0 < [ [ + ] keep ] when
+     [
+         (shift-mod)
+     ] 3keep
+     [ - ] keep (shift-mod) bitor ;
+
+
 : w+ ( int -- int )
     + HEX: ffffffff bitand ;