in reply to Simple decrypt ?
As ikegami says, crypt is not a reversible process. That said, if you have a crypted string, the usual way of finding the original string is with a brute force dictionary attack.
sub encrypt { my $x = shift; chomp $x; return reverse substr crypt( $x, 'ar' ), 2; } # choose a random dictionary word my $dictionary = '/usr/share/dict/words'; my $secret_word; open my $dict_fh, '<', $dictionary or die "Can't read '$dictionary': $!"; my $line_no = 0; while ( my $word = <$dict_fh> ) { chomp $word; $secret_word = $word if rand() < 1/++$line_no; } close $dict_fh or die "Can't close dict: $!"; print "my secret word is: $secret_word\n"; my $encrypted_word = encrypt( $secret_word ); undef $secret_word; # figure out which word it was open $dict_fh, '<', $dictionary or die "Can't read '$dictionary': $!"; while ( my $word = <$dict_fh> ) { chomp $word; if ($encrypted_word eq encrypt($word)) { print "secret word is: $word\n"; last; } } close $dict_fh or die "Can't close dict: $!";
On my system, this runs in less than a second, even when it picks a word relatively late in the file. Also, the word it finds that works is not always the word that was originally selected. For example:
my secret word is: shellfishes secret word is: shellfish
This is because crypt ignores everything after eight characters of input. That means that even if you have to look for passwords outside the dictionary, you can restrict yourself to passwords eight characters or less.
|
|---|