A simple example:
use strict; use warnings; my $plaintext = 'We are discovered. Flee at once!'; my $key = 'CorrectBatteryHorseStaple'; print "Original message: $plaintext\n"; my $ciphertext = cypher($plaintext,$key); my $ucode = pack("u",$ciphertext); print " Encoded message: $ucode (uuencoded)\n"; my $decoded = cypher($ciphertext,$key); print " Decoded message: $decoded\n"; sub cypher { my $plain = shift; my $key = shift; my $i=0; $key x= ( 1 + length($plain)/length($key) ); return $plain ^ substr($key,0,length($plain)); }
It requires a key that is XORd with the plaintext to produce the ciphertext. Calling the subroutine again with the ciphertext and the same key will reproduce the plaintext.
Update: copied example into response, against future changes to scratchpad. Updated again to use uuencode to display key, also removed unnecessary loop.
In reply to Re: Encryption/Decryption Program:
by GotToBTru
in thread Encryption/Decryption Program:
by Perl Beginner01
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |