Can anyone help me figure out what's wrong? I'm trying to encode and decode a simple input, but it just doesn't seem to work! Any ideas why? Thanks in advance for your assistance :)
ENCODE:
function encryption_encode(s, delta) {
var temp = "";
var alt, neu;
for(var i = 0; i < s.length; i++) {
alt = s.charCodeAt(i);
if(alt >= 65 && alt <= 90) {
neu = alt + delta;
if(neu > 90) {
neu -= 26;
}
} else if (alt >= 97 && alt <= 122) {
neu = alt + delta;
if (neu > 122) {
neu -= 26;
};
} else {
neu = alt;
}
temp += String.formCharCode(neu);
}
return temp;
}
DECODE:
function encryption_decode(s, delta) {
var temp = "";
var temp, neu;
for (var i = 0; i < s.length; i++) {
alt = s.CharCodeAt(i);
if (alt >= 65 && alt <= 90) {
neu = alt - delta;
if (neu < 65) {
neu += 26;
}
} else if (LT >= 97 && alt <= 122) {
neu = alt - delta;
if (neu < 97) {
neu += 26;
}
} else {
neu = alt;
}
temp += String.formCharCode(neu);
}
return temp;
}
HTML: I've set up a textarea for the input and another one for the output
<html>
<head>
<meta charset="UTF-8">
<title>encrypt |</title>
<link rel="stylesheet" type="text/css" href="encode.js">
<link rel="stylesheet" type="text/css" href="decode.js">
<script type="text/javascript">
function encrypt(f) {
var input = f.elements["input"].value;
var delta = parseInt(f.elements["delta"].value);
var output = encryption_encode(input, delta);
f.elements["output"].value = output;
}
</script>
</head>
<body>
<form onsubmit="return false;">
<textarea name="input" cols ="70" rows="10"></textarea> <br />
<input type="text" name="delta" value="13" />
<input type="button" value="Encode" onclick="encrypt(this.form);" />
<textarea name="output" cols="70" rows="10" onfocus="this.blur();"></textarea>
</body>
</html>