Password to decimal.

I am creating an encryption program, nothing fancy, I have written some working methods that jumble up text as needed and can be reversed as needed.

But I now need to create a key/password that works to encrypt and decrypt the files and I don't know where to start.

So if the user types in "Password" I want to internally convert that to the decimal equivalent e.g. "16 1 19 19 23 15 18 4"

I thought about doing an ASCII conversion but then how to I apply parameters that account for capitals and keep it within the 1-26 bounds?

I found this as a simple method but it throws up "error C2660: 'returnVal' : function does not take 1 arguments" as an error every time

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
string UserPassword;
cout << "Enter a Password: ";
cin >> UserPassword;
string s = UserPassword;
for (unsigned int i = 0; i < s.length(); i++)
{
    returnVal(s[i]);
}
return 0;

int returnVal(char x)
{
	return (int)x - 87;
}
Does your complete code also have a prototype declaration for returnVal? What does that state.
It does, with or without it throws the same error
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using namespace std;

int returnVal(); 

int main()
{
	string UserPassword;
	cout << "Enter a Password: ";
	cin >> UserPassword;
	string s = UserPassword;
	for (unsigned int i = 0; i < s.length(); i++)
	{
		returnVal(s[i]);
	}
	return 0;
}
	int returnVal(char x)
	{
		return (int)x - 87;
	}
Change the declaration (line 3)
from
int returnVal();
to
int returnVal(char);
That worked a treat! Thank you very much
Why did it need that may I ask?
Well, the full function definition,
17
18
19
20
int returnVal(char x)
{
    return (int)x - 87;
}
could be placed in a completely separate source file - that might be the case in a more complex project. So the only knowledge the compiler has when the function is called at line 13, is based on the prototype.

The purpose of the prototype declaration: int returnVal(char); is to
1. allow the compiler to check that the function is being called with suitable parameters, and
2. to actually generate the code which calls the function and receives the returned value, if any.

In order for that to work, the parameter list in the declaration must match the parameter list when the function is called - that is the type of each parameter should match, or be compatible. The return type is also required for similar reasons.

After the code has been compiled, it is the job of the linker to match up each function call with the code belonging to that function. That's a separate stage and may generate its own error messages.
Last edited on
Topic archived. No new replies allowed.