var cryptTable=new String(" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789	!@#$%^&*()`'-=[];,./?_+{}|:<>~");
var cryptLength=new Number(cryptTable.length-1) 
var escapeChar=cryptTable.charAt(cryptLength); 

var lineFeed="\n"; 
var doubleQuote='"'; 
var clearMessage=new Number(5000); 
 
function encrypt(input, password)
{
var inChar, inValue, outValue;

var output="";
var arNumberPw = new Array();

var pwLength=password.length;
var inLength=input.length;

var stopStatus=Math.round(inLength/10);
var statusBar=0;

for (var pwIndex=0; pwIndex<pwLength; pwIndex++)
	{
	arNumberPw[pwIndex]=cryptTable.indexOf(password.charAt(pwIndex));
	}

for (var inIndex=0, pwIndex=0; inIndex<inLength; inIndex++, pwIndex++)
	{
	if (pwIndex==pwLength) 
		{
		pwIndex=0;
		}
	
	inChar=input.charAt(inIndex)
	inValue=cryptTable.indexOf(inChar);

	if (inValue!=-1)
		{
		outValue=arNumberPw[pwIndex] ^ inValue;
		if (outValue>=cryptLength)
			{
			outValue=escapeChar+cryptTable.charAt(outValue-cryptLength);
			}
		else outValue=cryptTable.charAt(outValue);
		}	
	else if (inChar=="\r")
		{
		outValue=escapeChar+escapeChar;
		if (input.charAt(inIndex+1)=="\n") inIndex++; 
		}
	else if (inChar=="\n")
		{
		outValue=escapeChar+escapeChar;
		}
	else if (inChar==doubleQuote)
		{
		outValue=escapeChar+"'";
		}
	else
		{
		outValue=inChar;
		}

	output+=outValue; 

	}

return output;
}

function decrypt(input, password)
{
var inChar, inValue, outValue, escape=false;

var output="";
var arNumberPw = new Array();

var pwLength=password.length;
var inLength=input.length;

var stopStatus=Math.round(inLength/10);
var statusBar=0;

for (var pwIndex=0; pwIndex<pwLength; pwIndex++)
	{
	arNumberPw[pwIndex]=cryptTable.indexOf(password.charAt(pwIndex));
	}

for (var inIndex=0, pwIndex=0; inIndex<inLength; inIndex++, pwIndex++)
	{
	if (pwIndex>=pwLength)
		{
		pwIndex=0;
		}
	
	inChar=input.charAt(inIndex);
	inValue=cryptTable.indexOf(inChar);

	if (inValue==-1)
		{
		outValue=inChar;
		}	

	else if (escape)
		{
		if (inValue==cryptLength)
			{
			outValue=lineFeed;
			inValue=-1;
			}
		else if (inChar=="'")
			{
			outValue=doubleQuote;
			inValue=-1;
			}
		else
			{
			inValue+=cryptLength;
			}
		escape=false;
		}
	else if (inValue==cryptLength)
		{
		escape=true;
		pwIndex--; 
		outValue="";
		inValue=-1;
		}

	if (inValue!=-1)
		{
		outValue=cryptTable.charAt(arNumberPw[pwIndex] ^ inValue);
		}
	
	output+=outValue;

	}

return output;
}

