I found this code online and need to find a way to modify it to fit my requirements.
[CODE]<SCRIPT LANGUAGE=”JavaScript”>
function Encode(key, message)
// Given : key is a string of the 26 letters in arbitrary order,
// message is the string to be encoded using the key
// Returns: the coded version of message using the substitution key
{
var alphabet, coded, i, ch, index;
alphabet = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”;
coded = “”;
for (i = 0; i < message.length; i++) { // for as many letters as there are
ch = message.charAt(i); // access the letter in the message
index = alphabet.indexOf(ch); // find its position in alphabet
if (index == -1) { // if it’s not a letter,
coded = coded + ch; // then leave it as is & add
} // otherwise,
else { // find the corresponding
coded = coded + key.charAt(index); // letter in the key & add
}
}
return coded;
}
</SCRIPT>
It needs to be aranged to decode the following:
[FONT=Fixedsys]
ABCDEFGHIJKLM
|||||||||||||
NOPQRSTUVWXYZ[/FONT]
For instance: If the message you input says ‘hello’, the code would spit it out as ‘uryyb’. It simply substitutes the letters on the top with the letters on the bottom, and visa-versa. Can anyone help?