Skip to content

Instantly share code, notes, and snippets.

@aht
Created January 16, 2010 07:19
Show Gist options
  • Save aht/278715 to your computer and use it in GitHub Desktop.
Save aht/278715 to your computer and use it in GitHub Desktop.
#!/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