String.prototype.repeat = function(n) {
	return new Array(n + 1).join(this);
};

String.prototype.digest = function(format) {
	f = 0.0;
	s = this + String.fromCharCode(0).repeat(8 - (this.length % 8));
	for (i = 0; i < s.length; i++)
		f += Math.tan(Math.pow(s.charCodeAt(i) + 1, 2) * Math.pow(i + 1, Math.SQRT2));
	f = Math.abs(parseInt(Math.floor(0xFFFFFFFF * (Math.abs(f) - Math.floor(Math.abs(f))))));
	switch (format) {
		case 0:
			return String.fromCharCode(f >> 24 & 0xFF) + String.fromCharCode(f >> 16 & 0xFF) + String.fromCharCode(f >> 8 & 0xFF) + String.fromCharCode(f & 0xFF);
		case 1:
			return f.toString(36);
		default:
			return f;
	}
};
