[go: up one dir, main page]

Menu

[r2600]: / trunk / generate_regkeys.py  Maximize  Restore  History

Download this file

93 lines (79 with data), 2.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#! /usr/bin/env python
## The author disclaims copyright to this source code. In place of
## a legal notice, here is a poem:
##
## "Metaphysics"
##
## Matter: is the music
## of the space.
## Music: is the matter
## of the soul.
##
## Soul: is the space
## of God.
## Space: is the soul
## of logic.
##
## Logic: is the god
## of the mind.
## God: is the logic
## of bliss.
##
## Bliss: is a mind
## of music.
## Mind: is the bliss
## of the matter.
##
######################################################################
## This file implements the registration key generation tool.
##
import sys, os, getopt, hashlib
from cmbarter.modules import keygen
from cmbarter.settings import CMBARTER_REGISTRATION_KEY_PREFIX, SECRET_KEY
USAGE = """Usage: generate_regkeys.py --start=INTEGER --count=INTEGER
Print a sequence of valid registration keys.
--start=INTEGER the sequential number of the first key in the
sequence (must be between 0 and 4294967295)
--count=INTEGER number of consecutive keys to be printed
Example:
$ ./generate_regkeys.py --start=0 --count=100
... [Prints registration keys with sequence numbers 0-99]
"""
def parse_args(argv):
global start, count
try:
opts, args = getopt.gnu_getopt(argv, 'h', ['start=', 'count=', 'help'])
except getopt.GetoptError:
print(USAGE)
sys.exit(2)
if len(args) != 0:
print(USAGE)
sys.exit(2)
def srt2int(s):
try:
i = int(s)
if not (0 <= i <= 0xffffffff):
raise ValueError
except ValueError:
print(USAGE)
sys.exit()
else:
return i
for opt, arg in opts:
if opt in ('-h', '--help'):
print(USAGE)
sys.exit()
elif opt == '--start':
start = srt2int(arg)
elif opt == '--count':
count = srt2int(arg)
if __name__ == '__main__':
start = None
count = 0
parse_args(sys.argv[1:])
if (start is None) or (count == 0):
print(USAGE)
sys.exit()
gen = keygen.Keygen(SECRET_KEY, CMBARTER_REGISTRATION_KEY_PREFIX)
for i in range(start, start + count):
print gen.generate(i)