It doesn't really do base64 encoding in the usual sense, but rather
only uses 24 bits of every 32 bit group of the md5 hash (thus the shorter length of the result).
Also, it pads the input password with zeros (up to length 16), which produces
a different md5 hash to start with.
Anyway, here's a quick-n-dirty reimplementation of the C code in Perl:
#!/usr/bin/perl
use Digest::MD5;
my $passw = "cisco";
$passw .= "\0" x (16-length($passw)); # pad with zeros
my $itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr
+stuvwxyz";
sub pseudo_base64 {
my $md5 = shift;
my $s64 = "";
for my $i (0..3) {
my $v = unpack "V", substr($md5, $i*4, 4);
for (1..4) {
$s64 .= substr($itoa64, $v & 0x3f, 1);
$v >>= 6;
}
}
return $s64;
}
print pseudo_base64(Digest::MD5::md5($passw)),"\n"; # 2KFQnbNIdI.2KY
+OU
|