// QTEnDecode.js
// Encoding and decoding
// Copyright 2007 nekotech Software

var EncodingTable = "H8jgMpibLBcVdnmDxQSYv9Xu27NlFPfkaZ5JsEzIhq1CtyWG4rKOUweoT6RA03";

// Encode <src> and return the result
function Encode(src) {
	var result = new String;
	var	c, i, idx;
	
	for (i = 0; i < src.length; ++i) {
		c = src.charAt(i);
		idx = EncodingTable.indexOf(c) + i;
		c = idx.toString(16);
		
		if (c.length == 1)
			c = "0" + c;
			
		result += c.toUpperCase();
	}
	
	return result;
}

// Decode <src> and return the result
function Decode(src) {
	var result = new String;
	var	c, i, idx, s;
	
	for (i = 0; i < src.length / 2; ++i) {
		s = src.slice(i * 2, i * 2 + 2);
		idx = parseInt(s, 16) - i;
		c = EncodingTable.charAt(idx);
		result += c;
	}
	
	return result;
}
