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.






Write an interactive c program that will encode or decode a line of text. To encode a line of text..

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

Post New Answer

More C Interview Questions

list the no of files created when c source file is compiled

9 Answers   TCS,


#include main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); break; case j: printf("BAD"); break; } }

6 Answers   ME,


how can i get this by using for loop? * ** * **** * ******

3 Answers   Excel,


What is derived datatype in c?

0 Answers  


Explain can you assign a different address to an array tag?

0 Answers  






write a program to reverse the words in the sentence.NOTE:not reverse the entire string but just the occurance of each word

1 Answers   Sienna Ecad, Wipro,


how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions

0 Answers  


What's the right way to use errno?

0 Answers  


What is the difference between GETS();AND SCANF();

4 Answers   TCS,


where can function pointers be used?

2 Answers  


Explain how can you tell whether two strings are the same?

0 Answers  


helllo sir , what is the main use of the pointer ,array ,and the structure with the example of a programe

2 Answers  


Categories