0

I am getting

Warning: pack(): 1 arguments unused in

 $vector = pack("H*",0x77,0x99); 




 $vector = pack("H*","4A","76");  // with quotes also give same warning

but if i use only one value there is no Warning

 $vector = pack("H*",0x77); 

Do anybody know about this warning ?

what value should i pass to pack . is it should be hex?

zod
  • 12,092
  • 24
  • 70
  • 106

1 Answers1

2

You should pass it hexadecimals in a string, like so:

$vector = pack("H*", "7799");

If you use 0x77 you already have a numeric value with the value 77h, i.e. the compiler will transform the value from hexadecimals to binary - there is no need to use pack on it.

If you really want to use the 0x77,0x99 notation, then put the notation in quotes and use the following:

$hex="0x77,0x99";
preg_match_all("/0x([0-9A-F]{2})/i", $hex, $out);
$data = pack("H*", join($out[1]));
Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
  • Thanks . But Even if i try to give two values in quote , i am getting same warning . did you try two or more values ? Actually i have to convert a ,net script to php . in .net they pass 0x4A in byte array. so in php what should i pass? – zod Aug 29 '14 at 14:53
  • You could pass simply a "character array" consisting of `"\xHH\xHH"` where H is a hexadecimal character. You could of course with the scheme I've put above, and simply concatenate the hexadecimals. I used to simply use regular expressions to convert byte arrays to another. As cryptographer, I finally had enough and now have a tool called "Octational" that converts between any form of bytes. Unfortunately I created that while on the job, so officially it's not mine to share. – Maarten Bodewes Aug 29 '14 at 18:27
  • oh man... thanks for info... but did you mean this ..or something else.. just give one example .. $vector= pack('H*',"\x04\x09"); – zod Aug 29 '14 at 19:57
  • i have the issue only with h , c format works.. what is the importance of format.. .. can you please add that in answer.. is the format is for input or output ?? – zod Aug 29 '14 at 19:59
  • You don't need to pack those, that's already a byte array. But check the edited answer, you should be able to directly copy the C format in the quotes. – Maarten Bodewes Aug 29 '14 at 20:28
  • Any progress on this, zod? Try and read a bit into how PHP handles bye arrays, characters and the like. – Maarten Bodewes Aug 30 '14 at 20:12
  • Hey owlstead , ultimately i am trying achieve the same thing you answered here .. am trying to create that same byte array. do i need to do that or just use the output string ? http://stackoverflow.com/questions/9011635/how-do-i-convert-this-c-sharp-rijndael-encryption-to-php – zod Sep 02 '14 at 16:20