Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deleting passgen, adding randump to replace it
- Loading branch information
Ali Clark
committed
Dec 25, 2011
1 parent
1727c7b
commit 9a3eab4
Showing
2 changed files
with
64 additions
and
10 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/python | ||
|
||
import sys | ||
import argparse | ||
|
||
def base95(f, c, n, p): | ||
s = '' | ||
|
||
if p: | ||
pc = ' ' | ||
else: | ||
pc = '' | ||
|
||
for i in range(n): | ||
while True: | ||
d = f.read((c - len(s)) * 3) # discard roughly 2/3 | ||
s += ''.join(filter(lambda x: (ord(x) >= ord(' ')) and (ord(x) <= ord('~')), d)) | ||
|
||
if len(s) >= c: | ||
print ''.join(map(lambda x: pc + x, s[:c])) | ||
s = s[c:] | ||
break | ||
|
||
def base64(f, c, n, p): | ||
chars = ['+', '/'] | ||
for i in range(26): | ||
chars.append(chr(ord('a') + i)) | ||
chars.append(chr(ord('A') + i)) | ||
for i in range(10): | ||
chars.append(chr(ord('0') + i)) | ||
|
||
if p: | ||
pc = ' ' | ||
else: | ||
pc = '' | ||
|
||
for i in range(n): | ||
print ''.join(map(lambda x: pc + chars[ord(x) & 63], f.read(c))) | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-p', '--pad', action='store_true', default=False) | ||
parser.add_argument('-c', '--bytes', type=int, default=12) | ||
parser.add_argument('-n', '--lines', type=int, default=1) | ||
parser.add_argument('-b', '--base', type=int, default=95) | ||
|
||
args = parser.parse_args() | ||
|
||
if args.base != 95 and args.base != 64: | ||
print 'unknown base, use 64 or 95 (default)' | ||
sys.exit(1) | ||
|
||
f = open('/dev/random', 'rb') | ||
|
||
if args.base == 95: | ||
base95(f, args.bytes, args.lines, args.pad) | ||
|
||
if args.base == 64: | ||
base64(f, args.bytes, args.lines, args.pad) | ||
|
||
f.close() | ||
|
||
if __name__ == '__main__': | ||
main() |