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

Assignment 2- Caesar Cipher Introduction Your second assignment will consist of

ID: 3786897 • Letter: A

Question

Assignment 2- Caesar Cipher Introduction Your second assignment will consist of a decryption problem. Some encrypted text will be be and your job is to write a C program to decrypt it. As always, the C program should submitted as a standard C source code Please note that the computer program should comply with the commenting and formatting rules as described in class. For example, there should be a header for the whole program that gives the author's name, class name, date, and description. End braces should be commented, and there alignment and indenting requirements discussed. Please ask f you have any questions Please provide your pseudocode as a separate Word, txt, or PDF file. Program 1: Caesar Cipher In cryptography, a Caesar Cipher is one ofthe simplest and most widely known encryption a It is a cipher in each letter plaintext is replaced by letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would B, so on. The method is named after Julius cipher and Caesar, who used it in his private correspondence. ABC DEF A B C D E F Caesar the encryption is performed against a key string, which is often just the 26 letters alphabet. An value is defined that consists of a positive or negative integer. of the The plaintext (the normal text is encrypted, one letter at a time, by using that offset value in the following way: (a) the index position within the key string of the letter to be encrypted is determined, (b) the offset value is applied to that index in order to obtain a new index within the key string, (c) the character at the new index is written as the For a simple example, let's assume the key string consists of the 26 letters of the alphabet plus a space

Explanation / Answer

The below program prints out all possible plain text possible using key in range 1 to 50. You need to enter the cipher text and go through the output to find out a message which is valid. In this case, the offset 37 gives a valid output message.

#include<stdio.h>
char keySet[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
int main()
{
   char input[100];
   char output[100];
   int i = 0,j=0, k = 0, index = 0;
   //accepts input cipher text from user
   printf("Enter Cipher text ");
   scanf("%s",&input);
   //Try out all possible offset values
   for (j = 1; j <= 50; j++)
   {
      //Loop though each character in the input text
      for(i=0;input[i] != '';i++)
      {
   //Try to determine the position of matching character in keySet
   for(k=0;keySet[k] != '';k++)
   {
        if (keySet[k] == input[i])
        {
           //Match found
           index = k - j; // Determine position of plain text character
           if(k - j < 0)
           {
          index = 63 + k - j; //63 is number of characters in keySet
           }
           output[i] = keySet[index]; //Save plain text character
           break;
        }
   }
      }
      output[i] = '';
      printf("offset: %d , Text: %s ",j,output); // Print output
   }
   return 0;
}