Help about encode and decode text

Basically, i need a code to encode and decode a text combined only by capital letters and blank spaces. The text needs to be encoded on a way that every letter is changed by ascii code is raised by the smallest figure of a random entered three-digit number. The text and the numbers have to be different. And this is what i got, i could use a bit help, THANKS YOU UPWORDS AND ALOT !
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  #include<iostream>
#include<string>	

using namespace std;

int main()
{
	// KEYS TO BE USED
	const int ROT13 = 13, ROT7 = 7;

	cout << endl << " Enter a string of text. Press ENTER when finished. " << endl << endl;
	cout << " Text: ";

	string text;
	getline(cin, text);

	string encText = text; // text to encrypt
	
	for (size_t i = 0; i < encText.size(); i++)
	{
		encText[i] = encText[i] + ROT13;

		if (encText[i] % 5 == 0)
			encText[i] = encText[i] + ROT7;
		//encText;  // Add or removing this had no effect
	}

	cout << endl << "Encrypted text is " << endl << encText << endl;
	string decText = encText;  // Text to decrypt

	for (size_t i = 0; i < decText.size(); i++)
	{
		decText[i] = decText[i] - ROT13;

		if (decText[i] % 5 == 0)
			decText[i] = decText[i] - ROT7;
		//decText;
	}

	cout << endl << "Decrypted text is " << endl << decText << endl << endl;
	return 0;
}
Try doing a single character by hand. Suppose the character code is 12:
Line 21 sets it to 12+13=25.
25 is divisible by 5 so line 24 sets it to 25+7=32.

Now look at the decode part.
Line 33 sets it to 32=13 = 19.
19 is not divisible by 5 so line 36 isn't executed

The So the decoded character is 19, which is wrong.

My advice is to work out the algorithm by hand with a few characters. Once you're pretty sure you have the algorithm right, convert it to code.
@pzycloN3
Do you have another user name?

You see, your code is EXACTLY the same as
http://www.cplusplus.com/forum/beginner/204780/#msg971197
You know, monkeys and typewriters and all that ...!

Basically, i need a code to encode and decode a text combined only by capital letters and blank spaces. The text needs to be encoded on a way that every letter is changed by ascii code is raised by the smallest figure of a random entered three-digit number. The text and the numbers have to be different. And this is what i got, i could use a bit help, THANKS YOU UPWORDS AND ALOT !


Well, I don't believe "this is what I got".

And I don't see what this has got to do with "every letter is changed by ascii code is raised by the smallest figure of a random entered three-digit number".

Make an effort - by yourself - maybe someone will try to help you.
Rip off somebody else's code and try to pass it off as your own - well, not convinced anyone will want to look at it.
Registered users can post here. Sign in or register to post.