in reply to Encryption using perl core functions only
Xor against a shared secret key is a common approach to lightweight encryption. It is not secure. With a true random key of length greater than the message length it does become more secure.
my $str = 'hello world!'; my $key = 'just another perl hacker'; my $encoded = xor_encode($str,$key); my $decoded = xor_encode($encoded,$key); print "$encoded\n$decoded\n"; sub xor_encode { my ($str, $key) = @_; my $enc_str = ''; for my $char (split //, $str){ my $decode = chop $key; $enc_str .= chr(ord($char) ^ ord($decode)); $key = $decode . $key; } return $enc_str; }
|
|---|