-
[Q]Hide Password
Hi.
I know you can hide you password (in your .exe) with XOR encryption, but I have a question. I found out another simple way to hide it but I've never seen it before (I haven't really searched for it) so I quess it wont work. So my question is: Why doesn't this code work to hide the password, the password is hello and if I open my .exe with notepad, I can't find the string 'hello'.
PHP Code:
#include <iostream>
using namespace std;
int main()
{
int Password [ 4 ];
Password [ 0 ] = 104;
Password [ 1 ] = 101;
Password [ 2 ] = 108;
Password [ 3 ] = 108;
Password [ 4 ] = 111;
char Transfer [ 4 ];
Transfer [ 0 ] = Password [ 0 ];
Transfer [ 1 ] = Password [ 1 ];
Transfer [ 2 ] = Password [ 2 ];
Transfer [ 3 ] = Password [ 3 ];
Transfer [ 4 ] = Password [ 4 ];
string Pass = Transfer,
Input;
cout << "Input Password: ";
cin >> Input;
if ( Input == Pass )
{
cout << "Correct";
}
else
{
cout << "Wrong";
}
cin.ignore();
cin.get();
}
-
>Why doesn't this code work to hide the password
With this method the password could easily be picked out using a debugger. Using the xor method this wouldn't be possible.
-
It won't work because you are essentially writing each character of your password into contiguous blocks of memory (an array)
Code:
Password [ 0 ] = 104;
Password [ 1 ] = 101;
Password [ 2 ] = 108;
Password [ 3 ] = 108;
Password [ 4 ] = 111;
is no different than
Code:
Password [ 0 ] = 'h';
Password [ 1 ] = 'e';
Password [ 2 ] = 'l';
Password [ 3 ] = 'l';
Password [ 4 ] = 'o'
They both resolve to the same thing.
moving continguous memory from one location to another does nothing to facilitate encryption, it is no different than moving your car keys from the kitchen table to the dining room.
Code:
//This just adds unecessary overhead
Transfer [ 0 ] = Password [ 0 ];
Transfer [ 1 ] = Password [ 1 ];
Transfer [ 2 ] = Password [ 2 ];
Transfer [ 3 ] = Password [ 3 ];
Transfer [ 4 ] = Password [ 4 ];
If you want to avoid putting each character of your password into contiguous blocks of memory, avoid using arrays. Try pusing each character of your password into a linked list.
-
Hmm ok, but I still can't find it in my .exe file. How can I find 'hello' in my .exe?
-
Using a debugger as swoopy previously stated.
-
Code:
int Password [ 4 ];
Password [ 0 ] = 104;
Password [ 1 ] = 101;
Password [ 2 ] = 108;
Password [ 3 ] = 108;
Password [ 4 ] = 111; //Out of range
So the code is wrong. Though it wouldn't do anything useful if it was right.
-
Code:
int Password [ 4 ];
Password [ 0 ] = 104;
Password [ 1 ] = 101;
Password [ 2 ] = 108;
Password [ 3 ] = 108;
Password [ 4 ] = 111; //Out of range
So the code is wrong. Though it wouldn't do anything useful if it was right.
-
What do you mean with 'Out of range' it is the decimal value of 'o' from 'hello'. And how do you debug a .exe?
-
He means it's out of the bounds of your array. You declared an array with the subscript size of 4. This means the available indexes are 0, 1, 2, and 3. Not 4.
...and your compiler most likely came with a debugger, if it didn't you can get one online.
-
Just to wont make a new thread... I have another question but about something else; If possible, is it better to declare variables non global?
Example, which one is better (like faster):
Code:
#include <iostream>
using namespace std;
void Check()
{
int Bla = 5;
Bla = Bla + Var;
}
int main()
{
int Var;
cout << "Enter numb:";
cin >> Var;
Check();
cout << "Output: "<< Bla;
cin.ignore();
cin.get();
}
Or:
Code:
#include <iostream>
using namespace std;
int Bla = 5,
Var;
void Check()
{
Bla = Bla + Var;
}
int main()
{
cout << "Enter numb:";
cin >> Var;
Check();
cout << "Output: "<< Bla;
cin.ignore();
cin.get();
}
It probably wont really metter in this case but in big projects and etc. it may cost very little difference. But, what will be better (like faster), the first one or second (even when the difference is really really little)?
-
The first one will not compile, but anyways
The the first one is faster. It works like that because of registers and scope
-
Your first code will not work. Because Bla in main is not the Bla in check. you should do it this way:
Code:
#include <iostream>
using namespace std;
int Check(int Var)
{
int Bla = 5;
return Bla + Var;
}
int main()
{
int Var;
int Bla;
cout << "Enter numb:";
cin >> Var;
Bla = Check(Var);
cout << "Output: "<< Bla;
cin.ignore();
cin.get();
}
Using non global is better. But there is another technique that is a balance between fast and safe. It is file scope. Like this:
Code:
#include <iostream>
using namespace std;
static int Bla = 5,
Var;
void Check()
{
Bla = Bla + Var;
}
int main()
{
cout << "Enter numb:";
cin >> Var;
Check();
cout << "Output: "<< Bla;
cin.ignore();
cin.get();
}
Now only functions in this file can access Bla and Var.
-
I didn't know of static, to understand (make sure); So, only where you use the static variables, in Check and main in this case, they will be accessed to those functions? And not to other functions accept if you use it in that function, right? (:P, thanks btw)
-
If you created another function in that file, then you would be able to access blah and var there too. If you were to create another source file in the same project, it would not be able to access them.
A normal int has function scope
A static int has file scope
An int declared outside of a functon has global scope
-
I didn't want to teach you scoping, I just wanted to give an example. Start learning C++ by a book (if you didn't have started yet), you will find out all of that step by step.