0
$x = pack("N", $num1).pack("N", $num2).$data;

I am trying to do it with

 union unionchal {
  struct ast{
   unsigned long a;
   unsigned long b;
   char c[8];
  } chal;
  unsigned char response[16];
 };

ast being the input and response being the output

It is meant to output yp¶ ‚¬þÖHpö€ì_± but gives ¶pyßêÈ)ÖHpöì_

I think it's got something to do with it being big endian byte order

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
bentech
  • 1,226
  • 15
  • 19

3 Answers3

1

I think it's got something to do with it being big endian byte order

I also think so. You may use htonl() for example, to change the byte order on little-endian machines, or write your own byte-swapping function (but then you'll have to test yourself what the byte order of the host machine is).

Achille
  • 111
  • 2
1

Try using htonl on your integers before placing them into the structure. It will convert them into big-endian order. If you need 64-bit longs, see the discussion about it on SE.

Community
  • 1
  • 1
StasM
  • 10,593
  • 6
  • 56
  • 103
0

Try using Boost Variant library.

yasouser
  • 5,113
  • 2
  • 27
  • 41