Using C code only Problem 1: String Operations and Data Security: To enhance dat
ID: 3566857 • Letter: U
Question
Using C code only
Problem 1: String Operations and Data Security: To enhance data security in the transmission of data and documents, dynamic character coding is being practiced. The modification of the original characters
can be using the first 8 prime members [1, 2, 3, 5, 7, 11, 13, 17]: First character enhanced by 1; second character by 2, third by 3, .. 8th character by 17. Next 8 characters use the prime numbers in the reverse order 17..1, and decrease the values. Use a total message of at least 32 characters and repeat the process of modifying 1-17 for the first 8; modifying by 17 -1 for next 8, and so on. Make your own message. After the message is coded, decoding should also be done, to restore the original message.
Example: Original Message A B C D.
Explanation / Answer
#include<stdio.h>
#include<string.h>
main()
{
int i=0,r=0,order=0,p[]={1,2,3,5,7,11,13,17} ;
char s[64];
printf("Please enter the message string : ");
scanf("%[^ ]s",s);
// Coding the message starts here
while (i<strlen(s))
{
if (order==0)
{
s[i] = s[i] + p[r];
r++;
if(r==8)
{
order=1;
r--;
}
i++;
continue;
}
if (order==1)
{
s[i] = s[i] + p[r];
r--;
if(r==-1)
{
order=0;
r++;
}
i++;
}
}
printf("The coded message is: %s ",s);
i=0;
order=0;
// Decoding of the coded message starts here
while (i<strlen(s))
{
if (order==0)
{
s[i] = s[i] - p[r];
r++;
if(r==8)
{
order=1;
r--;
}
i++;
continue;
}
if (order==1)
{
s[i] = s[i] - p[r];
r--;
if(r==-1)
{
order=0;
r++;
}
i++;
}
}
printf("The decoded message is: %s",s);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.