i tried to modify this but it dont work were do you add thes

i tried to modify this but it dont work

were do you add these lines of code so that it properly encodes messages containg both upper case and lower case letters, any non letters ,( spaces and punctuation marks shoud be left unchanged by the encoding

alphabet = aplhabet + aplhabet.toLlowerCase();

key = key + key.tolLowerCase();

<html>
<head>
<title> Substitution Cipher</title>

<script type=\"text/javascript\">
function Encode()
// Assumes: the message to be encoded is in messageBox (all caps),
// the key for encoding is in keyBox (all caps)
// Results: the coded version of message is displayed in outputDiv
{
var message, key, alphabet, coded, i, ch, index;

message = document.getElementById(\'messageArea\').value;
key = document.getElementById(\'keyBox\').value;
alphabet = \'ABCDEFGHIJKLMNOPQRSTUVWXYZ\';
coded = \'\';

i = 0;
while (i < message.length) {        // FOR AS MANY LETTERS AS THERE ARE
ch = message.charAt(i);            // ACCESS EACH LETTER IN MESSAGE
index = alphabet.indexOf(ch);        // FIND ITS POSITION IN ALPHABET
if (index == -1) {         // IF NOT A CAPITAL LETTER,
coded = coded + ch;        // THEN ADD IT UNCHANGED
}        // OTHERWISE,
else {         // ADD THE CORRESPONDING LETTER
coded = coded + key.charAt(index);    // IN THE KEY STRING
}
i = i + 1;
}

document.getElementById(\'outputDiv\').innerHTML = coded;
}
</script>
</head>

<body>
<h2>Substitution Cipher</h2>
<p>
Key: <input type=\"text\" id=\"keyBox\" size=26 style=\"font-family:Courier,monospace\"
value=\"ZYXWVUTSRQPONMLKJIHGFEDCBA\">
</p>
<p>
Enter your message below: <br>
<textarea id=\"messageArea\" rows=8 cols=30></textarea> <br>
<input type=\"button\" value=\"Encode the Message\" onclick=\"Encode();\">
</p>
<hr>
<div id=\"outputDiv\"></div>
</body>
</html>

Solution

include #include #define MAXSIZE 1024 void encrypt(char*); void decrypt(char*); int menu(); int main(void) { char c, choice[2], s[MAXSIZE]; while(1) { menu(); gets(choice); if((choice[0]==\'e\')||(choice[0]==\'E\')) { puts(\"Input text to encrypt->\"); gets(s); encrypt(s); } else if((choice[0]==\'d\')||(choice[0]==\'D\')) { puts(\"Input text to decrypt->\"); gets(s); decrypt(s); } else break; } return 0; } void encrypt(char*str) { int n=0; char *p=str, q[MAXSIZE]; while(*p) { if(islower(*p)) { if((*p>=\'a\')&&(*p<\'x\')) q[n]=toupper(*p + (char)3); else if(*p==\'x\') q[n]=\'A\'; else if(*p==\'y\') q[n]=\'B\'; else q[n]=\'C\'; } else { q[n]=*p; } n++; p++; } q[n++]=\'\\0\'; puts(q); } void decrypt(char*str) { int n=0; char *p=str, q[MAXSIZE]; while(*p) { if(isupper(*p)) { if((*p>=\'D\')&&(*p<=\'Z\')) q[n]=tolower(*p - (char)3); else if(*p==\'A\') q[n]=\'x\'; else if(*p==\'B\') q[n]=\'y\'; else q[n]=\'z\'; } else { q[n]=*p; } n++; p++; } q[n++]=\'\\0\'; puts(q); } int menu() { puts(\"To encrypt, input e or E\ \"); puts(\"To decrypt, input d or D\ \"); puts(\"To exit, input any other letter\ \"); puts(\"Your choice:->\ \"); return 0; }
i tried to modify this but it dont work were do you add these lines of code so that it properly encodes messages containg both upper case and lower case letters
i tried to modify this but it dont work were do you add these lines of code so that it properly encodes messages containg both upper case and lower case letters

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site