At this point I have already done the part 1. I will add the source code of the
ID: 3753562 • Letter: A
Question
At this point I have already done the part 1. I will add the source code of the first part down below. Using that source code, you guys need to give me answer of part 2 as well as 3. Here is the source code of part 1:
#include<string.h>
#include<stdio.h>
#include<ctype.h>
char upper_case_letters[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
char lower_case_letters[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
void caeser_cipher ( char *s1, int key, char *s2);
void get_a_line_from_the_user( char s1[]);
int main()
{
char s1[20];
char s2[20];
int length;
int i;
int key;
printf(" Please enter a string: ");
scanf("%s", s1);
printf(" The string you entered is: %s", s1);
length = strlen(s1);
printf(" The length of the string you entered is: %d", length);
//Print out all the UPPER CASE characters
//-------------------------------------------------------------------------------------------------------------------------------
for (i = 0; i<=127; i++)
{
if (isupper(i) )
{
printf(" %d %c", i, i);
}
}
//Print out all the lower case characters
//-------------------------------------------------------------------------------------------------------------------------------
for (i = 0; i<=127; i++)
{
if (islower(i) )
{
printf(" %d %c", i, i);
}
}
char ch;
for(ch='A'; ch <= 'Z'; ch++)
{
printf(" %d %c", ch, ch);
}
// Lesson learned from above:
// Characters and letters are INTERCHANGABLE
// i.e., one can be used in the place of other
getchar();
printf(" Please enter the plain text string: ");
//scanf("%s", s1);
//option 2: Using the built in function called 'gets()'
gets (s1) ;
//option 1 : writing my own function
//get_a_line_from_the_user(s1);
//DEBUG, and come back to it later
printf(" Please enter the key: ");
scanf("%d", &key);
caeser_cipher(s1, key, s2);
printf(" The ciphered string you entered is: %s, key = %d, cipher text =%s", s1,key, s2);
//WORK DONE ON 9-18-2018
getchar(); // absorb the last new line chahrcater " "
// enter the cipher text, and use th eprogram to create the plain text
char cipher_text [100];
char plain_text [100];
printf(" Please enter the cipher text: ");
//scanf("%s", cipher text); // We need to read the whole line,
//not just teh first string. So we use gets() instead of scanf()
gets (cipher_text);
printf(" The cipher text you just entered is: %s", cipher_text);
// let us try to decipher (decrypt) with keys from 1 to 25, and
// see if we get words in the english language that user can recognize
char answer;
char junk;
for( key=1; key <= 25; key++)
{
// we are lucky that we can re-use the exisiting functions for
// BOTH encoding and decoding text.
caeser_cipher( cipher_text, key, plain_text);
printf(" The plain text is: %s", plain_text);
// let us ask the user if they recognize the plain text
printf(" Is that plain text CORRECT?: (Y/N): ");
scanf("%c", &answer);
junk = getchar(); // to absorb the newline charcater
if ((answer == 'y') || ( answer == 'Y') )
break;
}
getchar();
getchar();
return 0;
}
void caeser_cipher ( char *s1, int key, char *s2)
{
strcpy(s2, s1); //It will do s2 = s1
int i;
char ch;
int location;
int difference;
int location_in_cipher_string;
// What do i do if key is NEGATIVE?
// By the MAGIC of modulo arithmetic, we can add 26 to the 'key', and
// it should not change
if (key <=0)
{
key = key + 26;
}
for(i = 0; i < strlen(s1) - 1; i++)
{
ch =s2[i];
location = i;
if (isupper(ch))
{
difference = ch - 'A';
location_in_cipher_string = (difference + key) % 26;
s2[i] = upper_case_letters[location_in_cipher_string];
}
else if (islower(ch) )
{
difference = ch - 'a';
location_in_cipher_string = (difference + key) % 26;
s2[i] = lower_case_letters[location_in_cipher_string];
}
else // Characters other than upper case and lower case letters
// need not be converted......
{
s2[i] = s2[i];
}
}
s2[i] = '' ;
}
//Fix this bug later
//---------------------
void get_a_line_from_the_user( char s1[])
{
int i = 0;
char c;
while (c = getchar() != ' ')
{
s1[i] = c;
i++;
}
s1[i + 1] = '';
}
Sei 417/517 Assignment 1 At this point in the course, you have developed a good understanding ofthe need to perform encryption in secure computer systems. We have learned many encryption as the basic Caesar cipher, and the more advanced AES (Symmetric key encryption) and RSA (public key encryption) algorithms. schemes such Using the outline of the caesar_cipher() function that was developed in class, develop the code to take a message in plain text form and convert it to cipher text. Use this framework to perform decryption of cipher text. For the first part of this project, you must rely on user feedback to determine whether any further decryption is necessary. A sample of the expected outcome will be demonstrated by the instructor in class 1. 2. For the second part of this project, you must have your program decipher the message without any user inputs/feedback. You will need to create and use your own dictionary file. The dictionary (file) must contain at least 200 words (something with 1000+ words would be much more appropriate). It must contain at least the words used by each of the three teams to create their own cipher texts. Your program must decipher each of the three cipher text messages created at the beginning of the semester. To demonstrate the robustness of your code, you should include as many examples of cipher text as possible (10+) in your final deliverable 3. Write up (Third part of the project): Compare and contrast the approaches in your solutions above. Compare the two approaches based on'the following criteria: i) programming effort required for the two approaches i) the amount of intelligence required in the two programs iii) the usability of the programs Describe also the difficulties you encountered in your project implementation, and your solutions/workarounds to those difficulties Note: This project is to be done as a team. Note: In class, the instructor has used C for demonstrating his implementation of various features of encryption techniques needed for this projectExplanation / Answer
note ; iam giving answer fro the 1st question . I dint get any information regarding which question to answer
#include<stdio.h>
int main(){
char msg[149],ch;
int i ,key;
printf("Ceasar cypher enter the message to encrypt");
gets(msg);
printf("Enter the ceasar cypger shift value key");
scanf("%d",&key);
lower_string(msg);
for(i = 0; msg[i] != ''; ++i){
ch=msg[i];
if(ch>='a'&&ch<='z'){
ch=ch+key;
if(ch>'z'){
ch=ch-'z'+'a'-1;
}
msg[i]=ch;
}
else if(ch>='A'&&ch<='Z'){
ch=ch+key;
if(ch>'Z'){
ch=ch-'Z'+'A'-1;
}
msg[i]=ch;
}
}
}
void lower_string(char s[]) {
int c = 0;
while (s[c] != '') {
if (s[c] >= 'A' && s[c] <= 'Z') {
s[c] = s[c] + 32;
}
c++;
}
}
DecryptCaesar.C
#include<stdio.h>
int main()
{
char msg[49], ch;
int i, key;
printf("Enter a message to decrypt: ");
gets(msg);
printf("Enter key: ");
scanf("%d", &key);
for(i = 0; msg[i] != ''; ++i){
ch = msg[i];
if(ch >= 'a' && ch <= 'z'){
ch = ch - key;
if(ch < 'a'){
ch = ch + 'z' - 'a' + 1;
}
msg[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = ch - key;
if(ch < 'A'){
ch = ch + 'Z' - 'A' + 1;
}
msg[i] = ch;
}
}
printf("Decrypted message: %s", msg);
return 0;
}
-------------------------------------------------------END------------------------------------------------------
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.