Page 1 of 1

Hex String Definition

Posted: Tue Jul 15, 2014 3:55 am
by dcpbarrington
Forum,

I need to define a 128 bit string to use as a Key for encrypt().

I've defined a Hex string to represent the 128 bits = "C0FB7F4F840BBDC0F3FF1A2E0BA9E179"

The problem is that the string is not interpreted as HEX, but as 8 bit Ascii characters, which is 256 bits.

How do you represent a Hex String in LiveCode. I tried to prefix it with "0x", but that is rejected as to long.

I've tried format(), binaryEncode(), binaryDecode(), but I'm not doing something correctly.

If it cut the string in half, to 16 characters, encrypt works just fine, but that is not the Key that I need to use.

This seems very simple, but I cannot find it documented anywhere, but then I'm probably looking in the wrong place.

Thanks for the help.

Re: Hex String Definition

Posted: Tue Jul 15, 2014 4:12 am
by mwieder
Does

Code: Select all

put binaryEncode("H*", "C0FB7F4F840BBDC0F3FF1A2E0BA9E179")
give you what you want?

Re: Hex String Definition

Posted: Tue Jul 15, 2014 6:23 am
by dcpbarrington
Thanks

The binaryEncode gives the binary string and the encrypt function didn't complain.

I was thinking that I could put a indication at the start of the string to indicate that it was a Hex value without the conversion.

Thanks for the fast response. I will see how that works.

dcpbarrington

Re: Hex String Definition

Posted: Tue Jul 15, 2014 6:38 am
by mwieder
I was thinking that I could put a indication at the start of the string to indicate that it was a Hex value without the conversion.
You could, but I think with that many bits you might overflow the math library.

Re: Hex String Definition

Posted: Wed Jul 16, 2014 1:10 am
by dcpbarrington
Thanks for the reply

On the binaryEncode() function there are two HEX options.

h: encode amount groups of 2 characters as hexadecimal numbers
H: encode amount groups of 2 characters as hexadecimal, starting at the high end of each byte

Using the "H" value is the correct selection as you noted. Just to be sure I then verified that the bit stream was generated correctly by doing a get binaryDecode( "B*", tKeyHex, tKeyBinary)

Thanks for the help.
dcpbarrington