[PHP] [SOVLED - ISH] Re: [PHP] pack it in
thanks to everyone for there info/feedback/help/etc - I have a somewhat better understanding of this pack/unpack/binary stuff now :-) Jochem Maas schreef: someone asked about checksum values in another thread, I believe he got his answer no thanks to me. but whilst I was trying to help I got stuck playing with pack/unpack. so now I have the broadbrush question of what would one use pack/unpack for? can anyone point at some realworld examples/code that might help me broaden my horizons? rds, jochem [ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pack it in
2008. 01. 25, péntek keltezéssel 00.20-kor Jochem Maas ezt írta: someone asked about checksum values in another thread, I believe he got his answer no thanks to me. but whilst I was trying to help I got stuck playing with pack/unpack. so now I have the broadbrush question of what would one use pack/unpack for? can anyone point at some realworld examples/code that might help me broaden my horizons? I have used pack in my password decrypt function: function encode_pwd($text) { $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM); return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5('secret key goes here'), $text, MCRYPT_MODE_ECB, $iv )); } function decode_pwd($encrypted_text) { $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM); return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5('secret key goes here'), pack(H*, $encrypted_text), MCRYPT_MODE_ECB, $iv )); } greets Zoltán Németh rds, jochem -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pack it in
one of the little imps in my head just found the light switch. thank you :-) Nathan Nobbe schreef: On Jan 24, 2008 7:13 PM, Jochem Maas [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: ok. that's where my brain goes to mush - all strings in php (for now) are binary ... what's the difference between the binary strings in php and such found in these 'binary files' that they need to be packed/unpacked? sorry if I'm sounding retarded ... I probably am :-/ pack() allows you to format binary data. it can be formatted for specific architectures as well. formating of php stings does not take place on a binary level, rather it occurs on a byte level, or multibyte using the multibyte string functions http://www.php.net/manual/en/ref.mbstring.php http://www.php.net/manual/en/ref.mbstring.php here is a nice example i found from phpdig.net http://phpdig.net, that is designed to determine whether a system is little, big, or middle endian. (there is a small error on the script at the actual website; ive modified it for the post here and sent a notice to the site regarding it). id like to see how this could be done w/ regular php strings :) ?php # A hex number that may represent 'abyz' $abyz = 0x6162797A; # Convert $abyz to a binary string containing 32 bits # Do the conversion the way that the system architecture wants to switch (pack ('L', $abyz)) { # Compare the value to the same value converted in a Little-Endian fashion case pack ('V', $abyz): echo 'Your system is Little-Endian.'; break; # Compare the value to the same value converted in a Big-Endian fashion case pack ('N', $abyz): echo 'Your system is Big-Endian.'; break; default: $endian = Your system 'endian' is unknown. . It may be some perverse Middle-Endian architecture.; } ? -nathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pack it in
On Jan 24, 2008 7:13 PM, Jochem Maas [EMAIL PROTECTED] wrote: Richard Lynch schreef: On Thu, January 24, 2008 5:20 pm, Jochem Maas wrote: someone asked about checksum values in another thread, I believe he got his answer no thanks to me. but whilst I was trying to help I got stuck playing with pack/unpack. so now I have the broadbrush question of what would one use pack/unpack for? can anyone point at some realworld examples/code that might help me broaden my horizons? Reading a binary file with various bytes/bits that need to get converted to integers for you to do something useful with them. ok. that's where my brain goes to mush - all strings in php (for now) are binary ... what's the difference between the binary strings in php and such found in these 'binary files' that they need to be packed/unpacked? sorry if I'm sounding retarded ... I probably am :-/ Ditty for writing said file. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I took over a project that used XOR encryption on these jpeg files and re-wrote them with custom headers. So I had to learn all about converting binary to hex. I needed a way to find specific values within the file of where the header stopped and where the data began. Using pack() was a key part of getting my modified hex values back into binary when I was writing values into the file. So tools of the trade: bin2hex(), ord(), pack('H*'), sprintf('%02x'). Here is a simple way to write hex to binary: pack('H*', sprintf('%02x', $hex)); Here is a simple XOR example: ?php echo 'pre'; $string = 'My unencrypted string'; $salt = Ya Harr; $len= strlen($string); $saltLen= strlen($salt); $index = 0; $encrypted = array(); echo Encrypting:\n; for ($x=0; $x $len; ++$x) { $char = $string{$x}; $xor = ord($salt{ $index % $saltLen }); $enc = (ord($char) ^ $xor); ++$index; $encrypted[] = $enc; echo sprintf(char: %s enc: %d xor: %d \n, $char, $enc, $xor); } echo Decrypting:\n; $index = 0; foreach ($encrypted as $enc) { $xor = ord($salt{$index % $saltLen}); ++$index; $char = $xor ^ $enc; echo sprintf(char %c enc: %d xor: %d \n, $char, $char, $enc, $xor); } ? Of course one should know that xor encryption really isn't encryption. It is basically just reversing the file so it is more of an obfuscation method. I'm sure there are better ways of achieving the desired output, but this is what I found out in the time I was given. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pack it in
On Thu, January 24, 2008 6:13 pm, Jochem Maas wrote: Richard Lynch schreef: On Thu, January 24, 2008 5:20 pm, Jochem Maas wrote: someone asked about checksum values in another thread, I believe he got his answer no thanks to me. but whilst I was trying to help I got stuck playing with pack/unpack. so now I have the broadbrush question of what would one use pack/unpack for? can anyone point at some realworld examples/code that might help me broaden my horizons? Reading a binary file with various bytes/bits that need to get converted to integers for you to do something useful with them. ok. that's where my brain goes to mush - all strings in php (for now) are binary ... what's the difference between the binary strings in php and such found in these 'binary files' that they need to be packed/unpacked? sorry if I'm sounding retarded ... I probably am :-/ If you read a binary file with a bunch of (integer) values in it, you get a big long string that looks like symbol-soup when you print it, because it's a big fit binary string. You'd like to break that up into, say, the actual integers and bytes that were intended. The bytes that were intended may or may not be in big-endian or little-endian format, for that matter... Anyway, unpack is one way to tear the string apart into the formatted data. -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pack it in
On Fri, January 25, 2008 7:14 am, Eric Butera wrote: Of course one should know that xor encryption really isn't encryption. It is according to the DCMA, last I heard, based on the QueCat and the barcode-scanner hack for same... :-) (I still have a QueCat kicking around somewhere that I want to hack some day...) -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] pack it in
someone asked about checksum values in another thread, I believe he got his answer no thanks to me. but whilst I was trying to help I got stuck playing with pack/unpack. so now I have the broadbrush question of what would one use pack/unpack for? can anyone point at some realworld examples/code that might help me broaden my horizons? rds, jochem -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pack it in
On Jan 24, 2008 6:20 PM, Jochem Maas [EMAIL PROTECTED] wrote: someone asked about checksum values in another thread, I believe he got his answer no thanks to me. but whilst I was trying to help I got stuck playing with pack/unpack. so now I have the broadbrush question of what would one use pack/unpack for? can anyone point at some realworld examples/code that might help me broaden my horizons? here is an awesome one. so for ldap, you have to ensure data meets a specific 'format' for all the different 'syntax'es it supports. these are each represented by a particular syntax oid, and the syntax is written in backus noir form. i wish i could say its reasonable to cipher out the syntax of those things, but then id be lying; at least for me, i struggle .. =/ anyways; for the password field, you have to supply ldap an appropriate syntax. the field has this syntax oid 1.3.6.1.4.1.1466.115.121.1.40 which is described as an Octet String. in order to get a password into ldap, i had to use the following $attrs['userPassword'] = '{MD5}' . base64_encode(pack('H*', $userPassword)); per this article: http://logout.sh/computers/ldap/ -nathan
Re: [PHP] pack it in
On Thu, January 24, 2008 5:20 pm, Jochem Maas wrote: someone asked about checksum values in another thread, I believe he got his answer no thanks to me. but whilst I was trying to help I got stuck playing with pack/unpack. so now I have the broadbrush question of what would one use pack/unpack for? can anyone point at some realworld examples/code that might help me broaden my horizons? Reading a binary file with various bytes/bits that need to get converted to integers for you to do something useful with them. Ditty for writing said file. -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pack it in
Richard Lynch schreef: On Thu, January 24, 2008 5:20 pm, Jochem Maas wrote: someone asked about checksum values in another thread, I believe he got his answer no thanks to me. but whilst I was trying to help I got stuck playing with pack/unpack. so now I have the broadbrush question of what would one use pack/unpack for? can anyone point at some realworld examples/code that might help me broaden my horizons? Reading a binary file with various bytes/bits that need to get converted to integers for you to do something useful with them. ok. that's where my brain goes to mush - all strings in php (for now) are binary ... what's the difference between the binary strings in php and such found in these 'binary files' that they need to be packed/unpacked? sorry if I'm sounding retarded ... I probably am :-/ Ditty for writing said file. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pack it in
On Jan 24, 2008 7:13 PM, Jochem Maas [EMAIL PROTECTED] wrote: ok. that's where my brain goes to mush - all strings in php (for now) are binary ... what's the difference between the binary strings in php and such found in these 'binary files' that they need to be packed/unpacked? sorry if I'm sounding retarded ... I probably am :-/ pack() allows you to format binary data. it can be formatted for specific architectures as well. formating of php stings does not take place on a binary level, rather it occurs on a byte level, or multibyte using the multibyte string functions http://www.php.net/manual/en/ref.mbstring.php here is a nice example i found from phpdig.net, that is designed to determine whether a system is little, big, or middle endian. (there is a small error on the script at the actual website; ive modified it for the post here and sent a notice to the site regarding it). id like to see how this could be done w/ regular php strings :) ?php # A hex number that may represent 'abyz' $abyz = 0x6162797A; # Convert $abyz to a binary string containing 32 bits # Do the conversion the way that the system architecture wants to switch (pack ('L', $abyz)) { # Compare the value to the same value converted in a Little-Endian fashion case pack ('V', $abyz): echo 'Your system is Little-Endian.'; break; # Compare the value to the same value converted in a Big-Endian fashion case pack ('N', $abyz): echo 'Your system is Big-Endian.'; break; default: $endian = Your system 'endian' is unknown. . It may be some perverse Middle-Endian architecture.; } ? -nathan
Re: [PHP] Font size of text that will be written using php pack function
rdpweb wrote: Hi All I am just converting the data from database to excel format.For that i am using pack function of php . But i want some data to be in bold like Employee Name = ABC http://pear.php.net/package/Spreadsheet_Excel_Writer It has support for doing this. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Font size of text that will be written using php pack function
Hi All I am just converting the data from database to excel format.For that i am using pack function of php . But i want some data to be in bold like Employee Name = ABC How to do that .Will anybody help me -- View this message in context: http://www.nabble.com/Font-size-of-text-that-will-be-written-using-php-pack-function-tf4493862.html#a12816141 Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Pack function in C#
Symbian wrote: hello, Our PHP dev (who has since left) uses the pack function to turn a base64 string into a binary blob (?): $blob = pack(H*, $postBase64Data); Does anyone know what the above is doing? Doesn't the manual tell you: http://www.php.net/manual/en/function.pack.php /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Pack function in C#
hello, Our PHP dev (who has since left) uses the pack function to turn a base64 string into a binary blob (?): $blob = pack(H*, $postBase64Data); Does anyone know what the above is doing? I need to translate that to C# terms, which I thought was getting the eqivalent of the bytes: byte[] blob = ASCIIEncoding.UTF8.GetBytes(postedData); But this may not be right. Sym -- View this message in context: http://www.nabble.com/Pack-function-in-C--tf4407990.html#a12575709 Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pack vs. serialize
Nathan Nobbe wrote: all, i have recently stumbled upon the packhttp://www.php.net/manual/en/function.pack.phpmethod. can this be used as a substitute for serializehttp://www.php.net/manual/en/function.serialize.php ? No. pack() is for creating binary representations of data, while serialize() returns a text representation of a PHP sitructure, (for objects the class must be loaded before you unserialize it). -- Richard Heyes 0844 801 1072 http://www.websupportsolutions.co.uk Knowledge Base and HelpDesk software -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] pack vs. serialize
all, i have recently stumbled upon the packhttp://www.php.net/manual/en/function.pack.phpmethod. can this be used as a substitute for serializehttp://www.php.net/manual/en/function.serialize.php ? if so, is there any rationalization for this; like would it perhaps create a more compact representation of the data or run more quickly? it looks like pack cannot be used on object as i didnt see object in the format listing; what would be a typical application of the pack method? thanks, -nathan
[PHP] pack, unpack and little endian double values
Hello I am trying to parse ESRI shape files, which have double values stored in little endian format. when i read these values using something like this: $RawFileHeader = fread($ShapeFile, 100); $FileHeader = unpack(NFileCode/N5Unused/NFileLength/VVersion/VShapeType/d8Box, $RawFileHeader); the double values seem garbled. Is there any way to force unpack() to read the doubles as little endians and convert the value accordingly? Thanks. Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] pack problem
Hi I am having some problems with the 'pack' function. Some values just doesnt come out right. For instance, 0xa0 turns into x81a0. Here is some code I used for testing. It packs the value, prints it. Then unpacks the value and prints it # This is wrong, but note that unpack gives the correct value! $v = 0xa0; $x = pack (n, $v); echo $x . ***; # 33184 (0x0081a0) $y = unpack (nfoo, $x); echo $y[foo] . **; # 160 (0xa0) # These guys are ok $v = 0x9; $x = pack (n, $v); echo $x . ***; # 9 (0x0009) $y = unpack (nfoo, $x); echo $y[foo] . **; # 9 (0x0009) $v = 0x100; $x = pack (n, $v); echo $x . ***; # 256 (0x0100) $y = unpack (nfoo, $x); echo $y[foo] . **; # 256 (0x0100) Any ideas? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php