All pastes #285885 Raw Edit

Mine

public text v1 · immutable
#285885 ·published 2006-12-20 03:17 UTC
rendered paste body
#!/usr/bin/perl

  while (<>) {

  $str = $_;

  $random = random_string(length($str));
  $crypt = $str ^ $random;
  $restored = $crypt ^ $random;

  print "Message string: $str\n";

  print "Random string: $random\n";

  print "Crypted string: $crypt\n";

  print "Restored string: $restored\n";

  print "\n";
 }

 #-------------------------------------------------

 # a random string of the same length as the
 # message is generated.. thats than
 # XOR'ed, character-by-character, on the
 # message, the result is mixed but when
 # you XOR this mix with the same random string,
 # you get the original message back

 #-------------------------------------------------

 sub random_string {
  my $ret;
  for (1 .. $_[0]) { $ret .= chr(rand 256) }
  return $ret;
 }