Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

If you recall, a Caesar Cipher is a simple way of encoding information. The ciph

ID: 3684100 • Letter: I

Question

If you recall, a Caesar Cipher is a simple way of encoding information. The cipher takes every letter in a message and replaces it with another letter offset by an amount given as the key. For example: hello encoded with a key of 5 would be mjqqt

looking closer at that first letter of h in this example: h is the 8th letter of the alphabet. if we add 5 to 8 we get 13 and m is the 13th letter of the alphabet so the h in hello becomes m in our ciphered version.If we reach the end of the alphabet we need to wrap back around to the beginning so if we encoded z with a key of 5 we would wrap back around to e

Your mission will be to do the following:

1. Create an html page with a form to collect the phrase the user wishes to encrypt and the key they wish to use to do so.

2. Create a cgi page to receive the information from your html page. It should display the encrypted version of the user’s phrase using the key they provided.

Explanation / Answer

CGI script;

Please note that to run CGI script u need to setup initial setup for cgi.i assume you are aware of that.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
char *data;
char *result;
char *text;
int len;
int n,i;
int last_char = 'z';
char a;
printf("%s%c%c ",
"Content-Type:text/html;charset=iso-8859-1",13,10);
printf("<TITLE>Ceaser Cipher encoding</TITLE> ");
printf("<H3>Encoded Text</H3> ");
data = getenv("QUERY_STRING");
if(data == NULL)
printf("<P>Error! Error in passing data from form to script.");
  
   sscanf(data,"text=%s&n=%d",text,&n);
  
   len=strlen(text);
   result = (char *)malloc(len);
   for(i=0;i<len;i++){
       a=text[i]+n;
      
       a=(a>last_char)?('a'+a%last_char):a;
      
       result[i] = a;
       }
       result[i]='';

printf("<P>Encoded Text : %s",result);
  

return 0;
}

Html page:

<html>
<header>
<title>Ceaser Cipher</title>
</header>
<body>

   <!--Put your cgi-script path in this action attribute-->
   <form action="">
       <div><label>Your Text : <input name="text"></label></div>
       <div><label>Your Key : <input name="n" size=1></label></div>
                
       <div><input type="submit" value="Encode!"></div>
   </form>
  
   </body>
   </html>
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote