/*
 *
 *	Author: Ashutosh Raghuwanshi.
 *	E-Mail: ashutosh@pragya.net.in
 *	URL   : http://pragya.net.in
 *  Notice: You may freely use this script as long as you keep this banner as it is.
 *
 */
/*@cc_on @*/
/*@if (@_jscript_version > 3)
   try{window.status = "Using JScript version " + @_jscript_version;}catch(exception){}
   @else @*/
   alert("You need a more recent script engine.");
/*@end @*/

function BlockXOR(Src, Dest){
var RetLen = Math.max(Src.length, Dest.length), RetStr = "", i = 0;
	for(i=0; i<RetLen; i++) RetStr += String.fromCharCode(Src.charCodeAt(i) ^ Dest.charCodeAt(i));
return RetStr;
}

function EnCipher(PlainText, PassWord){
var CypherText = "";
var i = 0, PTLen = PlainText.length, PWLen = Math.max(PassWord.length, 1);
	for(i=PTLen - (PTLen % PWLen) - PWLen; i >= 0; i-=PWLen)
		CypherText = BlockXOR(PlainText.slice(i,i+PWLen), PlainText.slice(i+PWLen, i+PWLen*2)) + CypherText;
	if(PassWord.length == 0) return escape(PlainText.charAt(0) + CypherText);
	CypherText = BlockXOR(PassWord, PlainText.slice(i+PWLen, i+PWLen*2)) + CypherText;
return escape(CypherText);
}

function DeCipher(CypherText, PassWord){
var CT = unescape(CypherText);
var PWLen = Math.max(PassWord.length, 1);
var PlainText = (PassWord.length == 0) ? CT.charAt(0) : BlockXOR(PassWord, CT.slice(0, PWLen));
var i = 0;
	for(i=0; i < CT.length; i+=PWLen)
		PlainText += BlockXOR(PlainText.slice(i,i+PWLen), CT.slice(i+PWLen, i+PWLen*2));
return PlainText;
}

function RndEnCipher(PlainText, PassWord){
var CypherText = "", TmpStr = "";
var i = 0, PTLen = PlainText.length, PWLen = Math.max(PassWord.length, 1);
	for(i=0; i<(2*PTLen)+2; i++)
		TmpStr += (i%2!=0) ? PlainText.charAt(Math.floor(i/2)) : String.fromCharCode("A".charCodeAt(0)+(Math.random()*25));
	PTLen = TmpStr.length;
	for(i=PTLen - (PTLen % PWLen) - PWLen; i >= 0; i-=PWLen)
		CypherText = BlockXOR(TmpStr.slice(i,i+PWLen), TmpStr.slice(i+PWLen, i+PWLen*2)) + CypherText;
	if(PassWord.length == 0) return escape(TmpStr.charAt(0) + CypherText);
	CypherText = BlockXOR(PassWord, TmpStr.slice(i+PWLen, i+PWLen*2)) + CypherText;
return escape(CypherText);
}

function RndDeCipher(CypherText, PassWord){
var CT = unescape(CypherText), PlainText = "";
var PWLen = Math.max(PassWord.length, 1);
var TmpStr = (PassWord.length == 0) ? CT.charAt(0) : BlockXOR(PassWord, CT.slice(0, PWLen));
var i = 0;
	for(i=0; i < CT.length; i+=PWLen)
		TmpStr += BlockXOR(TmpStr.slice(i,i+PWLen), CT.slice(i+PWLen, i+PWLen*2));
	for(i=1; i<TmpStr.length; i+=2) PlainText += String.fromCharCode(TmpStr.charCodeAt(i));
return PlainText;
}

function EasyEnCipher(PlainText){
var CypherText = "";
	for(i=PlainText.length-1; i>=1; i--) CypherText = String.fromCharCode(PlainText.charCodeAt(i)^PlainText.charCodeAt(i-1)) + CypherText;
return escape(String.fromCharCode(PlainText.charCodeAt(0)) + CypherText);
}

function EasyDeCipher(CypherText){
var CT = unescape(CypherText), PlainText = CT.charAt(0), i = 0;
	for(i=0; i<CT.length-1; i++) PlainText += String.fromCharCode(PlainText.charCodeAt(i)^CT.charCodeAt(i+1));
return PlainText;
}

function EasyRndEnCipher(PlainText){
var CypherText = "", TmpStr = "";
	for(i=0; i<(2*PlainText.length)+2; i++) TmpStr += (i%2!=0) ? PlainText.charAt(Math.floor(i/2)) : String.fromCharCode("A".charCodeAt(0)+(Math.random()*25));
	for(i=TmpStr.length-1; i>=1; i--) CypherText = String.fromCharCode(TmpStr.charCodeAt(i)^TmpStr.charCodeAt(i-1)) + CypherText;
return escape(String.fromCharCode(TmpStr.charCodeAt(0)) + CypherText);
}

function EasyRndDeCipher(CypherText){
var CT = unescape(CypherText);
var TmpStr = CT.charAt(0), PlainText = "", i = 0;
	for(i=0; i<CT.length-1; i++) TmpStr += String.fromCharCode(TmpStr.charCodeAt(i)^CT.charCodeAt(i+1));
	for(i=1; i<TmpStr.length; i+=2) PlainText += String.fromCharCode(TmpStr.charCodeAt(i));
return PlainText;
}

function Scramble(TextSring, WordList){
var RegExp_Words, Scrambled_String = TextSring, RndWord = "", CharCase = "a", i, j;
var Regexp_Comma = / *, */g
var Words = (WordList.replace(Regexp_Comma,",")).split(",")
	for (i=0; i < Words.length; i++){
		RegExp_Words = new RegExp("\\b"+Words[i]+"\\b","g");
		for(j=0; j < (Math.random() * Words[i].length * 2); j++){
			CharCase = (Math.round(Math.random()) == 1) ? "A" : "a";
			RndWord += String.fromCharCode(CharCase.charCodeAt(0)+(Math.random()*25));
		}
		Scrambled_String = Scrambled_String.replace(RegExp_Words, RndWord);
		RndWord = "";
	}
return Scrambled_String;
}
