Array.prototype.doppelfind = doppelfind;
Array.prototype.cleanDouble   = new Array();

////////////

Array.prototype.recombine = recombine;
Array.prototype.zufallsliste   = new Array();
Array.prototype.element = 0;
Array.prototype.auswaehlen = auswaehlen;
Array.prototype.recombinecheck = recombinecheck;


Array.prototype.fade = fade;
Array.prototype.fadeZustand = new Boolean(false);


Array.prototype.StringConvert = StringConvert;
Array.prototype.CharCodeConvert = CharCodeConvert;


hanswurst = new Array(0,1,2,3,4,5);
lotti = new Array(5,22,6,0,9,16);


function StringConvert()
{
this.converter = new String();
for (i=0; i<this.length; i++ )
    {
    this.converter = this.converter.concat(this[i]);
    }
}




function fade(eingabe)
{
this.trueCounter = 0;
this.wahrheit = new Boolean(false);

if (eingabe.length < this.length)
   {
   // alert ("Zieldatei ist kleiner");
   }

if (eingabe.length > this.length)
   {
   // alert ("Zieldatei ist größer");
   }


for (i=0; i<this.length; i++ )
 {
 if (eingabe[i] != this[i])
    {

    if (eingabe[i] < this[i])
      {
      eingabe[i] ++;
      }
   else {
        eingabe[i] --;
        }
    }

 }
for (i=0; i<this.length; i++ )
    {
    if (eingabe[i] != this[i])
       {
       // this.fade(eingabe);
       this.fadeZustand = false;
       }
    else {
         this.trueCounter ++;
         if (this.trueCounter == this.length)
            {
            this.wahrheit = (true);

            }
         }

    }

}




function recombine()
{
for (i=0; i<this.length; i++ )
    {
    this.auswaehlen();
    if (i>0)
       {
       this.recombinecheck();
       }
    this.zufallsliste[i] = this.element;
    }
}


function auswaehlen()
{
zufallszahl = Math.random();
this.element = Math.floor(this.length*zufallszahl);
}



function recombinecheck()
{
for (j=0; j<this.zufallsliste.length; j++ )
    {
    if (this.element == this.zufallsliste[j])
       {
       this.auswaehlen();
       this.recombinecheck();
       }
    }
}



function doppelfind()
{
j = 0;
for (i=0; i<this.length; i++ )
    {
    if (this[i] == this[i+1])
       {
       }
     else {
          this.cleanDouble[j]= this[i];
          j++;
          }
    }
}


//////////////////

String.prototype.rekombination  = rekombination;
String.prototype.rekomb_array  = new Array();
String.prototype.rekomb_C  = new Array();

String.prototype.permutatio  = permutatio;
String.prototype.elementwahl = elementwahl;
String.prototype.ziehung = ziehung;
String.prototype.ersetzung = ersetzung;
String.prototype.modulatorarray = new Array();
String.prototype.modulatorarray_check = modulatorarray_check;

String.prototype.einzelwort = einzelwort;
String.prototype.einzelsatz = einzelsatz;
String.prototype.alphabetisch = alphabetisch;
String.prototype.wortliste = new Array();
String.prototype.littera = new Array();
String.prototype.litteraC = new Array();
String.prototype.textfade = textfade;
String.prototype.rekombInit = 0;
String.prototype.CharCodeConvert = CharCodeConvert;

String.prototype.merge                    = merge;
String.prototype.mergeInit = (false);

var test = new String("Testphrase");
var novatest = new String("Ich frage mich");




function einzelwort()
{
suche = / /;
ergebnis = suche.test(this);
if (ergebnis == true)
   {
   ergebnis = suche.exec(this);
   loc = ergebnis.index;
   this.wortliste = this.split(suche);
   }
}


function einzelsatz()
{
suche = /\. /;
ergebnis = suche.test(this);

if (ergebnis == true)
   {
   this.satzliste = this.split(suche);
   }
for (i=0; i<this.satzliste.length; i++ )
    {
    }
}


function alphabetisch()
{
this.wortliste.sort();
}

////////////


