factor/extra/crypto/barrett/barrett.factor

15 lines
339 B
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
USING: kernel math math.functions ;
IN: crypto.barrett
: barrett-mu ( n size -- mu )
#! Calculates Barrett's reduction parameter mu
#! size = word size in bits (8, 16, 32, 64, ...)
2008-04-03 14:57:33 -04:00
! over log2 1+ over / 2 * >r 2 swap ^ r> ^ swap / floor ;
[
[ log2 1+ ] [ / 2 * ] bi*
] [
2^ rot ^ swap /i
] 2bi ;
2007-09-20 18:09:08 -04:00