Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1)Random Cipher Write a program called cipher.c that makes use of the three ciphers that you just created. Copy over your cipher-making code into this

1)Random Cipher Write a program called cipher.c that makes use of the three ciphers that you just created. Copy over your cipher-making code into this file. Adjust the main program so that it asks for the user message, and then randomly chooses one of the three ciphers and applies it to the message. The program should then output only (and exactly) 100 characters representing the encoded message followed by -1 valued bytes. If, for example, cipher1 is used and ABC is the message, then the program should output followed by 97 bytes which are all -1. It is important that no other output is made to the screen (i.e., no other printf() calls not even for asking for user input) because the next program will require exactly 100 bytes. 2)Deciphering it all Finally, write a program called decipher.c that will take the result of the cipher.c program and attempt to determine what the original message was by applying all three ciphers and seeing which one gives the most likely result. Now, although we cannot be sure which cipher was used, if we make some assumptions that the original text was mostly alphanumeric characters then we can make a decent guess. To approach this problem first read in the characters from the standard input (i.e., getchar()). We will set up our testing so that the output from the cipher program is fed into the decipher program for testing (based on pipes which we will discus later in the course). Once the array of characters has been read in you should try to decipher the message using each cipher and then choose the most likely match. To find the best match you must take each deciphered character and determine if it is an alphanumeric character (i.e., is it an upper or lowercase letter or a digit from 0 to 9 or the space character). You should count the percentage of decoded characters that are alphanumeric. The cipher that has the highest percentage of decoded alphanumeric characters that will be the cipher that we will assume is the correct one and you should display that result. You should display the count for each cipher as well. To test the code, use the following command (which assumes that the cipher and decipher programs are in the current directory): ./cipher | ./decipher Here is what the output should look like: student@COMP2401-F19:~$ ./cipher | ./decipher This is an Encoded Message ! Match = 46.43% Deciphered String = i1i1y]9 YMY11yY{ Match = 96.43% Deciphered String = This is an Encoded Message ! Match = 57.14% Deciphered String = ai@i@hg@*globjb@+jhnj@H Deciphered Message: "This is an Encoded Message !"

following C code is Random cipher, please answer for question #2 decipher

use random cipher code and change it to decipher. Write decipher.c

#include

#include

#include

#include

#define MAX 100

char str1[MAX];

unsigned char n;

char cipher(char c){

return c+1;

}

void printAsBinary(unsigned char n);

int main(){

char cipher1[MAX};

char cipher1[MAX};

char cipher1[MAX};

printf("Enter the message to encode");

scanf("%s",str1);

for(int i=0;i<3;i++){

cipher1[I] = (~str1[I]);

for(int j=0;j<8;j++){

if(str1[I] & (1<

cipher2[I] |= 1<<(7-j);

}

cipher3[I] = (str1[I] >>4 | (str1[I]<<4);

}

//random

int r =rand()%3;

if(r==1){

printf("Cipher = %s",cipher1);

}

if(r>1){

printf("Cipher = %s",cipher1);

}

if(r==0){

printf("Cipher = %s",cipher1);

}

}

void printAsBinary(unsigned char n){

for(int I=7; I>=0;i--){

if((int)(n/pow(2,i))>0){

printf("1");

n = n- pow(2,i);

}else

print("0");

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Does your product/program have a descriptive and memorable slogan?

Answered: 1 week ago

Question

How does this compare with the Fog Index for your written message?

Answered: 1 week ago