Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

incremental string generator - perl

Name: Anonymous 2008-10-09 14:27

real    1m21.853s
user    1m21.070s
sys     0m0.165s


This is on a 1.8ghz c2d. Incremental string generator from charset (999999 passes). Can anyone think of a more efficient way?

my $alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !?";

my $pass = "a";

for (my $i = 0; $i < 1000000; $i++) {
  $pass = nextPass($pass, $alpha);
}

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: Anonymous 2008-10-10 8:43

>>24
It uses UTF-8.

For UCS-2 or UTF-32, just change byte to word and dword, and resb to resw and resd.

Also, it's relatively easy to make it use a character map, I just thought I'd make it OMG OPTIMIZED.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List