Hex String Definition

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Hex String Definition

Post by dcpbarrington » Tue Jul 15, 2014 3:55 am

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.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Hex String Definition

Post by mwieder » Tue Jul 15, 2014 4:12 am

Does

Code: Select all

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

dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Re: Hex String Definition

Post by dcpbarrington » Tue Jul 15, 2014 6:23 am

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Hex String Definition

Post by mwieder » Tue Jul 15, 2014 6:38 am

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.

dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Re: Hex String Definition

Post by dcpbarrington » Wed Jul 16, 2014 1:10 am

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

Post Reply