C Text Encryption

Hi, I have a program in C that takes in a users password of type: char *userPass;

I need to store the password for the program inside the source code in an encrypted format that can be compared by the user's password entry once that too has been encrypted.

I need any kind of algorithm be it simple or otherwise as I can just choose the best one to suit my needs and experimentation. I've tried finding an inbuilt function in C but the only one i found works best only with numbers.

Any help will be appreciated even if you just point me in the right direction.

for (i=0; i<len; i++) { text [i] ^= mask; }}[/code][color=Blue]After encryption, you need to keep the length of the text together with the encrypted text - to make comparisons, because after encryption text may be no longer terminated with zero and strcmp() type of functions will be useless and dangerous to use - you will have to use the memcmp() with length.

XOR-ing with the same value is not strong. Try to add some value to the mask for each character to make it stronger:[/color][code]void encrypt (char* text, int len){ unsigned char mask = 0xAB; int i;

for (i=0; i<len; i++, mask += 9) { text [i] ^= mask; }}[/code][color=Blue]In professional programs usually MD5 algorithm is used to get a signature of the data:

strcpy (pass1, "password");len = strlen (pass1);encrypt (pass1, len);[/code][color=Blue]After encryption - you can't use any string functions on it (you tried to use "%s" to print it, but "%s" assumes the proper string and it is no longer a proper string - it is just a line of bytes)[/color]

I'm having trouble matching the encryptedPass to userPass coz I can't use "password" inside the code, but I've encrypted the userPass and a 3rd one that is an encrypted version of "password" and they match fine.

The only thing i can think of is that i need to use an escape character to make

: I'm having trouble matching the encryptedPass to userPass coz I : can't use "password" inside the code, but I've encrypted the : userPass and a 3rd one that is an encrypted version of "password" : and they match fine.: : The only thing i can think of is that i need to use an escape : character to make

I know i shouldn't have testPass i was just using it in my debugging to find out whether i was comparing them wrong, but it seems like encryptedPass is changed from just an encrypted version of the text "password" because writng it in the source code requires an escape character for the " in: