#!/usr/bin/perl # symmetrical cipher STDIN to STDOUT use warnings; use strict; @ARGV or die "Usage $0 keyphrase < source > dest\n"; my @key = unpack "C*", "@ARGV"; # init ARC4 state from key my @s = (0..255); my $i=0; for (0..255) { $i+=$key[$_%@key]+$s[$_], $i%=256; ($s[$_],$s[$i])=($s[$i],$s[$_]); } # do the magic my $x=0; my $y=0; my $t; print pack "C*", map { $x++, $x%=256; $y+=$s[$x], $y%=256; ($s[$x],$s[$y])=($s[$y],$s[$x]); $_^$s[($s[$x]+$s[$y])%256]; } unpack "C*", $t while read STDIN, $t, 32768;