File: prime_speed.py

package info (click to toggle)
python-crypto 2.0.1%2Bdfsg1-2.3%2Blenny0
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 744 kB
  • ctags: 935
  • sloc: ansic: 6,597; python: 3,598; makefile: 28; sh: 10
file content (24 lines) | stat: -rw-r--r-- 554 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

import time
from Crypto.Util import number

# Test of prime-generation speed

# This randfunc is deterministic, so we should always find the same primes.
chars = ''.join(map(chr, range(255, 0, -1)))
def randfunc (N):
    s = ''
    while len(s)<N:
        s += chars
    return s[:N]

def main ():
    for i in range(128, 2049, 128):
        s = time.time()
        N = number.getPrime(i, randfunc)
        e = time.time()
        N = str(N)
        print '%5i' % i, '%-7.03fsec' % (e-s), N[:10] + '...' + N[-10:]

if __name__ == '__main__':
    main()