Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

ltoa.pl

By: a guest on Feb 4th, 2011  |  syntax: Perl  |  size: 0.82 KB  |  views: 137  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/perl -w
  2.  
  3. # OpenLDAP {APR1} to Apache $apr1$ hash converter
  4. # (C) 2011 Devin J. Pohly
  5. # You may use this code freely.  It would be nice to be credited.
  6.  
  7. use MIME::Base64;
  8.  
  9. while (<>) {
  10.         ($user, $hash) = split(/:/, $_);
  11.         unless ($hash =~ /^{APR1}/) {
  12.                 print STDERR "Not an Apache MD5 hash\n";
  13.                 next;
  14.         }
  15.  
  16.         chomp $hash;
  17.         $hash = decode_base64(substr($hash, 6));
  18.         ($hash, $salt) = (substr($hash, 0, 16), substr($hash, 16));
  19.         $hash = $hash;
  20.         $hash =~ s/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)/$1$7$13$2$8$14$3$9$15$4$10$16$5$11$6\0\0$12/s;
  21.         $hash = encode_base64($hash);
  22.         chomp $hash;
  23.         $hash =~ s/(.)(.)(.)(.)/$4$3$2$1/gs;
  24.         unless ($hash =~ /AA$/) {
  25.                 #print "Problem with hash\n";
  26.                 next;
  27.         }
  28.         $hash =~ s/AA$//;
  29.         $hash =~ tr|A-Za-z0-9+/|./0-9A-Za-z|;
  30.         print "$user:\$apr1\$$salt\$$hash\n"
  31. }