sub nextPass {
my ($in, $alpha) = @_;
my @pass = split //, $in;
my @set = split //, $alpha;
my $current = $#pass;
my $done = 0;
while (!$done) {
# is the current character the end of the set?
if ($pass[$current] eq $set[$#set]) {
# set the current character to the start of the set
$pass[$current] = $set[0];
# is the current character the beginning of the pass?
if ($current == 0) {
# add the start of the set to the end of the pass and finish
push(@pass, $set[0]);
$done = 1;
} else {
$current--;
}
} else {
my $spot = index($alpha, $pass[$current]) + 1;
$pass[$current] = $set[$spot];
$done = 1;
}
}
my $out = join "", @pass;
return $out;
}
Name:
Anonymous2008-10-10 2:32
OP, seriously, read SICP.
Original: use Benchmark qw(:all);
my $alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !?";
sub nextPass {
my ($in, $alpha) = @_;
my @pass = split //, $in;
my @set = split //, $alpha;
my $current = $#pass;
my $done = 0;
while (!$done) {
# is the current character the end of the set?
if ($pass[$current] eq $set[$#set]) {
# set the current character to the start of the set
$pass[$current] = $set[0];
# is the current character the beginning of the pass?
if ($current == 0) {
# add the start of the set to the end of the pass and finish
push(@pass, $set[0]);
$done = 1;
} else {
$current--;
}
} else {
my $spot = index($alpha, $pass[$current]) + 1;
$pass[$current] = $set[$spot];
$done = 1;
}
}
my $out = join "", @pass;
return $out;
}