in reply to Encryption/Decryption
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Encryption/Decryption
by Anonymous Monk on Jan 08, 2004 at 01:15 UTC | |
by Anonymous Monk on Jan 08, 2004 at 16:15 UTC | |
by Anonymous Monk on Jan 08, 2004 at 17:06 UTC |