-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmktokens
executable file
·82 lines (71 loc) · 2.36 KB
/
mktokens
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
#!/usr/bin/perl
### GAH PERL NOOOOOOO
use strict;
use warnings;
use Getopt::Std;
use vars qw( $VERSION @VOWELS @CONSONANTS );
$VERSION = '1.0';
# Digest::BubbleBabble from Benjamin Trott, cpan@stupidfool.org
@VOWELS = split //, q{aeuioy};
@CONSONANTS = split //, q{bcdfghklmnprstvzx};
sub bubblebabble {
my ($input) = @_;
my @dgst = map { ord } split //, $input;
my $dlen = length $input;
my $seed = 1;
my $rounds = int($dlen / 2) + 1;
my $retval = 'x';
for my $i (0..$rounds-1) {
if ($i+1 < $rounds || $dlen % 2) {
my $idx0 = ((($dgst[2 * $i] >> 6) & 3) + $seed) % 6;
my $idx1 = ($dgst[2 * $i] >> 2) & 15;
my $idx2 = (($dgst[2 * $i] & 3) + $seed / 6) % 6;
$retval .= $VOWELS[$idx0] . $CONSONANTS[$idx1] . $VOWELS[$idx2];
if ($i+1 < $rounds) {
my $idx3 = ($dgst[2 * $i + 1] >> 4) & 15;
my $idx4 = $dgst[2 * $i + 1] & 15;
$retval .= $CONSONANTS[$idx3] . q/-/ . $CONSONANTS[$idx4];
$seed = ($seed * 5 + $dgst[2 * $i] * 7 +
$dgst[2 * $i + 1]) % 36;
}
} else {
my $idx0 = $seed % 6;
my $idx1 = 16;
my $idx2 = $seed / 6;
$retval .= $VOWELS[$idx0] . $CONSONANTS[$idx1] . $VOWELS[$idx2];
}
}
$retval .= 'x';
return $retval;
}
# --- END
sub readch {
my ($chars, $fh) = @_;
my $retval = '';
sysread $fh, $retval, $chars;
return $retval;
}
sub usage {
my ($msg) = @_;
print <<'EOB';
Usage: mktokens [options] count
-c category name
-s size of token hash [default: 8]
EOB
die "\n[x] $msg\n" if $msg;
exit 0;
}
my $count = 1;
my $size = 8;
my $cat = '';
my %options=();
getopts('c:s:h', \%options);
usage('not enough arguments!') unless scalar @ARGV > 0;
usage() if $options{h};
$cat = "$options{c}:1:" if $options{c} and $options{c} =~ m/\A ([[:alnum:]_-]+) \Z/msix;
$size = $options{s} if $options{s} and $options{s} =~ m/\A (\d+) \Z/msix;
$count = $ARGV[0] if $ARGV[0] and $ARGV[0] =~ m/\A (\d+) \Z/msix;
open my $fh, '<', '/dev/urandom';
print {*STDERR} "[+] Generating $count token", ($count > 1 ? 's' : ''), " [$size bytes of entropy]", $cat ? " with prefix '$cat'" : '', $/;
print $cat, bubblebabble(readch($size, $fh)), $/ for (1 .. $count);
close $fh;