/*
Write a program to ask the user to enter an entire input line 
from the keyboard. Then read this string (call it line) using 
getline. Then encrypt the string as follows: replace every 
character in line by the reverse of its ASCII position. 
Store the new string in a variable called encrypted. 
Then print encrypted.
*/
#include <iostream>
#include <string>
using namespace std;
string IntToString(int n)
{
	// This function converts from int to string.
	// Note: There is a similar function in C++.
	string s = "", t = "";
	char c;
	int i, m, len;
	while (n != 0)
	{
		m = n % 10;
		c = char(m + 48);
		s = s + c;
		n = n / 10;
	}
	len = s.length();
	for (i = len - 1; i >=0; i--)
		t = t + s[i];
	return t;
}
int main()
{
	string line, s, reversed, encrypted = "";
	int i, j, n, m, asciiPos;
	cout << "Enter a string (could be an entire line):\n";
	getline(cin,line);
	n = line.length();
	i = 0;
	while (i < n)
	{
		
		//line = lineReversed;

		// Get the ASCII position of the character at position i.
		asciiPos = line[i];
		// Convert the ASCII position to string.
		s = IntToString(asciiPos);
		// Now reverse s
		reversed = "";
		m = s.length();
		j = m - 1;
		while (j >= 0)
		{
			reversed = reversed + s[j];
			j--;
		}
		// Update the encrypted line
		encrypted = encrypted + reversed;
		i++;
	}
	cout << "The encrypted line is: \n";
	cout << encrypted << endl;
	system("pause");
	return 0;
}

