Hier mal mein Script mit dem ich bisher gearbeitet habe. Ich finde es fair, dass damit auch andere Leute mal rumprobieren dürfen, falls ihr wollt, da dies doch ne ziemliche arbeit war und die braucht nicht mehrmals gemacht werden.
Code:
/*l2.js */
//mit array.slice(0) wird als praktischer Nebeneffekt eine Kopie und keine Referenz des Arrays verwendet.
function setText () {
set_output("");
codeArray = input_umwandeln(document.getElementById("Eingabe").value)
//Formatiere den Text im Eingabefenster, für bessere Lesbarkeit
input_format(codeArray.slice(0));
//Formatiert den Input für die Ausgabe
input_ausgabe(codeArray.slice(0));
//Anzahl der Zahlen ausgeben
document.getElementById("zeichen").value = codeArray.length;
//Gibt die Häufigkeit der Zahlen aus
zahlenHaeufigkeit( codeArray.slice(0) );
}
function append_output(text) {
document.getElementById("Text").firstChild.nodeValue = document.getElementById("Text").firstChild.nodeValue + text;
}
function set_output(text) {
document.getElementById("Text").firstChild.nodeValue = text;
}
function zahlenHaeufigkeit(Array_mit_Zeichen) {
append_output("---Zahlenhaufigkeit---\r\n");
//Ausgabe der Zahlenhäufigkeit
for (var zaehlArray = new Array() ; zaehlArray.length<100 ; zaehlArray.push(0));
for (Array_mit_Zeichen ; Array_mit_Zeichen.length>0 ; Array_mit_Zeichen.shift()) {
zaehlArray[Array_mit_Zeichen[0]] = zaehlArray[Array_mit_Zeichen[0]]+1;
}
var i = 0;
for(;i<100;i++) {
append_output(i + " ");
if(i < 10) append_output(" ");
}
append_output("\r\n");
for( ; zaehlArray.length>0 ; zaehlArray.shift()) {
append_output(zaehlArray[0]+" ");
if(zaehlArray[0] < 10) append_output(" ");
}
append_output("\r\n---\r\n");
}
function input_umwandeln(input) {
//Input in Array umwandeln, als 2stellige Zahlen interpretiert
var codeArray = new Array();
for (var temp = input ; temp.length>0 ;) {
if(temp.charCodeAt(0)==10 || temp.charCodeAt(0)==32) { temp = temp.slice(1); }
else{
if(temp.charCodeAt(1)==10 || temp.charCodeAt(1)==32) {
codeArray.push(temp.charAt(0)+temp.charAt(2));
temp = temp.slice(3); }
else {
codeArray.push(temp.charAt(0)+temp.charAt(1));
temp = temp.slice(2);
}}}
return codeArray;
}
function input_format(temp2) {
//Formatiert den Input im Input Fenster
document.getElementById("Eingabe").value = "";
for( ; temp2.length > 0 ; temp2.shift() ) {
document.getElementById("Eingabe").value = document.getElementById("Eingabe").value + temp2[0] + " ";
}
}
function input_ausgabe(temp) {
//Formatiert den Input für die Ausgabe
append_output("---Formatierter Input---\r\n");
for(temp = codeArray.slice() ; temp.length > 0 ; temp.shift() ) {
append_output(temp[0] + " ");
}
append_output("\r\n---\r\n");
}
Code:
<html><head><title>Entschlüsseln von Level2</title>
<script src="l2.js" type="text/javascript"></script>
</head><body>
<h1>Level2 Entschlüsseln</h1>
<form name="Formular" action="">
Text:
<textarea id="Eingabe" rows="15" cols="50" style="font-size:1em;"></textarea>
<input type="button" name="mach" value="mach!" onclick="setText(); false;">
Zeichenanzahl<input type="Text" id="zeichen" name="zeichenanzahl" value="0" size="3">
</form>
<pre>
<div id="Text" style="font-size:1em;"></div></pre>
</body></html>
Lesezeichen