someone explain encrypting keys?

Hello,
I am trying to incorporated into my program a way for the user to enter there own key to encrypt to.
right now I have it encrypting and decrypting to a default key when the user enters default, but if the user enters there own code at this junction how do I take that new key in and use it?
can someone explain how to do this?
or just give a hint, anything will help.

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
52
53
54
55
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main ()
{
	string method, map, word, str;
	int encryption, decryption;

	cout<<"What is the method (encryption or decryption)?"<<endl;
	cin>>method;
 
    if (method=="encryption")
    {
		cout<<"What is the translation map (type 'default' to use default):"<<endl;
        cin>>map;
        if (map=="default")
        {
			cout<<"What is the single word to translate:"<<endl;
            cin>>word;

			for(int i = 0; i < word.length(); i++)
				word.at(i) = 'a' - word.at(i) + 122; //'z' == 122
			
            cout<<"encrypted word: "<<word<<endl;                 
		}
		
		else 
		    cout<<"not valid"<<endl;
	}
    else if (method=="decryption")
    {
        cout<<"What is the translation map (type 'default' to use default):"<<endl;
        cin>>map;
        if (map=="default")
        {
		cout<<"What is the single word to translate:"<<endl;
            cin>>word;

			for(int i = 0; i < word.length(); i++)
				word.at(i) = 'a' - word.at(i) + 122; //'z' == 122
				
			cout<<"decrypted word: "<<word<<endl;
        }
        else
            cout<<"not valid"<<endl;
    }
    else
		cout<<"Error: invalid method choice."<<endl;

	
	return 0;
}
Here its farly simple
en.wikipedia.org/wiki/Caesar_cipher
I have make similiar before usng this method
thank you
But doesn't Caesar cipher only shift the input?
I'm looking for the user to input there own key
Yes it is, What did you mean ? Give some example :D
I really hope your code isn't formatted like that. :)

Here's an example:

1
2
3
4
5
6
7
8
9
10
std::string Encrypt(const std::string& source, const std::string& key)
{
	std::string temp; temp = ""; // Store the encryped text
	int tempk; tempk = 0; // Store the key

	for(int j = 0; j < key.length(); j++) tempk += (int)key[j]; // Key is the char values added together
	for(int i = 0; i < source.length(); i++) temp += (char)source[i] ^ tempk; // Encrypt each letter of the word

	return temp;
}
for example
the user chooses encryption
next the user inputs their own key, that is no more than 26 characters.
nhjuyhgf
next the code assigns
a to n
b to h
c to j
d to u
etc...
next the user enters a word... : help
the output would be: belp

Its hard to do it without a specific pattern ._. I know there's another method of caesar chipper instead of using a single charater as a key, it use a word as a key example
The word is "what"
And the key is "abc"
First the key word should be extended up to numbers of letter in descrypted word
So the key will be "abca"
Then encryption begn :D
w -> a = w
h -> b = i
a -> c = c
t -> d = x
Done o,o
Topic archived. No new replies allowed.