#!/usr/bin/perl # q1.pl - Don Yang (uguu.org) # # 08/05/03 $template = "P.bK .bEaE."; $data = "kfool#tlqog"; $key = 3; sub xor_string { $r = ''; # Can remove this line if function is called only once $r .= chr ($_[1] ^ ord $_) foreach ($_[0] =~ /./g); $r; } sub remove_space { ($x = $_[0]) =~ s/ //g; return $x; } sub format_text { $t = $_[1]; foreach $x ($_[0] =~ /./g) { $x = ord $x; print ( ($x > 64 && $x < 91) ? (substr $t, 0, ($x -= 64)) : ($x > 96 && $x < 123) ? (' ' x ($x - 96)) : "\n" ); ($x < 27) && ($t = substr $t, $x); } } format_text remove_space($template), remove_space("header $template$data" . xor_string($data, $key));