/* * Written by Joseph K. Myers on 2001/05/18 * e_mayilme@hotmail.com; http://www.angelfire.com/yt/jmyers/ * 2001/10/03: added Unicode support with binf() and unif() */var cipher_block_size=64, encoding_buffer=1024;function binf(s) {	var bytes = [], b, i;	for (i=0; i<s.length; i++) {		if ((b=s.charCodeAt(i)) < 255)			bytes[bytes.length] = b;		else {			bytes[bytes.length] = 255;			bytes[bytes.length] = b%256;			bytes[bytes.length] = (b-bytes[bytes.length-1])/256;		}	}	return bytes;}function unif(b) {	var bytes = '';	for (var i=0; i<b.length; i++) {		bytes += b[i] < 255			? String.fromCharCode(b[i])			: String.fromCharCode(b[++i]+b[++i]*256);	}	return bytes;}function b0f(c) {	return c < 16 ? '0' + c.toString(16) : c.toString(16);}function bff(c) {	return parseInt(c, 16);}function salt(s) {	var n = 0;	for (var i=0; i<s.length; i++) n += i&s.charCodeAt(i);	return b0f(n%256);}function encrypt(s,k,p,m) {	var r=parseInt(Math.random()*256), o=b0f(r), i;	for (i=p; i<Math.min(s.length, p+cipher_block_size); i++) {		o += b0f(s[i]^r^k[(i-p)%k.length]);	}	if (p+cipher_block_size < Math.min(s.length, m)) {		// var m=parseInt(s.length/cipher_block_size), t=Math.round(m/2)*cipher_block_size;		return o + encrypt(s, k, p+cipher_block_size, m);	}//*/	return o;}function decrypt(s,k) {	// return o;	var dbs = (cipher_block_size+1)*2;	var n=bff(s.substring(0,2)), o=[], i;	for (i=2; i<Math.min(dbs, s.length); i+=2) {		o[o.length] = bff(s.substring(i,i+2))^n^k[(i-2)/2%k.length];	}	if (s.length > dbs) {		return unif(o) + decrypt(s.substring(dbs), k);	}	return unif(o);/*	if (s.length > dbs) {		var m=parseInt(s.length/dbs), t=Math.round(m/2)*dbs;		return decrypt(s.substr(0, t), k) + decrypt(s.substring(t), k);	}	var n=bff(s.substring(0,2)), o=[], i;	for (i=2; i<s.length; i+=2) {		o[o.length] = bff(s.substring(i,i+2))^n^k[(i-2)/2%k.length];	}	return unif(o);// */}function encipher(f) {	self.status = 'Transforming Unicode input...';	var s=binf(f.stream.value), k=binf(f.key.value), r=salt(f.key.value), b=encoding_buffer,		p=0, n=Math.floor(s.length/b)+1;	while (n > p++) {		// alert('r.length = ' + r.length + '; ' + ((p-1)*b) + '');		self.status = 'Encrypting block ' + p + '/' + n;		r += encrypt(s, k, (p-1)*b, p*b, (p-1)*b, Math.min((p-1)*b+b, s.length), k);	}	f.stream.value = r;	self.status = 'Done';}function decipher(f) {	var s=f.stream.value.substr(2), k=binf(f.key.value), r='',		b=2*(encoding_buffer+encoding_buffer/cipher_block_size), p=0, n=Math.floor(s.length/b)+1;	if (salt(f.key.value) != f.stream.value.substr(0, 2)) {		if (!confirm('The key is probably incorrect.\nContinue decryption?'))			return;	}	while (p++ < n) {		self.status = 'Decrypting block ' + p + '/' + n;		r += decrypt(s.substr((p-1)*b, b), k);	}	f.stream.value = r;	return self.status = 'Done';}