Markus
2008-05-22 09:25:47
Was bored, and I was angry at TEA (Tiny Encryption Algorithm), so I decided to implement RC4 instead :)
According to Wikipedia, "RC4 (also known as ARC4 or ARCFOUR) is the most widely-used software stream cipher and is used in popular protocols such as Secure Sockets Layer (SSL) (to protect Internet traffic) and WEP (to secure wireless networks). "
It seems to be compatible with every RC4 implementation, except that it doesn't pad the text that needs to be encrypted to match the length of the key :) So use a bigger text than key, or equal length ;)
Script+Demo
According to Wikipedia, "RC4 (also known as ARC4 or ARCFOUR) is the most widely-used software stream cipher and is used in popular protocols such as Secure Sockets Layer (SSL) (to protect Internet traffic) and WEP (to secure wireless networks). "
It seems to be compatible with every RC4 implementation, except that it doesn't pad the text that needs to be encrypted to match the length of the key :) So use a bigger text than key, or equal length ;)
Script+Demo
program New;
var
s : array [0 .. 255] of byte;
i, j : integer;
const cyphertext = 'f¬o}bvU\€&bRÓÇ6(Ê-…ù’©® 1XÎɱ~íÃÝúÛX*';
Key = 'testmeh';
procedure InitRandomGen(key : string);
begin
for i := 0 to 255 do
S[i] := i;
for i := 0 to 255 do
begin
j := (j + S[i] + (ord(key[(i mod (length(key))+1)]))) mod 256;
swap(S[i],S[j])
end;
i := 0;
j := 0;
end;
function GenerateByte : byte;
begin
i := (i + 1) mod 256;
j := (j + S[i]) mod 256;
swap(s[i], s[j]);
result := S[(s[i]+s[j]) mod 256];
end;
function EncryptRC4(text, key : string) : string;
var CC, LL : integer;
begin
LL := length(text);
InitRandomGen(key);
result := text;
for CC := 1 to LL do
begin
result[CC] := chr((ord(text[cc])) xor GenerateByte);
end;
end;
begin
writeln(EncryptRC4(cyphertext, key));
end.