RC4 is about your easiest encryption. There are alot of others too, RC5, and Rijndael. The biggest problem for beginners is the need to make either the data or key a certain blocksize. Some algorithms don't require this.

Here are a couple of examples:

#!/usr/bin/perl use Crypt::RC4; $passphrase = "rumpelstiltskin"; $plaintext= qw(qqq"""""""''''''';;;;;qwweeerrrtttyyyy); $encrypted = RC4( $passphrase, $plaintext ); $decrypt = RC4( $passphrase, $encrypted ); print "$plaintext\n$encrypted\n$decrypt\n";

or

#!/usr/bin/perl use Crypt::RC5; $key = 'e726f4a56b3e4f'; $rc5 = new Crypt::RC5($key, '12' ); open (FH,"< /etc/passwd"); while(<FH>){ $file .= $_ } close FH; print "$file\n"; $cipher = $rc5->encrypt($file); $rc5d = new Crypt::RC5($key, '12' ); $plain = $rc5d->decrypt($cipher); print "$plain\n";

or

#!/usr/bin/perl use Crypt::Rijndael; $key = chr(0) x 32; #key is all nulls here substr($key, 0, 1) = chr(1); #put 1 chr(1)in key just for fun print "key->$key\n"; $plaintext= "adrqwqqqqqqqqqqqqqqqqqqqqqqwrxcq4gfq3g2q45g2q43g5"; print "plaintext->$plaintext\n"; $plaintext16= get16($plaintext); print "plaintext16->$plaintext16\n"; $cbc = new Crypt::Rijndael $key, Crypt::Rijndael::MODE_CBC; $crypted = $cbc->encrypt($plaintext16); print 'crypted->',"$crypted\n"; #keep encrypted string in different pr +int string #to avoid character corruption of prec +eding string $cbc = new Crypt::Rijndael $key, Crypt::Rijndael::MODE_CBC; $decrypted = $cbc->decrypt($crypted); print "decrypted->$decrypted\n"; #this sub makes all data blocksize of 16 bytes. sub get16 { my $data = shift; print "data=$data\n"; return "\0" x ( 16 - length($data)%16 ) . $data; } exit;

In reply to Re: Encryption/Decryption by zentara
in thread Encryption/Decryption 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.