]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/crypto/rsa/rsa.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / extra / crypto / rsa / rsa.factor
index ccf17da4e809f2dea433988a16a12e78652e3ba2..917e98a6ee52cc7f251e7abf19a99ee737de90e4 100644 (file)
@@ -1,5 +1,7 @@
-USING: math.miller-rabin kernel math math.functions namespaces
-sequences ;
+! Copyright (C) 2008 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: math.primes kernel math math.functions namespaces
+sequences accessors ;
 IN: crypto.rsa
 
 ! The private key is the only secret.
@@ -16,15 +18,15 @@ C: <rsa> rsa
 
 <PRIVATE
 
-: public-key 65537 ; inline
+CONSTANT: public-key 65537
 
 : rsa-primes ( numbits -- p q )
-    2/ 2 unique-primes first2 ;
+    2/ 2 swap unique-primes first2 ;
 
 : modulus-phi ( numbits -- n phi ) 
     #! Loop until phi is not divisible by the public key.
     dup rsa-primes [ * ] 2keep
-    [ 1- ] bi@ *
+    [ 1 - ] bi@ *
     dup public-key gcd nip 1 = [
         rot drop
     ] [
@@ -39,7 +41,7 @@ PRIVATE>
     public-key <rsa> ;
 
 : rsa-encrypt ( message rsa -- encrypted )
-    [ rsa-public-key ] keep rsa-modulus ^mod ;
+    [ public-key>> ] [ modulus>> ] bi ^mod ;
 
 : rsa-decrypt ( encrypted rsa -- message )
-    [ rsa-private-key ] keep rsa-modulus ^mod ;
\ No newline at end of file
+    [ private-key>> ] [ modulus>> ] bi ^mod ;