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
  • 665,005
  • 155
  • 1,345
  • 1,328
bentech
  • 1,186
  • 14
  • 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,095
  • 5
  • 53
  • 101
0

Try using Boost Variant library.

yasouser
  • 4,991
  • 2
  • 26
  • 39