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

What's the best way to declare and define global variables?

7 Answers  


What does s c mean in text?

0 Answers  


how to use showbits function?

2 Answers   Infosys, TATA,


Write a c program to demonstrate Type casting in c?

2 Answers  


What is the most efficient way to count the number of bits which are set in a value?

4 Answers  






print the palindrome numbers in between 0 to n

1 Answers  


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

0 Answers   L&T,


Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)

0 Answers  


what is difference between C and C++

4 Answers  


progrem to generate the following series 1 12 123 1234 12345

6 Answers   HCL, Wipro,


What does return 1 means in c?

0 Answers  


how to make c program without a libary? e.g.#include<stdio.h> libary is not in c progaram.

2 Answers  


Categories