in reply to Anyone has simple encryption mechanism?
Here's a cheap way to get a non-repeating xor pattern of the proper length. It works by seeding rand with the key and relying on repeatability. The key is a single perl integer. The symmetric property* of xor encryption is handy.
All the map ... sprintf .... unpack stuff is just to coerce the binary encoded string into ascii, to avoid frying a tty's tiny brain.# Usage: cypher KEY, LIST; sub cypher { srand shift; my $string = join '', @_; my $here = 0; while ( 2*$here < length( $string)) { vec( $string, $here, 16) ^= int rand 1<<16; $here++; } $string; } my $encoded = cypher 12345, <<'EOT'; Listen, my children, and you shall hear Of the midnight ride of Paul Revere. EOT print map {sprintf '%x ', $_ } unpack 'C*', $encoded; print $/, cypher 12345, $encoded;
This is better than rot13, but probably is still weak crypto. The keyspace is small. Decryption depends on having the same particular implementation of rand. Regularities of rand can be exploited. But it is certainly enough to discourage casual readers.
* the same procedure is used for both encryption and decryption.
After Compline,
Zaxo
|
|---|