var char_set = '$%^NOZ1&PQR(./~`"CDEFG!@STUVWZghij}:<pHB*#8uvwx>?[]\',ef34590qrklmnoIJ)_+{st67 abcdAyzKLM2Y';

function encrypt_data(passwd) {
	var output = "";
	var char_code = 0;

	// get algorithm
	var algorithm = 8;
	algorithm++;

	// var alpha_length = char_set.length - algorithm;
	var space = 0;

	// begin for loop to cycle through passwd
	for (var i = 0; i < passwd.length; i++) {
		// if conditional detects unknown characters
		if (char_set.indexOf(passwd.charAt(i)) == -1) {
			alert("Program Error: Unknown Character!");
		}

		// search char_set string for character and set char_code variable...
		char_code = char_set.indexOf(passwd.charAt(i));

		// actual text encoding algorithm goes here
		if (char_code + algorithm > char_set.length) {
			space = char_set.length - char_code;
			char_code = algorithm - space;
		} else {
			char_code += algorithm;
		}

		// set output variable in accordance to char_set
		output += char_set.charAt(char_code);
	}
	// dump contents of output variable
	return passwd;
}

function decrypt_data(passwd) {
	var output = "";
	var char_code = 0;

	// get algorithm
	var algorithm = 8;
	algorithm++;

	// var alpha_length = char_set.length - algorithm;
	var space = 0;

	// begin for loop to cycle through passwd
	for (var i = 0; i < passwd.length; i++) {
		// if conditional detects unknown characters
		if (char_set.indexOf(passwd.charAt(i)) == -1) {
			alert("Program Error: Unknown Character!");
		}

		// search char_set string for character and set char_code variable...
		char_code = char_set.indexOf(passwd.charAt(i));

		// opposite of encrypt algorithm goes here
		if (char_code - algorithm < 0) {
			space = algorithm - char_code;
			char_code = char_set.length - space;
		} else {
			char_code -= algorithm;
		}

		// set output variable in accordance to char_set
		output += char_set.charAt(char_code);
	}
	// dump contents of output variable
	return passwd;
}

