-
Notifications
You must be signed in to change notification settings - Fork 0
/
nato_alpha
executable file
·236 lines (159 loc) · 4.47 KB
/
nato_alpha
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/perl
=head1 NAME
- nato_alpha
nato_alpha - script for reading aloud passwords
=head1 PREREQUISITES
=over 4
=item 1
Minimally I<Perl 5.8.4>.
=back
=head1 SYNOPSIS
USAGE: nato_alpha [-new] [<password plain text>]
Provides verbal script of password to be read aloud for phone or voicemail.
If your password has shell interpreted characters, run without arguments (recommended).
-new generate new password
nato_alpha weTi202*rjf0
lowercase w as in whiskey
lowercase e as in echo
UPPERCASE T as in TANGO
lowercase i as in india
The number 2
The number 0
The number 2
an * asterisk
lowercase r as in romeo
lowercase j as in juliet
lowercase f as in foxtrot
The number 0
=head1 DESCRIPTION
=head1 METHODS/FUNCTIONS
=cut
## Packages used
use strict;
use warnings;
use autouse 'Data::Dumper' => 'Dumper';
use Getopt::Long qw(:config auto_help);
### GLOBAL VARIABLES
my $SETTING = {};
my $letter = "a";
my %CONVERT = map { $letter++, $_ }
qw( alpha bravo charlie delta echo foxtrot golf hotel india juliet kilo lima mike november oscar papa quebec romeo sierra tango uniform victor whiskey x-ray yankie zulu );
my %SYMBOLS = (
'!' => "exclamation mark",
'"' => "double quotation mark",
'#' => "number (hash) sign",
'$' => "dollar sign",
'%' => "percent sign",
'&' => "ampersand",
'\'' => "apostrophe (single quote)",
'(' => "left parenthesis",
')' => "right parenthesis",
'*' => "asterisk",
'+' => "plus sign",
',' => "comma",
'-' => "hyphen (dash)",
'.' => "period (fullstop)",
'/' => "forward slash",
':' => "colon",
';' => "semi-colon ",
'<' => "less than sign",
'=' => "equals sign",
'>' => "greater than sign",
'?' => "question mark",
'@' => "at symbol",
'[' => "left square bracket",
'\\' => "backslash",
']' => "right square bracket",
'^' => "caret symbol",
'_' => "underscore",
'`' => "backtick (reverse quote)",
'{' => "left curly brace",
'|' => "vertical bar (pipe) symbol",
'}' => "right curly brace",
'~' => "tilde symbol",
'€' => "Euro",
);
############################################
################## MAIN ##################
############################################
=pod
TODO LIST:
=cut
GetOptions($SETTING, qw( debug new ));
my $pwd = $ARGV[0];
if( !$pwd && !$SETTING->{new}){
local $| = 1;
print "Enter password [new password generated]: ";
chomp($pwd = <STDIN>);
} elsif( !$SETTING->{new} ){
print "\tYou ran this with the password in the command line.
\tRecommend running without arguements to avoid shell escaping.\n";
}
if( !$pwd ){
($pwd) = generatePassword();
}
print "\nPassword: $pwd\n\n";
my $lastUpper = 2;
foreach my $char ( split //, $pwd ){
my $pre = '';
my $post = '';
my $upper = $char =~ /[A-Z]/;
if( $char =~ /[a-z]/i ){
$pre = ($upper ? "UPPERCASE": "lowercase" );
$lastUpper = $upper;
$post = "as in ". ( $upper ? uc( $CONVERT{lc $char} || $char ) : ( $CONVERT{$char} || $char ) );
} elsif ( $char =~ /\d/ ){
$pre = "The number";
} else {
$post = exists($SYMBOLS{$char}) ? $SYMBOLS{$char} : "symbol";
$pre = $post =~ /^[aeiou]/i ? "an" : "a";
}
printf "%12s %s %s\n", $pre, $char, $post;
}
print "\n";
################ MAIN END ##################
############################################
############### FUNCTIONS ################
############################################
sub generatePassword {
=pod
=over 4
=item generatePassword
I<Arguements>:
I<Returns>:
=back
=cut
my( $length ) = @_;
$length = 10 unless $length;
my $password = '';
my $possible = 'abcdefghijkmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWXYZ~!@#$%^&*()-=_+|[]{};<>,./?';
while (length($password) < $length) {
$password .= substr($possible, (int(rand(length($possible)))), 1);
$password =~ s/^\W//g; # must start with an alphanumeric
}
return $password
} ################################################## END generatePassword
sub debug {
=pod
=over 4
=item debug
I<Arguments>:
I<Returns>:
=back
=cut
my(@args) = @_;
return unless $SETTING->{debug};
foreach my $arg (@args){
if( ref( $arg ) ){
print "DEBUG START:\n", Dumper( $arg );
print "DEBUG END\n";
} else {
print "DEBUG: $arg\n";
}
}
} ################################################## END debug
=head1 AUTHORS
Nikola Janceski <[email protected]>
=head1 BUGS and CAVEATS
=cut
__END__