++
ColinHorne on a very respectable first Japh!
Here are a few tips for "golfing" it down, should you desire to make it even more terse, while still preserving the important elements:
- Convert 'shift' to 'pop' wherever @_ contains a single argument.
- Get rid of the extra "{ }" around the main program, and get rid of extra "( )" wherever you can.
- Change "long" variable names like "count" and "buf" to single chars like "c" and "b". (You can even get really obtuse and use variables like "$," and "$;" if you want)
- Get rid of 'my'. You're not using strict anyway, so change all your variables to globals (it's not production code after all!)
Use a different name if there's a variable name conflict. Then, you may have to assign to 0, but you can even save space there, with "$b=$c=0;" instead of "$b=0;$c=0;". Or, if you're willing to forego warnings, you can even avoid the assignment, as $b and $c default to zero.
- Changing for(...){...} to map{...}... saves a few characters. It has the added benefit that it forms an array, so you can actually get rid of all occurrences of @r!
- You have a string concatenation which seems unnecessary, and saves 3 characters ('"."')
- You can change "$b=(($b<<1)|($_?1:0))&255" to "$b=255&$b<<1|($_?1:0)" to save 4 chars.
- Changing "print chr($b)unless(++$c%8)" to "++$c%8or print chr$b" saves 7 chars.
- If you change "(reverse(0..7))" to "(-7..0)", and change the sign of $_ where it's used "2**-$_", it'll have the same effect, but obviates the need for "reverse". (You need two extra '-', but you also save a pair of parens "(...)").
- You were already careful not to have the last statement in each subroutine end with ';', and you can apply that to the last line of the program as well.
- Finally, prefer $/ over "\n", and you save a couple of chars.
And here is the final result:
#!/usr/bin/perl
@k=split//,'colin@colinhorne.co.uk';
@p=sub{$_=pop;map{sub{$_=pop;map{chr(eval"0b$_")}/.{8}/g}->(sprintf('%
+032b',eval
"0x$_"))}split/,/;}->("291a1f1d,4e210d00,18010b1a,4f220b17,4243274f,16
+080a1e");
sub d{$b=255&$b<<1|($_?1:0);++$c%8or print chr$b}sub{$f=pop;map{for$a(
+map{2**-$
_}(-7..0)){local$_=(ord($k[$_%$#k])^ord($p[$_]))&$a;&$f}}0..$#p}->(\&d
+);print$/
s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/