Write a program that, given the same permutation string, can decode a message that was encoded with the method of the previous question. So, with char perm[] = "qjczieaungsdfxmphybklortvw"; Given the string "bicyik fibbqai km ixcmzi", the program should output "secret message to encode" Similarly as previously, if it works for lowercase, then get it to work for upper case too. If the string is "Bicyik Fibbqai Km Ixcmzi" it should output "Secret Message To Encode"

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

last q i use the second photo code i dont know how to do in this q

Write a program that, given the same permutation string, can decode a message that was encoded with the method of the previous
question.
So, with
char perm[] = "qjczieaungsdfxmphybklortvw";
Given the string "bicyik fibbqai km ixcmzi", the program should output
"secret message to encode"
Similarly as previously, if it works for lowercase, then get it to work for upper case too. If the string is
"Bicyik Fibbqai Km Ixcmzi"
it should output
"Secret Message To Encode"
For example:
Input
Result
bicyik fibbqai km ixcmzi
secret message to encode
Bicyik Fibbqai Km Ixcmzi
Secret Message To Encode
qxmkuiy fibbqai km ixcmzi
another message to encode
Transcribed Image Text:Write a program that, given the same permutation string, can decode a message that was encoded with the method of the previous question. So, with char perm[] = "qjczieaungsdfxmphybklortvw"; Given the string "bicyik fibbqai km ixcmzi", the program should output "secret message to encode" Similarly as previously, if it works for lowercase, then get it to work for upper case too. If the string is "Bicyik Fibbqai Km Ixcmzi" it should output "Secret Message To Encode" For example: Input Result bicyik fibbqai km ixcmzi secret message to encode Bicyik Fibbqai Km Ixcmzi Secret Message To Encode qxmkuiy fibbqai km ixcmzi another message to encode
#include <stdio.h>
#define MAX_STR_LEN 256
int main(void)
{
char perm[]="abcdefghijklmnopqrstuvwsyz";
char msg[MAX_STR_LEN+1];
int i;
fgets (msg,MAX_STR_LEN,stdin);
for (i=0;i<MAX_STR_LEN;i++){
if(msg[i]==' '){
continue;
}
if(msg[i]=='\n'){
break;
}
int low=97;
int high=65;
while(msg[i]!=perm[i]){
if(low<=122){
low++;
}
else{
break;
}
}
if(low>122){
while(msg[i]!=high){
if(high<=90){
high++;
}
}
if(low<=122){
msg[i]=perm[low-97];
}else{
char temp=perm[high-65];
msg[i]=temp-32;
}
}
for (int i-0;i<MAX_STR_LEN;i++){
if(msg[i]=='\n'){
break;
}
printf("%c",msg[i]);
}
return 0;
}
Transcribed Image Text:#include <stdio.h> #define MAX_STR_LEN 256 int main(void) { char perm[]="abcdefghijklmnopqrstuvwsyz"; char msg[MAX_STR_LEN+1]; int i; fgets (msg,MAX_STR_LEN,stdin); for (i=0;i<MAX_STR_LEN;i++){ if(msg[i]==' '){ continue; } if(msg[i]=='\n'){ break; } int low=97; int high=65; while(msg[i]!=perm[i]){ if(low<=122){ low++; } else{ break; } } if(low>122){ while(msg[i]!=high){ if(high<=90){ high++; } } if(low<=122){ msg[i]=perm[low-97]; }else{ char temp=perm[high-65]; msg[i]=temp-32; } } for (int i-0;i<MAX_STR_LEN;i++){ if(msg[i]=='\n'){ break; } printf("%c",msg[i]); } return 0; }
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY