
var sbox = new Array(256);
var key = new Array(256);

function RC4(strTexto, strClave) {
	var i, j, k, temp, cipherby, cipher;

	i = 0;
	j = 0;
	cipher = "";
	temp = 0;

	InicializarRC4(strClave);

	for (a = 0; a < strTexto.length; a++) {
		i = (i + 1) % 256;
		j = (j + sbox[i]) % 256;
		temp = sbox[i];
		sbox[i] = sbox[j];
		sbox[j] = temp;

		k = sbox[(sbox[i] + sbox[j]) % 256];

		cipherby = strTexto.charCodeAt(a) ^ k;
		cipher = cipher + String.fromCharCode(cipherby);
	}
	return(cipher);
}


function InicializarRC4(strLlave) {
	var a, b, tempSwap;

	for (a = 0; a < 256; a++) {
		key[a] = (strLlave.charCodeAt(a % strLlave.length)) % 256;
		sbox[a] = a;
	}

	b = 0;
	for (a = 0; a < 256; a++) {
		b = (b + sbox[a] + key[a]) % 256;
		tempSwap = sbox[a];
		sbox[a] = sbox[b];
		sbox[b] = tempSwap;
	}
}

function canDoRC4() {
	return StringToHex(RC4("abc","abc")) == "ACFFBA"
}






