Created
January 16, 2010 07:19
-
-
Save aht/278715 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2.6 | |
""" | |
Usage: python ./rsa_tuples [-s] n | |
Generate `n` RSA tuples using 200-digit primes. | |
Requires: | |
ent.py <http://modular.fas.harvard.edu/ent/ent_py> | |
stream.py <http//github.com/aht/stream.py> | |
""" | |
import ent | |
from stream import ForkedFeeder, PCollector, chop | |
NUM_DIGITS = 200 | |
def random_primes(n): | |
"""Yield `n` random primes.""" | |
for _ in range(n): | |
yield ent.random_prime(num_digits=NUM_DIGITS) | |
def sequential_main(n): | |
"""Print `n` RSA (e, d, n) tuples sequentially.""" | |
for p, q in random_primes(2*n) >> chop(2): | |
print ent.rsa_init(p, q) | |
def parallel_main(n): | |
"""Print `n` RSA (e, d, n) tuples using random primes | |
generated by two child processes. | |
""" | |
primes = PCollector() | |
for _ in range(2): | |
ForkedFeeder(random_primes, n) >> primes | |
for p, q in primes >> chop(2): | |
print rsa_init(p, q) | |
if __name__ == '__main__': | |
import sys | |
if sys.argv[1] == '-s': | |
sequential_main(int(sys.argv[2])) | |
else: | |
parallel_main(int(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment