Skip to content

Instantly share code, notes, and snippets.

@pstray
Created December 7, 2018 12:29
Show Gist options
  • Save pstray/1e36ed8f0b252ccc9dac617644132949 to your computer and use it in GitHub Desktop.
Save pstray/1e36ed8f0b252ccc9dac617644132949 to your computer and use it in GitHub Desktop.
Generate various crypt for a password
#! /usr/bin/perl
use strict;
use Term::ReadKey;
my $pass = shift;
unless ($pass) {
$| = 1;
print "Password: ";
ReadMode 'noecho';
$pass = ReadLine 0;
ReadMode 'normal';
printf "\n";
chomp $pass;
}
my @chars = ('a' .. 'z', 'A' .. 'Z', '0' .. '9', '.', '/');
my @types = (
[ 'DES' => 2, '%s%s' ],
# [ 'BSDi' => 3, '_%s%s' ],
[ 'MD5' => 8, '$1$%s$%s' ],
#[ 'bcrypt' => 100, '$2a$%s$%s' ], # also 2, 2b, 2x, 2y;
# [ 'NTHASH' => 0, '$3$%s$%x' ],
[ 'SHA-256' => 16, '$5$%s$%s' ],
[ 'SHA-512' => 16, '$6$%s$%s' ],
# md5 Solaris MD5 $md5,rounds=5000$GUBv0xjJ$$mSwgIswdjlTY0YxV7HBVm0
# sha1 PBKDF1 with SHA-1 $sha1$40000$jtNX3nZ2$hBNaIXkt4wBI2o5rsi8KejSjNqIq
);
my($max_salt) = sort { $b <=> $a } map { $_->[1] } @types;
my $src_salt = join '', @chars[map{rand +@chars} 1..$max_salt];
for my $t (@types) {
my($id,$salt_length,$fmt) = @$t;
my $salt = sprintf $fmt, substr($src_salt, 0, $salt_length), 'stuff';
my $crypt = crypt $pass, $salt;
printf "%-10s%s\n", "$id:", $crypt if length $crypt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment