HEX to INT
-
i have used INTtoHEX to convert some text to HEX but now I need to convert it back to read able text any cues? AnsiString EditText = RichEdit1->Lines->Text; for (int i=1;i<=EditText.Length();i++) { RichEdit2->Lines->Text = RichEdit2->Lines->Text + IntToHex(EditText[i],2); } RichEdit1->Lines->Text = ""; RichEdit1->Lines->Text = RichEdit2->Lines->Text; RichEdit2->Lines->Text = "";
-
i have used INTtoHEX to convert some text to HEX but now I need to convert it back to read able text any cues? AnsiString EditText = RichEdit1->Lines->Text; for (int i=1;i<=EditText.Length();i++) { RichEdit2->Lines->Text = RichEdit2->Lines->Text + IntToHex(EditText[i],2); } RichEdit1->Lines->Text = ""; RichEdit1->Lines->Text = RichEdit2->Lines->Text; RichEdit2->Lines->Text = "";
-
i have used INTtoHEX to convert some text to HEX but now I need to convert it back to read able text any cues? AnsiString EditText = RichEdit1->Lines->Text; for (int i=1;i<=EditText.Length();i++) { RichEdit2->Lines->Text = RichEdit2->Lines->Text + IntToHex(EditText[i],2); } RichEdit1->Lines->Text = ""; RichEdit1->Lines->Text = RichEdit2->Lines->Text; RichEdit2->Lines->Text = "";
Very crude, but i think this should work (send 2 chars at a time in your case)
int Hex2Int(char* hex)
{if (!*hex) return 0;int tmp = 0;
if (*hex >= '0' && *hex <= '9')
tmp = *hex - '0';
else if (*hex >= 'A' && *hex <= 'F')
tmp = *hex - 'A' + 10;
else if (*hex >= 'a' && *hex <= 'f')
tmp = *hex - 'a' + 10;return (tmp << (4*(strlen(hex)-1))) + Hex2Int(hex+sizeof(char));
}/moliate
-
Very crude, but i think this should work (send 2 chars at a time in your case)
int Hex2Int(char* hex)
{if (!*hex) return 0;int tmp = 0;
if (*hex >= '0' && *hex <= '9')
tmp = *hex - '0';
else if (*hex >= 'A' && *hex <= 'F')
tmp = *hex - 'A' + 10;
else if (*hex >= 'a' && *hex <= 'f')
tmp = *hex - 'a' + 10;return (tmp << (4*(strlen(hex)-1))) + Hex2Int(hex+sizeof(char));
}/moliate
sorry i am not sure how to implement this on to a decrypt button? when i press encrypt i get something like this: 68 65 72 65 73 20 77 68 61 74 20 68 61 70 70 65 6E 73 0D 0A and that says: heres what happens so i need the button to change it back from numbers to the text?
-
sorry i am not sure how to implement this on to a decrypt button? when i press encrypt i get something like this: 68 65 72 65 73 20 77 68 61 74 20 68 61 70 70 65 6E 73 0D 0A and that says: heres what happens so i need the button to change it back from numbers to the text?
Perhaps it is not the best solution for you. Anyway, what the function does is taking a string like |6|8|\0| and turn it into the number 104 decimal - the ascii code for 'h'. If you can access each line as a string, you can send it to the function and get back a char. The string must be null-terminated, though. /moliate
-
sorry i am not sure how to implement this on to a decrypt button? when i press encrypt i get something like this: 68 65 72 65 73 20 77 68 61 74 20 68 61 70 70 65 6E 73 0D 0A and that says: heres what happens so i need the button to change it back from numbers to the text?
-
Those are all ASCII character values displayed in hex. Try sprintf with a %c format specifier to get the text character. See the docs on sprintf for more details.
right heres what i have now: Encrypt: AnsiString EditText = RichEdit1->Lines->Text; for (int i=1;i<=EditText.Length();i++) { Form1->Tmp = Form1->Tmp + IntToHex(EditText[i],2); } RichEdit1->Lines->Text = ""; RichEdit1->Lines->Text = Form1->Tmp; Form1->Tmp = ""; Decrypt: AnsiString DeCrypt = Form1->RichEdit1->Lines->Text; int i = 1; int l = 2; for ( ;iTmp = DeCrypt[i]; Form1->Tmp = Form1->Tmp + DeCrypt[l]; Form1->RichEdit1->Lines->Append (Form1->Tmp); } so now: hello when encrypted = 68656C6C6F0D0A and on decrypt i get: 68 65 6C 6C 6F 0D 0A so tmp contains the temp string for each letter i now just need tmp to be converted?