a2c8a755074a188f544f04675419ee63594ff739
1 /* RC4 symmetric cipher encryption/decryption
2 * Copyright (c) 2006 by Ali Farhadi.
3 * released under the terms of the Gnu Public License.
4 * see the GPL for details.
6 * Email: ali[at]farhadi[dot]ir
7 * Website: http://farhadi.ir/
11 * Encrypt given plain text using the key with RC4 algorithm.
12 * All parameters and return value are in binary format.
14 * @param string key - secret key for encryption
15 * @param string pt - plain text to be encrypted
18 function rc4Encrypt(key
, pt
) {
20 for (var i
=0; i
<256; i
++) {
25 for (i
=0; i
<256; i
++) {
26 j
= (j
+ s
[i
] + key
.charCodeAt(i
% key
.length
)) % 256;
34 for (var y
=0; y
<pt
.length
; y
++) {
40 ct
+= String
.fromCharCode(pt
.charCodeAt(y
) ^ s
[(s
[i
] + s
[j
]) % 256]);
46 * Decrypt given cipher text using the key with RC4 algorithm.
47 * All parameters and return value are in binary format.
49 * @param string key - secret key for decryption
50 * @param string ct - cipher text to be decrypted
53 function rc4Decrypt(key
, ct
) {
54 return rc4Encrypt(key
, ct
);
This page took 0.275978 seconds and 3 git commands to generate.