I have the following encoder/decoder program.
It runs perfectly in FF, but returns a yellow caution in IE at a location that doesn’t make sense to me! 😮
Can anyone spot what is failing when run in MSIE? ?
[code]
<HTML>
<HEAD>
<script type=”text/javascript”>
var original = ”;
original += ‘0aAbBcC1dDeEfF2gGhHiI3jJkKlL4mMnNoO5pPqQrR6sStTuU7vVwWxX8yYzZ9’;
var alpha = original.split(”);
var letters = original.split(”);
function next(x) { return ((x+1) % alpha.length); }
function encodeRing(flag,num,info) {
// start offset at KEY value (allows base-36 entries [0-9,a-zA-Z])
var i2 = 0;
for (var i = 0; i < parseInt(num,36); i++) { i2 = ((i2+1) % alpha.length); }
// formulate character replacements
for (var i=0; i<alpha.length; i++) { letters[i] = alpha[i2]; i2=next(i2); }
info = decodeRing(flag,letters,info);
return info;
}
function decodeRing(flag,all,info) {
var wt = ”;
var et = ”;
var wh = ”;
var temp = info.split(“”);
for (q=0; q<temp.length; q++) {
wt = temp[q];
if (flag == true) {
wh = alpha.indexOf(wt); // encode part
if (wh == -1) { et += wt; } else { et += all[wh]; }
} else {
wh = all.indexOf(wt); // decode part
if (wh == -1) { et += wt; } else { et += alpha[wh]; }
}
}
return et;
}
function LoopEncode(flag,vKey,vLoop) {
for (var l=0; l<parseInt(vLoop,16); l++) { // hexidecimal counts allowed
document.f1.ta1.value=encodeRing(flag,vKey,document.f1.ta1.value); }
}
// Sample application set-up and display
function TestText() {
var str = ‘Now is the time for all good men to comen’;
str += ‘to the aid of their country.nn’;
str += ‘The quick red fox jumps over the lazy brown dog.nn’;
str += ‘Whatever the mind of man can conceive and believe,n’;
str += ‘he can achievenn01 23 45 67 89’;
return str;
}
var Counter = 0;
var LoopCounter = 0;
function EncodeCount() {
document.getElementById(‘TA1’).value
= encodeRing(true,document.getElementById(‘TB1’).value,document.getElementById(‘TA1’).value);
Counter++;
document.getElementById(‘CodeCnt’).innerHTML = Counter.toString();
}
function DecodeCount() {
document.getElementById(‘TA1’).value
= encodeRing(false,document.getElementById(‘TB1’).value,document.getElementById(‘TA1’).value);
Counter–;
document.getElementById(‘CodeCnt’).innerHTML = Counter.toString();
}
function LoopEncodeCount() {
LoopEncode(true,document.getElementById(‘TB1’).value,document.getElementById(‘TB2’).value);
LoopCounter++;
document.getElementById(‘LoopCodeCnt’).innerHTML = LoopCounter.toString();
}
function LoopDecodeCount() {
LoopEncode(false,document.getElementById(‘TB1’).value,document.getElementById(‘TB2’).value);
LoopCounter–;
document.getElementById(‘LoopCodeCnt’).innerHTML = LoopCounter.toString();
}
</script>
</HEAD>
<BODY>
<center>
<form name=’f1′ onsubmit=”return false”>
<table border=”1″><tr><td>
<textarea id=’TA1′ name=’ta1′ cols=’60’ rows=’20’></textarea>
<p>
Key Value: <input type=”text” size=’8′ name=”tb1″ id=”TB1″ value=”Key”>
Loop Pass: <input type=”text” size=’8′ name=”tb2″ id=”TB2″ value=”f”>
<button onclick=”document.getElementById(‘TA1’).value=TestText()”>Test text</button>
<br>
<input type=”button” value=”Encode Message” onclick=”EncodeCount();return false”>
<span id=”CodeCnt”>0</span>
<input type=”button” value=”Decode Message” onclick=”DecodeCount();return false”>
<br>
<input type=”button” value=”Loop Encode Message” onClick=”LoopEncodeCount();return false”>
<span id=”LoopCodeCnt”>0</span>
<input type=”button” value=”Loop Decode Message” onClick=”LoopDecodeCount();return false”>
</td>
<tr>
</table>
</form>
</body>
</html>