function elementwahl(Prozent, Unschaerfe)
{
this.fuzz = Unschaerfe;
this.double = this;
elementzahl = Prozent/100;
elementzahl = Math.floor(this.length*elementzahl);

for (i=0; i<elementzahl; i++ )
    {
    this.ziehung();
    this.modulatorarray_check();
    this.modulatorarray[i] = this.aktuell;
    }
this.ersetzung();
}


function ersetzung()
{
for (i=0; i<this.modulatorarray.length; i++ )
    {
    index = this.modulatorarray[i];
    this.permutatio(index);
    anfang = this.double.slice(0, index);
    ende = this.double.slice(index+1, this.double.length);
    this.double = anfang.concat(this.derivat, ende);
    }


}




function ziehung()
{
zufallszahl = Math.random();
this.aktuell = Math.floor(this.length*zufallszahl);
}



function modulatorarray_check()
{
if (this.modulatorarray.length > 0)
   {

   for (j=0; j<this.modulatorarray.length; j++ )
       {
       if (this.aktuell == this.modulatorarray[j])
          {
          this.ziehung();
          this.modulatorarray_check();
          }
       }

   }
}


function permutatio(eingabe)
{
ergebnis = this.double.charAt(eingabe);

this.zufallszahl = Math.random();
this.range = 18;
offset = Math.floor(this.range*this.zufallszahl);
this.derivat = this.charCodeAt(1) + offset;

if (this.derivat > 255)
   {
   this.derivat = this.derivat-255;
   }
this.derivat = String.fromCharCode(this.derivat);
}

////////////////////////

function rekombination()
{
oldindex = 0;
for (i=0; i<this.length ; i++ )
    {
    newindex = oldindex + 1;
    this.littera[i] = this.slice(oldindex, newindex);
    this.litteraC[i] =     this.littera[i].charCodeAt(0);
    oldindex = newindex;
    }
this.littera.recombine();

for (i=0; i<this.littera.length; i++ )
    {
    index = this.littera.zufallsliste[i];
    this.rekomb_array[i] = this.littera[index];
    this.rekomb_C[i] = this.rekomb_array[i].charCodeAt(0);
    }
}



function textfade()
{
this.litteraC.fade(this.rekomb_C);
this.CharCodeConvert();
this.rekomb_array.StringConvert();
}




function CharCodeConvert()
{
for (i=0; i<this.rekomb_C.length; i++ )
    {
    this.rekomb_array[i] = String.fromCharCode(this.rekomb_C[i]);
    }
}







function korrelation(eingabe)
{
}

mergeInit = 0;



function merge(eingabe)
{

if (mergeInit == 0)
   {
   if (eingabe.length>this.length)
   {
   differenz = eingabe.length-this.length;

   a = " ";
   einschub = "";
   for (i=0; i<differenz; i++ )
       {
       einschub = einschub.concat(a);
       }
   this.double = this.concat(einschub);
   this.counter = this.double.length;

   }

   if (eingabe.length<this.length)
   {
   differenz = this.length-eingabe.length;

   a = " ";
   einschub = "";
      for (i=0; i<differenz; i++ )
       {
       einschub = einschub.concat(a);
       }
   eingabe = eingabe.concat(einschub);
   this.counter = eingabe.length;
   this.double = this;
   }

   if (eingabe.length == this.length)
   {
   this.counter = this.length;
   this.double = this;
   }

   oldindex = 0;
   for (i=0; i<this.counter; i++ )
     {
     newindex = oldindex + 1;
     this.littera[i] = this.double.slice(oldindex, newindex);
     this.litteraC[i] = this.littera[i].charCodeAt(0);

     this.rekomb_array[i] = eingabe.slice(oldindex, newindex);
     this.rekomb_C[i] = this.rekomb_array[i].charCodeAt(0);
     oldindex = newindex;
     }
   mergeInit = 1;
   }


this.litteraC.fade(this.rekomb_C);
this.CharCodeConvert();
this.rekomb_array.StringConvert();

if (this.litteraC.wahrheit == true)
   {
   this.double = "";
   this.counter = 0;
   mergeInit = 0;
   }

}