History, asked by mukeshmech, 1 year ago


You know Galois is a very smart student. He dislikes History exams and you know that he will find a smart way to cheat. You are the supervisor in the exam hall for his History exam and you recover from him a sheet of paper that contains several lines that appear to be in a language not even remotely resembling English even though the alphabets used are from the English language. The Principal will not believe you unless you establish beyond doubt, that the paper recovered from him contains an answer to one of the questions. You show the paper to the head of Computer Science department and he says that it is a well-known crypto method and agrees to decrypt the same for you. It turns out that Galois did the following,

He writes the original message in a zig zag pattern and reads of the lines horizontally. For example, IAMSMARTERTHANYOU is written first as and encoded as IEUATROMRTYSAHNMA



Given the number of rows used by Galois to encode the text and the encoded text, write a program to recover the original text. Note that if the length of the string is not adequate to complete the pattern, Galois pads it with the character "X" to make up the length. These must not appear in the output.


mukeshmech: Iam in need of this answer right now please answer me now
kejriwalkanishotuhc4: i know the code but i wont share it with you mf

Answers

Answered by aniketbharti
4
#include<stdio.h>#include<string.h>main(){int dept;scanf("%d",&dept);char a[100];scanf("%s",a);char out[100];int loc;
out[0]=a[0];int j=2;int k=0;int m=2;int count=0;out[1]=a[3];int len=strlen(a);int ind=0;while(m--){for(int i=ind;i<len;i++){if(i>3) {count++;if(count==4){out[j]=a[i];j++;count=0;loc=i;k++;}}if(len-1-loc==3){out[j]=a[i+3];j++;count=0;loc=i+3;k++;}}count=0;for(int i=len-1;i>=0;i--){if(len-1==loc){if(count==2){out[j]=a[i];j++;count=0;loc=i;k++;}}else if(i>=2){if(count==4){out[j]=a[i];j++;loc=i;count=0;k++;}}else{if(count==3){out[j]=a[i];j++;count=0;loc=i;k++;}}count++;}}for(int m=0;m<j;m++)if(out[m]!='X')printf("%c",out[m]);
}
Similar questions