RC4 in JavaScript and PHP

RC4 (Rivest Cipher 4) is a symmertic cryptoghraphy algorithm and is one of the most used encryption algorithms
in the world because of its simplicity and speed. it is used in popular protocols such as SSL and WEP.
Although, RC4 falls short of the high standards of security, some systems based on RC4 are secure enough for practical use.

I have written this algorithm in both php and js. Therefor it will be possible to transfer information between the client and the server in a secure manner.
but it may not be useful in practice, due to the unsecure transfer of secret key. It would be useful in conjunction with other algorithms like RSA,
however, it may be used for other purposes rather than securing data transmissions.

RC4 is a Vernam cipher, which means that it generates a keystream that, for encryption, is combined with the plaintext using XOR.
As with any Vernam cipher decryption is performed the same way.

Download RC4 JavaScript Source Code
Download RC4 PHP Source Code

Note that the plain text should not contain any unicode charachters. In other words, the plain text must be
a string that each character of this string is representing a single byte. Therefor, if you want to encode strings
that contains unicode characters you should first convert it to UTF-8. (see UTF-8 in JS)

Example:
Secret Key: (less than 256 character)

Plain Text: Encrypted Data (hex):




Note: At the above example, the encrypted data will be converted to Hex(base16) format after encryption. (see Hex in JS)