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 |
There is a number and when the last digit is moved to its first position the resultant number will be 50% higher than the original number.Find the number?
how to write a cprogram yo get output in the form * *** ***** ******* ********* ******* ***** *** *
Difference Between embedded software and soft ware?
why we use "include" word before calling the header file. is there any special name for that include??????
What is meant by high-order and low-order bytes?
logic for generating all the combinations of the any number of given letters. ex::::::::: if a,b,c,d are given the o/p should be abcd,dcba,dbac,bcad,................ 4*3*2*1 combinations............
print out of string in this format; 1. "rajesh" 2. \n 3. %d
What is the difference between array and structure in c?
How do you list a file’s date and time?
Write a program to compute the similarity between two strings - The program should get the two strings as input - Then it will output one single number which is the percentage of similarity between the two strings
In the following code segment what will be the result of the function, value of x , value of y { unsigned int x=-1; int y; y = ~0; if(x == y) printf("same"); else printf("not same"); } a) same, MAXINT, -1 b) not same, MAXINT, -MAXINT c) same , MAXUNIT, -1 d) same, MAXUNIT, MAXUNIT e) not same, MAXINT, MAXUNIT
How can you increase the size of a dynamically allocated array?