]> gitweb.factorcode.org Git - factor.git/blob - basis/math/primes/safe/safe-docs.factor
Solution to Project Euler problem 65
[factor.git] / basis / math / primes / safe / safe-docs.factor
1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators.short-circuit help.markup help.syntax kernel
4 math math.functions math.primes random ;
5 IN: math.primes.safe
6
7 HELP: next-safe-prime
8 { $values
9     { "n" integer }
10     { "q" integer }
11 }
12 { $description "Tests consecutive numbers and returns the next safe prime. A safe prime is desirable in cryptography applications such as Diffie-Hellman and SRP6." } ;
13
14 HELP: random-safe-prime
15 { $values
16     { "numbits" integer }
17     { "p" integer }
18 }
19 { $description "Returns a safe prime number " { $snippet "numbits" } " bits in length, with the topmost bit set to one." } ;
20
21 HELP: safe-prime?
22 { $values
23     { "q" integer }
24     { "?" "a boolean" }
25 }
26 { $description "Tests whether the number is a safe prime. A safe prime " { $snippet "p" } " must be prime, as must " { $snippet "(p - 1) / 2" } "." } ;
27
28
29 ARTICLE: "math.primes.safe" "Safe prime numbers"
30 "The " { $vocab-link "math.primes.safe" } " vocabulary implements words to calculate safe prime numbers. Safe primes are of the form p = 2q + 1, where p,q are prime. Safe primes have desirable qualities for cryptographic applications." $nl
31
32 "Testing if a number is a safe prime:"
33 { $subsection safe-prime? }
34 "Generating safe prime numbers:"
35 { $subsection next-safe-prime }
36 { $subsection random-safe-prime } ;
37
38 ABOUT: "math.primes.safe"