/*

Copyright (C) 1995-2004 Thomas Gebhardt 
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by 
the Free Software Foundation; either version 2 of the License, or 
(at your option) any later version. 

This program is distributed in the hope that it will be useful, but 
WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 
See the GNU General Public License for more details. You should have
received a copy of the GNU General Public License along with this
program; if not, write to the Free Software Foundation, Inc., 
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

*/

var CSET="%_.1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/+*-@",SET=CSET;
var RNDS,RNDA,RNDB,RNDM;
var PWFALSCH="pwfalsch.htm";

function rnd(n) 
        { RNDS=(RNDA*RNDS+RNDB)%RNDM;
          return Math.floor(RNDS/RNDM*n);
	}

function init(p)
	{ var cset=SET+"'ßäöüÄÖÜ ,:;!?§$&=#[]{}";
	  var len=p.length,z,i,ls=cset.length,ma=1,mb,n=26,la=17,lb=13; 
	  /* Rechnungen in rnd() bis 2^26 in Ganzzahl */
	  n-=2;
	  for(i=0;i<n;i++) ma*=2;
	  mb=ma*2;
	  RNDM=ma*4;
	  la*=len;
	  lb*=len;
	  RNDS=0;
	  RNDA=0;
	  RNDB=0;
	  for(i=0;i<len;i++) {
		z=cset.indexOf(p.charAt(i));
		RNDS=(z*ls+RNDS)%RNDM;
		RNDA=(z*la+RNDA)%ma;
		RNDB=(z*lb+RNDB)%mb;
		}
	  RNDA*=4; RNDA++;
	  RNDB*=2; RNDB++;
	} 

function format(r) {
	var f=10000000000;
	return Math.round(f*r)/f;
}

function invert(s) {
	var i,len=s.length,r="";
	if(len<=1) return s;
	for(i=len-1;i>=0;i--) r+=s.charAt(i);
	return r;
	}

var CC="copyright http://www.eduvinet.de/gebhardt ";

function perm(n) {
	var SET=CSET,i,x,len=SET.length;
	for(i=0;i<n;i++) {
		x=rnd(len);
		SET=invert(SET.substring(x,len))+SET.substring(0,x);
		}
	}

function entkrypt3(p,v,np) {
	window.status="Entschlüsselung läuft...";
	init(p);
	perm(np);
	var k=v.indexOf(CC);
	if(k==0) v=v.substring(k+CC.length);
	var n=v.length,nn=n-1,i,m,lesc=SET.length,z=Math.round(0.5+n/100);
	m='';
	for(i=0;i<n;i++) {
		k=SET.indexOf(v.charAt(i))+rnd(lesc);
		m+=SET.charAt(k%lesc);
		if(i%z==0) window.status=Math.round(100*i/nn)+"% entschlüsselt";
		}
	window.status="";
	return unescape(m);
	}

function ekrypt2(v,n,pw) {
	var p=CC;
	if(pw) p=pw;
	var m=entkrypt3(p,v,n),lm=m.length,lp=p.length,s=m.substring(lm-lp,lm);
	if(p==s) { 
		document.write(m.substring(0,lm-lp));
		document.close();
		}
	else  window.location=PWFALSCH;
}

function ekrypt(v,n){
	var p=prompt('Diese Seite erfordert ein Passwort:','');
	if((p==null)||(p=="")) {history.go(-1); return; }
	ekrypt2(v,n,p);
	}

function ekrypturl2(v,n,pw) {
	var p=CC;
	if(pw) p=pw;
	ekrypturlx(p,v,n);
	}

function ekrypturlx(p,v,n){
	var m=entkrypt3(p,v,n),lm=m.length,lp=p.length,s=m.substring(lm-lp,lm);
	if(p==s) window.location=m.substring(0,lm-lp);
	else alert("Falsches Passwort");
	}

function ekrypturl(v,n) {
	var p=prompt('Bitte Passwort eingeben:','');
	if((p==null)||(p=="")) return;
	ekrypturlx(p,v,n);
	}

