~dustin-spy/twisted/dustin

« back to all changes in this revision

Viewing changes to twisted/secsh/primes.py

  • Committer: z3p
  • Date: 2002-07-17 14:44:36 UTC
  • Revision ID: vcs-imports@canonical.com-20020717144436-6dce525e73d836e2
moving secsh to conch.
Conch: The Twisted Shell

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import random
2
 
 
3
 
def parseModuliFile(filename):
4
 
    lines = open(filename).readlines()
5
 
    primes = {}
6
 
    for l in lines:
7
 
        l = l.strip()
8
 
        if  not l or l[0]=='#':
9
 
            continue
10
 
        tim, typ, tst, tri, size, gen, mod = l.split()
11
 
        size = int(size) + 1
12
 
        gen = int(gen)
13
 
        mod = long(mod, 16)
14
 
        if not primes.has_key(size):
15
 
            primes[size] = []
16
 
        primes[size].append((gen, mod))
17
 
    return primes
18
 
 
19
 
def getDHPrimeOfBits(primes, bits):
20
 
    keys = primes.keys()
21
 
    keys.sort(lambda x,y:cmp(abs(x-bits),abs(y-bits)))
22
 
    realBits = keys[0]
23
 
    return random.choice(primes[realBits])
24
 
 
25
 
 
26