• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 744
  • Last Modified:

Encrypt & Decrypt password

hi!,  i'd like to know how can i encrypt & decrypt string in visual c++ 6.0, please provide me sample routine or reference.
0
nolram
Asked:
nolram
  • 6
  • 5
  • 2
  • +2
1 Solution
 
Arthur_WoodCommented:
How secure does the encryption need to be.  The algorithms suggested by ozo, while being very secure, and also very involved.  A very simple, and yet also reasonably secure encryption technique is known as XOR encryption (XOR for the Logical operation Exclusive OR).  The process is completely symmetric, meaning that to Encrypt a value, you XOR the Key with the value to be encrypted, which produces the ENCRYPTED result.  To decrypt the ENCRYPTED value, you again XOR the ENCRYPTED result with the Key, and you get the Original value back again.

AW
0
 
ozoCommented:
perhaps in the sense of
A very simple, and yet also "not excessive or extremely" secure encryption technique
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Arthur_WoodCommented:
ozo>> depends on how it is implemented.  I used a 'trick', using the Users UserName as the encryption Key, which has the effect of creating a DIFFERENT KEY for every user, and this is very close to using a One-Time Pad, which is UNCRACKABLE.

AW
0
 
ozoCommented:
An uncrackable One-Time Pad requires a *random* key of the same length as the plaintext.
UserName tends not to be very random.
0
 
Arthur_WoodCommented:
true, but as I said, it is 'very close', since the algorithm is NOT identified as a 'one time pad', and each user does in fact have a UNIQUE user name, and if the username is shorter than the plaintext, I simply concatenate the username as many times as needed to create a key that IS as long as the plain text.

And since someone trying to crack the encryption is not aware of the algorithm in use, cracking it is essentially impossible.

AW
0
 
Arthur_WoodCommented:
ozo>> also, in the application where I used this, there was only a single field (it happened to be a Creadit Card Number) that needed to be encrypted for each user, so there were not multiple encrypted fields ion play for a potential cracker to try out various algorithms against.

AW
0
 
ozoCommented:
concatenating a key  as many times as needed to create a key that IS as long as the plain text is one of the common misuses of 'one time pad' that have opened the door to many cracks.
I'm sure there are many applications where XORing with a repeating user name is adequate, but Creadit Card Number protection is not one I would count among them.
0
 
Arthur_WoodCommented:
ozo, I might agree with you in the general case, but the situation was that the application was on a secure PC, in the Pentagon, nn Washington DC, and the PC was NOT accessible from the outside.  So the approach was sufficient for the situation.

AW
0
 
Arthur_WoodCommented:
Notice that we have been talking to ourselves, and the original asker is nowhere to be found.  Perhaps we should wait until he/she deems it necesary to make himself/herself heard.

AW
0
 
nolramAuthor Commented:
sorry guys i did not mean my question will turn into an argument, i just want to know or have a simple routine for encrypting or decrypting user password, i'd seen a routine before, which i can not found right now, i think its name is encryptor?, i tried to consult experts in experts exchange if ever you have this.

sorry again and thanks again.
0
 
ozoCommented:
user passwords are usually hashed with a one way function that cannot be decrypted, only compared to see if you had the right password.
What exactly do you want to do with this routine?
If you are looking for a specific routine, "encryptor" is a pretty common name.
You might try googleing for it and see if you can recognise which one you want.
0
 
dr_countryCommented:
If you are looking for something simple you can use a Caesar cipher. Use arrays of all the alphabetical characters, number, special characters, etc. For example,

char upper[] = {'A','B','C',......'Z'};
char lower[] = {'a','b','c',.......'z'};
char number[] = {'0','1','2',....'9'};
char special[] = {'@','~','_',.........};

then call encrypt(int key)

char* encrypt(char *theString, int key)
{
   char temp;
   char *output;

   if(theString != NULL)
   {
       for(int i=0; i<theStringLength; i++)
       {
             temp = theString[i];

            if( temp == 'A' || temp == 'B' || ..... || temp == 'Z')
              {

                  for(int j = 0; j<upperLength; j++)
                      {
                          if(temp == punctuation[j])
                             {
                                int ctext = ((j + key)%upperLength);
                                if(ctext < 0) ctext += upperLength;
                                temp = punctuation[ctext];
                                break;
                              }
                      }
              }
     
pretty much do the same thing for all your arrays and then
at the end add each encrypted character to your new array:

    output[i] = temp;

}//end of for loop

return output;
}

The second parameter, int key, is the number that will be used to shuffle around, or number of spaces to move so your decrypt function should use the same key and do the inverse of the encrypt function. Hope it helps.
                   
             
0
 
dr_countryCommented:
I guess this is what you were looking for? No more questions?
0
 
nolramAuthor Commented:
hi! thanks for all ur reply, i found and apply this hashing of password using MD5, http://www.codeguru.com/Cpp/Cpp/algorithms/article.php/c5087 , Implementing MD5 algorithm
0
 
moduloCommented:
PAQed with points refunded (100)

modulo
Community Support Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 5
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now