[ t ] [ 10 atanh tanh 10 1.e-10 ~ ] unit-test
[ t ] [ 0.5 atanh tanh 0.5 1.e-10 ~ ] unit-test
-: test-gcd ( x y -- z )
- [ gcd nip ] [ gcd* ] 2bi [ assert= ] keep ;
-
-[ 100 ] [ 100 100 test-gcd ] unit-test
-[ 100 ] [ 1000 100 test-gcd ] unit-test
-[ 100 ] [ 100 1000 test-gcd ] unit-test
-[ 4 ] [ 132 64 test-gcd ] unit-test
-[ 4 ] [ -132 64 test-gcd ] unit-test
-[ 4 ] [ -132 -64 test-gcd ] unit-test
-[ 4 ] [ 132 -64 test-gcd ] unit-test
-[ 4 ] [ -132 -64 test-gcd ] unit-test
-
-[ 100 ] [ 100 >bignum 100 >bignum test-gcd ] unit-test
-[ 100 ] [ 1000 >bignum 100 >bignum test-gcd ] unit-test
-[ 100 ] [ 100 >bignum 1000 >bignum test-gcd ] unit-test
-[ 4 ] [ 132 >bignum 64 >bignum test-gcd ] unit-test
-[ 4 ] [ -132 >bignum 64 >bignum test-gcd ] unit-test
-[ 4 ] [ -132 >bignum -64 >bignum test-gcd ] unit-test
-[ 4 ] [ 132 >bignum -64 >bignum test-gcd ] unit-test
-[ 4 ] [ -132 >bignum -64 >bignum test-gcd ] unit-test
+[ 100 ] [ 100 100 gcd nip ] unit-test
+[ 100 ] [ 1000 100 gcd nip ] unit-test
+[ 100 ] [ 100 1000 gcd nip ] unit-test
+[ 4 ] [ 132 64 gcd nip ] unit-test
+[ 4 ] [ -132 64 gcd nip ] unit-test
+[ 4 ] [ -132 -64 gcd nip ] unit-test
+[ 4 ] [ 132 -64 gcd nip ] unit-test
+[ 4 ] [ -132 -64 gcd nip ] unit-test
+
+[ 100 ] [ 100 >bignum 100 >bignum gcd nip ] unit-test
+[ 100 ] [ 1000 >bignum 100 >bignum gcd nip ] unit-test
+[ 100 ] [ 100 >bignum 1000 >bignum gcd nip ] unit-test
+[ 4 ] [ 132 >bignum 64 >bignum gcd nip ] unit-test
+[ 4 ] [ -132 >bignum 64 >bignum gcd nip ] unit-test
+[ 4 ] [ -132 >bignum -64 >bignum gcd nip ] unit-test
+[ 4 ] [ 132 >bignum -64 >bignum gcd nip ] unit-test
+[ 4 ] [ -132 >bignum -64 >bignum gcd nip ] unit-test
[ 6 ] [
1326264299060955293181542400000006
1591517158873146351817850880000000
- test-gcd
+ gcd nip
] unit-test
[ 11 ] [
13262642990609552931815424
159151715887314635181785
- test-gcd
+ gcd nip
] unit-test
[ 3 ] [
13262642990609552931
1591517158873146351
- test-gcd
+ gcd nip
] unit-test
[ 26525285981219 ] [
132626429906095
159151715887314
- test-gcd
+ gcd nip
] unit-test
swap [ /mod [ over * swapd - ] dip ] keep (gcd)
] if ; inline recursive
-: (gcd*) ( a b -- c )
- [ [ mod ] keep swap (gcd*) ] unless-zero ; inline recursive
-
PRIVATE>
: ^ ( x y -- z )
: nth-root ( n x -- y ) swap recip ^ ; inline
: gcd ( x y -- a d )
- [ 0 1 ] 2dip (gcd) dup 0 < [ neg ] when ; foldable
-
-: gcd* ( x y -- d )
- (gcd*) dup 0 < [ neg ] when ; foldable
+ [ 0 1 ] 2dip (gcd) dup 0 < [ neg ] when ; foldable inline
: lcm ( a b -- c )
- [ * ] 2keep gcd* /i ; foldable
+ [ * ] 2keep gcd nip /i ; foldable
: divisor? ( m n -- ? )
- mod 0 = ;
+ mod 0 = ; inline
ERROR: non-trivial-divisor n ;
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: math.primes kernel math math.functions namespaces
-sequences accessors ;
+USING: math.primes kernel math math.functions math.primes
+namespaces sequences accessors ;
IN: crypto.rsa
! The private key is the only secret.
#! Loop until phi is not divisible by the public key.
dup rsa-primes [ * ] 2keep
[ 1 - ] bi@ *
- dup public-key gcd* 1 = [
+ dup public-key coprime? [
rot drop
] [
2drop modulus-phi