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.


In reply to Re: Simple decrypt ? by kyle
in thread Simple decrypt ? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.