Skip to content

Instantly share code, notes, and snippets.

@mdeous
Created January 27, 2011 19:56
Show Gist options
  • Save mdeous/799109 to your computer and use it in GitHub Desktop.
Save mdeous/799109 to your computer and use it in GitHub Desktop.
Perl SSHA
#!/usr/bin/perl
use strict;
use warnings;
use MIME::Base64;
# ssha uses sha1($pass.$salt)
my $line = "{SSHA}EOmijWjrWh9KVWSDWb6hq4Hd3UFMcWIyOVRCUw==";
chomp ($line);
$line =~ s/^{SSHA}//;
next unless length $line == 40;
my $hash = decode_base64 ($line);
my ($a, $b, $c, $d, $e, $s1, $s2) = unpack ("NNNNNNN", $hash);
my $salt_hex = sprintf ("%08x%08x", $s1, $s2);
my $salt;
$salt .= chr hex substr ($salt_hex, 0, 2);
$salt .= chr hex substr ($salt_hex, 2, 2);
$salt .= chr hex substr ($salt_hex, 4, 2);
$salt .= chr hex substr ($salt_hex, 6, 2);
$salt .= chr hex substr ($salt_hex, 8, 2);
$salt .= chr hex substr ($salt_hex, 10, 2);
$salt .= chr hex substr ($salt_hex, 12, 2);
$salt .= chr hex substr ($salt_hex, 14, 2);
printf ("%08x%08x%08x%08x%08x:%s\n", $a, $b, $c, $d, $e, $salt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment