[Q]Hide Password

This is a discussion on [Q]Hide Password within the C++ Programming forums, part of the General Programming Boards category; Hi. I know you can hide you password (in your .exe) with XOR encryption, but I have a question. I ...

  1. #1
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133

    [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 ];

        
    Password ] = 104;
        
    Password ] = 101;
        
    Password ] = 108;
        
    Password ] = 108;
        
    Password ] = 111;

        
    char Transfer ];

        
    Transfer ] = Password ];
        
    Transfer ] = Password ];
        
    Transfer ] = Password ];
        
    Transfer ] = Password ];
        
    Transfer ] = Password ];

        
    string Pass Transfer,
               
    Input;

        
    cout << "Input Password: ";
        
    cin >> Input;

        if ( 
    Input == Pass )
        {

            
    cout << "Correct";
        }

        else
        {

            
    cout << "Wrong";
        }

        
    cin.ignore();
        
    cin.get();


  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >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.

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    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.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Hmm ok, but I still can't find it in my .exe file. How can I find 'hello' in my .exe?

  5. #5
    Registered User
    Join Date
    Feb 2005
    Posts
    59
    Using a debugger as swoopy previously stated.

  6. #6
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    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.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  7. #7
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    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.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  8. #8
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    What do you mean with 'Out of range' it is the decimal value of 'o' from 'hello'. And how do you debug a .exe?
    Last edited by Yuri; 03-01-2006 at 08:56 AM.

  9. #9
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    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.
    Sent from my iPadŽ

  10. #10
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    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)?

  11. #11
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    The first one will not compile, but anyways

    The the first one is faster. It works like that because of registers and scope

  12. #12
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    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.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  13. #13
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    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)

  14. #14
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    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

  15. #15
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    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.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A tenet connection from a C program..
    By ahmd2080 in forum Linux Programming
    Replies: 2
    Last Post: 07-04-2009, 03:42 AM
  2. Problem reading a password from a file.
    By medeshago in forum C Programming
    Replies: 15
    Last Post: 12-21-2008, 06:20 AM
  3. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 08:42 PM
  4. Password prompt in unix w/o \b
    By rafe in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2002, 08:54 AM
  5. password
    By hammers6 in forum C Programming
    Replies: 1
    Last Post: 10-10-2001, 12:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21