How do I convert characters (in arrays and strings) to its respective ascii value. I want to do that so I can encrypt some variables for a save file, to prevent tampering(or at least not useful tampering). Thanks.
Printable View
How do I convert characters (in arrays and strings) to its respective ascii value. I want to do that so I can encrypt some variables for a save file, to prevent tampering(or at least not useful tampering). Thanks.
how do you think they are stored in memory??
as characters?
remember computers only understand numbers!
Stoned_Coder is right.
But for knowledge sake, use the stty raw echo command. Get the input and the raw echo will convert it to hex.
This is just a little C that I put together for you...lol :) Just to test that conversion works......printf. Object oriented is pretty much the same way.Code:#include <stdio.h>
#include <stdlib.h>
void main(){
char input;
system("stty raw -echo");
printf("This program is designed to convert characters into hex"
" value\n\r");
printf("Press q at any time to quit this program");
while(input != 'q'){
fflush(stdin);
printf("\n\rPlease enter a character:");
scanf("%c", &input);
printf("\n\rChahrater entered: %c", input);
printf("\n\rHexidecimal value: %x", input);
printf("\n\n\rPress q at any time to quit this program");
}
printf("\n\r\n\rThank you\n\r");
system("stty -raw echo");
}
But this will not make anything secure!!!
Or you could use itoa