algorithm

can some on give me a more complicated algorithm for this code my doesnt work.
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
43
44
45
46
47
48
49
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <Windows.h>

using namespace std;

int main()
{
	string code;
	string message;
	
	while (true)
	{
		SetConsoleTitleA((LPCSTR)"Encryption/Decryption Software");
		cout << "Encrypt or Decrypt: ";
		cin >> code;

		if (code == "encrypt")
		{
			cout << "Input the message would u like to Encrypt" << endl;
			SetConsoleTitleA((LPCSTR)"Encoding . . .");
			getline(cin >> ws, message);
			transform(message.begin(), message.end(), message.begin(), [](int c){ if (isalpha(c) && (c = tolower(c)) && (c += 13) && c > 'z') c -= 26; return c; });
			transform(message.begin(), message.end(), message.begin(), [](int c){ if (isalpha(c) && (c = tolower(c)) && (c -= 21) && c > 'z') c -= 26; return c; });
			transform(message.begin(), message.end(), message.begin(), [](int c){ if (isalpha(c) && (c = tolower(c)) && (c += 33) && c > 'z') c -= 26; return c; });
			cout << message << endl;
			continue;
		}
		else if (code == "decrypt")
		{
			cout << "Input the message would u like to Decrypt" << endl;
			SetConsoleTitleA((LPCSTR)"Decoding . . .");
			getline(cin >> ws, message);
			transform(message.begin(), message.end(), message.begin(), [](int c){ if (isalpha(c) && (c = tolower(c)) && (c -= 13) && c < 'a') c += 26; return c; });
			transform(message.begin(), message.end(), message.begin(), [](int c){ if (isalpha(c) && (c = tolower(c)) && (c += 21) && c < 'a') c += 26; return c; });
			transform(message.begin(), message.end(), message.begin(), [](int c){ if (isalpha(c) && (c = tolower(c)) && (c -= 33) && c < 'a') c += 26; return c; });
			cout << message << endl;
			continue;
		}
		else
		{
			cout << "Sorry, that is none of the choices please try again" << endl;
			continue;
		}
		return 0;
	}
}
Last edited on
Generally, the goal of programming is to find the simplest, most elegant algorithm, not a more complex one. What do you mean by "doesn't work"? Does it make your keyboard explode? Does it eject your CD drive? Does it email your friends a virus? You need to be specific.
Generally, the goal of programming is to find the simplest, most elegant algorithm, not a more complex one. What do you mean by "doesn't work"? Does it make your keyboard explode? Does it eject your CD drive? Does it email your friends a virus? You need to be specific.


I litterally laughed 20 minutes at this post. Your answer doesn't fix my laughing problems :D

Dear kmtompkins:

You should really read what transform does and if you REALLY need it to make an encryption algorithm.

Usually everyone thinks of a pattern to encrypt and decrypt rather than using C/C++ lib functions :)
Last edited on
nvm i got it

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
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <Windows.h>

using namespace std;

int main()
{
	string code;
	string message;
	
	while (true)
	{
		SetConsoleTitleA((LPCSTR)"Encryption/Decryption Software");
		cout << "Encrypt or Decrypt: ";
		cin >> code;

		if (code == "encrypt")
		{
			cout << "Input the message would u like to Encrypt" << endl;
			SetConsoleTitleA((LPCSTR)"Encoding . . .");
			getline(cin >> ws, message);
			transform(message.begin(), message.end(), message.begin(), [](int c){ if (isalpha(c) && (c = tolower(c)) && (c += 13) && c > 'z') c -= 26; return c; });
			transform(message.begin(), message.end(), message.begin(), [](int c){ if (isalpha(c) && (c = tolower(c)) && (c += 10) && c > 'z') c -= 26; return c; });
			transform(message.begin(), message.end(), message.begin(), [](int c){ if (isalpha(c) && (c = tolower(c)) && (c += 1) && c > 'z') c -= 26; return c; });
			transform(message.begin(), message.end(), message.begin(), [](int c){ if (isalpha(c) && (c = tolower(c)) && (c += 20) && c > 'z') c -= 26; return c; });
			cout << message << endl;
			continue;
		}
		else if (code == "decrypt")
		{
			cout << "Input the message would u like to Decrypt" << endl;
			SetConsoleTitleA((LPCSTR)"Decoding . . .");
			getline(cin >> ws, message);
			transform(message.begin(), message.end(), message.begin(), [](int c){ if (isalpha(c) && (c = tolower(c)) && (c -= 13) && c < 'a') c += 26; return c; });
			transform(message.begin(), message.end(), message.begin(), [](int c){ if (isalpha(c) && (c = tolower(c)) && (c -= 10) && c < 'a') c += 26; return c; });
			transform(message.begin(), message.end(), message.begin(), [](int c){ if (isalpha(c) && (c = tolower(c)) && (c -= 1) && c < 'a') c += 26; return c; });
			transform(message.begin(), message.end(), message.begin(), [](int c){ if (isalpha(c) && (c = tolower(c)) && (c -= 20) && c < 'a') c += 26; return c; });
			cout << message << endl;
			continue;
		}
		else
		{
			cout << "Sorry, that is none of the choices please try again" << endl;
			continue;
		}
		return 0;
	}
}
Topic archived. No new replies allowed.