Write an interactive c program that will encode or decode a
line of text. To encode a line of text, proceed as follows:
Convert each character, including blank spaces, to its
ASCII equivalent.
Generate a positive random integer. Add this integer to the
ASCII equivalent of each character. The same random integer
will be used for the entire line of text.
Suppose that N1 represents the lowest permissible value in
the ASCII code, and N2 represents the highest permissible
value. If the number obtained in step 2 above exceeds N2,
then subtract the largest possible multiple of N2 from this
number, and add the remainder to N1. Hence the encoded
number will always fall between N1 and N2, and will
therefore always represent some ASCII character.
Display the characters that correspond to the encoded ASCII
values.
The procedure is reversed when decoding a line of text. Be
certain, however, that the same random number is used in
decoding as was used in encoding.
Answer / sss
#include<iostream.h>
#include<string.h>
void main()
{
char str1[]="Testing";
char str2[40];
strcpy(str2, str1);
cout<<"str1="<<str1<<endl;
cout<<"str2="<<str2<<endl;
int i=0;
while(str1[i]!='\0')
{
cout<<(int)str1[i]<<" ";
str2[i]=(char)((int)str1[i]+2);
i++;
}
cout<<endl;
i=0;
while(str2[i]!='\0')
{
cout<<(int)str2[i]<<" ";
i++;
}
cout<<endl;
cout<<str2<<endl;
i=0;
while(str2[i]!='\0')
{
cout<<(char)((int)str2[i]-2);
i++;
}
cout<<endl;
}
| Is This Answer Correct ? | 14 Yes | 32 No |
f1() { f(3);} f(int t) { switch(t); { case 2: c=3; case 3: c=4; case 4: c=5; case 5: c=6; default: c=0;} value of c?
What is the function of volatile in c language?
What is the best style for code layout in c?
Why & is used in c?
What is the output of the program given below #include<stdio.h> main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
21 Answers ADITI, Student, TCS,
Explain how can I convert a string to a number?
what is c++ programming?
Write a C program to accept a matrix of any size. Find the frequency count of each element in the matrix and positions in which they appear in the matrix
How to print all the 26 alphabets in this order in C. AbCdEfGh..... it should print dynamically from a to z and do not print this using pgm like this print("Ab......"); Use loops or anything to print all alphabets
What is structure padding in c?
what is the main use of c where it can use the c
which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above