I need to make a string representation of a 128bit GUID that represents 8bit chunks instead of 4bit; so like base 256 :/ Why? Because I need to shorten the length of the string hex representation of the GUID, it is too long. I have a max array size of 31 plus NULL terminator. Also the character value cannot be from 0x000 to 0x01F.... It's giving me a headache but I know it can be done. Any suggestions on the best and safest way how? Right now I'm just mucking around with memcpy and adding 0x01F but the numbers keep bouncing around in my head.... can't nail 'em down no! And I have to interconvert :\
+2
A:
Try base64 encoding : it packs 6-bits per character and is still portable. You will need 22 chars to store 128 bits GUID in a portable way.
Peter Tillemans
2010-06-22 09:19:50
This will make a difference somewhere? 8-bits is too much(not portable)? Suggestions on how to properly handle the conversion? I avoided the word encoding because it kind of is like the opposite o~o
PrettyFlower
2010-06-22 09:24:08
You need the 0 to get the 8-bit which conflicts with the C++ end of string sentinel value, so you end up with a byte array. If you want to keep using strings you must also be careful they are not translated when using different code pages. Also your requirements state no combinations in 00-1F are not to be used. Base64 is about as good as it gets within these constraints.
Peter Tillemans
2010-06-22 09:36:58
"...you must also be careful they are not translated when using different code pages..." - you ~ but this is only really relevant if someone is trying to read and copy the damn thing over visually or did I miss something in the class I never attended? I don't think anyone will be reading the encrypted file .... most likely! I am a little concerned with sudden changes of bit/byte order pending computer and compile of the code that I'm writting to do the converting. o.o
PrettyFlower
2010-06-22 09:47:16
In the end it's a matter of simplicity. Base64 code is all over the net, and too trivial to copyright. It's also sufficient for your purpose (22 characters output). What's the benefit of a more complex solution?
MSalters
2010-06-22 14:06:37
Ah yes forgive my ignorance of already established practices.... I guess I'll go with converting Hex to base64 what would seem to be the most common character set.... Thank you MSalters!
PrettyFlower
2010-06-22 18:29:46
and thank you also Peter...
PrettyFlower
2010-06-22 18:46:27
A:
Having that OLESTR first convert it into a GUID with IIDFromString(), then use base64 as user Peter Tillemans suggests.
sharptooth
2010-06-22 09:37:32
Ok ... I take it I'm adding the '\0' to make it 132bits as 6x22 is well 132 not 128 and that is what he meant by "You need the 0 to get the 8-bit which conflicts with the C++ end of string sentinel value, so you end up with a byte array." I also take it I'm going to be copying bit by bit where in which case I would just copy it to the upper six bits of the lower byte? So as to take care of the character offset....
PrettyFlower
2010-06-22 10:21:56