The hashed text from crypt can be longer than 8 characters unless you are working with ancient implementation
#!/usr/bin/env perl use strict; use warnings; # a non-random salt == 'salt' #SHA256 print crypt("secret",'$5$salt'); print "\n"; #SHA512 print crypt("secret",'$66salt'); print "\n"; # Oops, security gone, that is not what I meant # I meant this print crypt("secret",'$6$salt');
You also have Digest, which is core
#!/usr/bin/env perl use strict; use warnings; use Digest; my $algo = 'SHA-512'; sub hash { my $string = shift; my $salt; # bless whoever wrote this $salt .= join '',('.','/',(0..9),"a".."z","A".."Z")[rand 64] for ( +1..8); my $hasher = Digest->new($algo); $hasher->add($salt); $hasher->add($string); return $salt . $hasher->b64digest(); } sub checkHash { # First 8 characters are salt my $hash = shift; my $string = shift; my $salt = substr($hash,0,8); my $hasher = Digest->new($algo); $hasher->add($salt); $hasher->add($string); return $hash eq $salt . $hasher->b64digest(); } my $hash = hash('blahblah'); print "match" if checkHash($hash,'blahblah');
for encryption, you can xor, read more here Encryption using perl core functions only.

In reply to Re: crypto with core modules only by trippledubs
in thread crypto with core modules only by morgon

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.