// MailScramble by Geoffrey Hoo 6 Feb 2004

// scramble stores the encrypted email address for later display,
// please use the included "index.html" to generate the encrypted email for you.
scramble = "53cd31b84209d082a49cdcc0a8e12f2d7fd4f8895b12a6a46c9ed619fecc9c30";

// This is optional.  This will show your email address link with full name in printLink().
name="Jason Holdcroft";

// This is the key used to encrypt and decrypt your email address.
// If you want to change it, change it *BEFORE* you generate the encrypted email
key="12345678903334567890123456789012";


function printEmail(){
	document.write(doDecryption(scramble));
}

function printLink(showtext, subject){

	var mail = doDecryption(scramble);
	var addsub = "";
	var show = "";

	if(subject != undefined && subject != null && subject != ""){
		addsub="?subject="+subject;
	}

	if(showtext != undefined && showtext != null && showtext != "") show = showtext;
	else show = mail;

	if (name == "" || name == null){
		document.write("<a href=\"mailto:"+mail+addsub+"\">"+show+"</a>");
	}
	else{
		document.write("<a href='mailto:\""+name+"\" <"+mail+">"+addsub+"'>"+show+"</a>");
	}		
}


function doEncryption(plaintext) {
  var ptArray, keyArray;
  keyArray = hexToByteArray(key);
  return byteArrayToHex(rijndaelEncrypt(plaintext, keyArray, "ECB"));
}

function doDecryption(ct) {
  var ctArray, keyArray;
  ctArray = hexToByteArray(ct);
  keyArray = hexToByteArray(key);
  return byteArrayToString(rijndaelDecrypt(ctArray, keyArray, "ECB"));
}