Dwords... more like FWords!
March 22, 2013 10:02 AM Subscribe
Need some help converting an array of C# DWords to a PHP String....
My programming partner and I have been handed a set of DWords from the land of dotnet that we're using to build a key. It looks little like this:
tkKey.push_back(0x789d6152);
tkKey.push_back(0x630fe221);
tkKey.push_back(0x789d6152);
tkKey.push_back(0x630fe221);
... we want to convert it to a string that ends up looking like:
\x8f\xb3M\x05,
... etc...
How do we do that? I've been looking at pack and unpack, just finding myself horribly confused....
My programming partner and I have been handed a set of DWords from the land of dotnet that we're using to build a key. It looks little like this:
tkKey.push_back(0x789d6152);
tkKey.push_back(0x630fe221);
tkKey.push_back(0x789d6152);
tkKey.push_back(0x630fe221);
... we want to convert it to a string that ends up looking like:
\x8f\xb3M\x05,
... etc...
How do we do that? I've been looking at pack and unpack, just finding myself horribly confused....
Response by poster: We're trying to port a bit of functionality from C# to PHP.... essentially, trying to generate an encryption key.
posted by ph00dz at 10:22 AM on March 22, 2013
posted by ph00dz at 10:22 AM on March 22, 2013
Best answer: If I'm reading your question right, pack is what you want. You can just use your dwords directly:
pack("V*", 0x789d6152, 0x630fe221, 0x789d6152, 0x630fe221)
And what you get is:
string(16) "Ra�x!cRa�x!c"
This string doesn't have the escapes in there like your example, but it's your data. Remember that when you pack little-endian data like this, your string is going to have each set of four bytes reversed. This is probably what you want, but if you want them the other way around, use "N*" instead of "V*".
posted by pocams at 10:50 AM on March 22, 2013
pack("V*", 0x789d6152, 0x630fe221, 0x789d6152, 0x630fe221)
And what you get is:
string(16) "Ra�x!cRa�x!c"
This string doesn't have the escapes in there like your example, but it's your data. Remember that when you pack little-endian data like this, your string is going to have each set of four bytes reversed. This is probably what you want, but if you want them the other way around, use "N*" instead of "V*".
posted by pocams at 10:50 AM on March 22, 2013
Response by poster: In case this comes up in anyone else's desperate search, here's something dumb to keep in mind: our array consists of dozens of those bytes. I had the values in quotes... you know... like one might expect. Don't do that... it won't work.
posted by ph00dz at 11:02 AM on March 23, 2013
posted by ph00dz at 11:02 AM on March 23, 2013
« Older Best site for conducting employee background... | Web site that recommends songs from movies? Newer »
This thread is closed to new comments.
posted by artlung at 10:19 AM on March 22, 2013