Problem: You and a friend are trying to communicate in a (relatively) secure man
ID: 3640406 • Letter: P
Question
Problem: You and a friend are trying to communicate in a (relatively) secure manner. You will do so three alphanumeric characters at a time using four integer values to represent the three characters. The first integer entered represents the first character's ASCII value minus that of the second's. The second integer is the secondcharacter's ASCII value minus that of the third's. The third and fourth integer values represent the sum of the first and second character's ASCII values and the sun of the second and third character's ASCII values respectively.
Given the four integers as input, decrypt the three characters that they represent.
• It is possible that the four integers entered won't produce a solution of three integers (see example #4).
• Inform the user should any of the three decrypted values represent something other than an alphanumeric character (see example #3).
Example Execution #1:
Enter encrypted value #1: 32
Enter encrypted value #2: 12
Enter encrypted value #3: 162
Enter encrypted value #4: 118
Decrypted characters: a A 5
Example Execution #2:
Enter encrypted value #1: -11
Enter encrypted value #2: 72
Enter encrypted value #3: 233
Enter encrypted value #4: 172
Decrypted characters: o z 2
Example Execution #3:
Enter encrypted value #1: -51
Enter encrypted value #2: -30
Enter encrypted value #3: 131
Enter encrypted value #4: 212
One or more values does not represent an alphanumeric character!
Example Execution #4:
Enter encrypted value #1: 99
Enter encrypted value #2: 84
Enter encrypted value #3: 84
Enter encrypted value #4: 66
Unable to calculate integer values.
Example Execution #5:
Enter encrypted value #1: -30
Enter encrypted value #2: -19
Enter encrypted value #3: 164
Enter encrypted value #4: 213
Decrypted characters: C a t
Example Execution #6:
Enter encrypted value #1: 28
Enter encrypted value #2: -17
Enter encrypted value #3: 200
Enter encrypted value #4: 189
Decrypted characters: r V g
Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
void main()
{
int a[4],i,c1,c2,c3,d=0;
for(i=0;i<4;i++)
{
printf("Enter encrypted value #%d: ",(i+1));
scanf("%d",&a[i]);
}
if((a[0]+a[2])%2==0)c1=(a[0]+a[2])/2;
else {printf("Unable to calculate integer values."); exit(1);}
if((a[1]+a[3])%2==0)c2=(a[1]+a[3])/2;
else {printf("Unable to calculate integer values."); exit(1);}
c3=c2-a[1];
if((c1>=65 && c1<=90) || (c1>=97 && c1<=122) || (c1>=48 && c1<=57))d++;
if((c2>=65 && c2<=90) || (c2>=97 && c2<=122) || (c2>=48 && c2<=57))d++;
if((c3>=65 && c3<=90) || (c3>=97 && c3<=122) || (c3>=48 && c3<=57))d++;
if(d!=3){printf("One or more values does not represent an alphanumeric character!");
exit(1);}
printf("Decrypted characters: %c %c %c",c1,c2,c3);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.