I am searching for a way to convert a string of characters into a string of their hexadecimal representations. So the letter A
will be represented as 0x41
.
What I am trying to do is encrypting a text file using an algorithm that encrypts hexadecimal characters of notation 0x** where ** resembles the hexadecimal notation of the character.
I am reading an array of 16 characters from the file to an array of characters, then I should convert them to hexadecimal notation so I can pass them to the encryption function.
I am using the following snippet of code to convert the array of characters to hexadecimal. I created a TempBuffer to hold the hexadecimal value for each character so it will be in the notation 0x**. My problem is how to store the value in TempBuffer to an element of the Unsigned characters array. Look the code below:
static uint8_t TextToEncrypt[16]; // Declaring the array to store the hexadecimal notation
void ToHex(char InText[]) // The Function to Convert an array of characters to hexadecimal array
{
int i=0;
for(i=0; i<16; i++)
{
char TempBuffer[4]; // Tempbuffer to hold the converted value
sprintf(TempBuffer,"0x%x",InText[i]); // converting to hexadecimal
// Here i need to store the value in TempBuffer which will be something like 0x41 in TextToEncrypt[i] so I can pass it to encryption
}
}