By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,491 Members | 3,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,491 IT Pros & Developers. It's quick & easy.

generate 20 byte int from GUID ?

P: n/a
Is it possible to generate a 20 byte integer from a GUID that is "unique
enough" ( just like a GUID is not truly unique , but is "unique enough" ).

We identify transactions with GUIDs , but a partner web service has a 20
byte limit on transaction ID passed.
Nov 17 '05 #1
Share this Question
Share on Google+
26 Replies


P: n/a
John Grandy wrote:
Is it possible to generate a 20 byte integer from a GUID that is "unique
enough" ( just like a GUID is not truly unique , but is "unique enough" ).

We identify transactions with GUIDs , but a partner web service has a 20
byte limit on transaction ID passed.


20 bytes = 160 bits. Most GUIDs are 128 bits, a 20 byte limit should be
more than enough to use a standard GUID.

--
Rob Schieber
Nov 17 '05 #2

P: n/a
The 3rd party's 20 byte representation of a TransactionID must be a string.
So each byte contains one character (ASCII coding). So although 20 bytes
are available, when converted to an integer this only corresponds to 20
nibbles or 10 bytes. So we need to convert a 32 nibble GUID to a 20 nibble
"psuedo-GUID".

"Rob Schieber" <sc******@hotmail.com> wrote in message
news:uG**************@TK2MSFTNGP12.phx.gbl...
John Grandy wrote:
Is it possible to generate a 20 byte integer from a GUID that is "unique
enough" ( just like a GUID is not truly unique , but is "unique
enough" ).

We identify transactions with GUIDs , but a partner web service has a 20
byte limit on transaction ID passed.


20 bytes = 160 bits. Most GUIDs are 128 bits, a 20 byte limit should be
more than enough to use a standard GUID.

--
Rob Schieber

Nov 17 '05 #3

P: n/a
John Grandy wrote:
The 3rd party's 20 byte representation of a TransactionID must be a string.
So each byte contains one character (ASCII coding). So although 20 bytes
are available, when converted to an integer this only corresponds to 20
nibbles or 10 bytes. So we need to convert a 32 nibble GUID to a 20 nibble
"psuedo-GUID".

"Rob Schieber" <sc******@hotmail.com> wrote in message
news:uG**************@TK2MSFTNGP12.phx.gbl...
John Grandy wrote:
Is it possible to generate a 20 byte integer from a GUID that is "unique
enough" ( just like a GUID is not truly unique , but is "unique
enough" ).

We identify transactions with GUIDs , but a partner web service has a 20
byte limit on transaction ID passed.


20 bytes = 160 bits. Most GUIDs are 128 bits, a 20 byte limit should be
more than enough to use a standard GUID.

--
Rob Schieber



Ah, ok I guess it all depends on how the GUIDS are created. I believe
GUIDs are generated using a combination of the Adapter Address and a
timestamp, that said, I doubt that uniqueness will be a problem if you
truncate a section of the GUID.

If you are really concerned you may want to look into generating your
own 20 nibble GUIDs according to criteria that will guarentee uniqueness.

--
Rob Schieber
Nov 17 '05 #4

P: n/a

"John Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:uT*************@tk2msftngp13.phx.gbl...
Is it possible to generate a 20 byte integer from a GUID that is "unique enough" ( just like a
GUID is not truly unique , but is "unique enough" ).

We identify transactions with GUIDs , but a partner web service has a 20 byte limit on transaction
ID passed.


Just figured I would ask the obvious.
Does the Transaction ID need to be numeric or can it be Alphanumeric?
I'm assuming numeric, because otherwise there is no problem.

Bill

Nov 17 '05 #5

P: n/a
<"John Grandy" <johnagrandy-at-yahoo-dot-com>> wrote:
The 3rd party's 20 byte representation of a TransactionID must be a string.
So each byte contains one character (ASCII coding). So although 20 bytes
are available, when converted to an integer this only corresponds to 20
nibbles or 10 bytes. So we need to convert a 32 nibble GUID to a 20 nibble
"psuedo-GUID".


Hang on though - you can get an awful lot more than one nybble in a
single ASCII character!

If you can use *any* ASCII character (including the ones which aren't
really in ASCII, but everyone talks about as if they are - bell,
carriage return, etc - the control characters, basically) then you
should only need to drop one bit per byte, giving you 20*7=140 bits,
which is still enough to hold a full GUID.

Otherwise, you could use Base64 to give you 6 bits per byte. That means
dropping one byte from the GUID, but that would probably still be good
enough, I suspect. It may be worth finding out how the GUIDs are
generated by default in .NET - there could be one byte which is better
to get rid of than others.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6

P: n/a
Problem is that the string must be URL encoded. The 3rd party can only
accept 20 chars *including* any potential extra chars created by URL
encoding.

So, to ensure never go over the 20 char limit, that only leaves 0-9, a-z ,
A-Z = 62 chars.

62 ^ 20 = 7.044 x 10^35

Not enough to hold a full GUID. So how to hash it down is the question.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<"John Grandy" <johnagrandy-at-yahoo-dot-com>> wrote:
The 3rd party's 20 byte representation of a TransactionID must be a
string.
So each byte contains one character (ASCII coding). So although 20 bytes
are available, when converted to an integer this only corresponds to 20
nibbles or 10 bytes. So we need to convert a 32 nibble GUID to a 20
nibble
"psuedo-GUID".


Hang on though - you can get an awful lot more than one nybble in a
single ASCII character!

If you can use *any* ASCII character (including the ones which aren't
really in ASCII, but everyone talks about as if they are - bell,
carriage return, etc - the control characters, basically) then you
should only need to drop one bit per byte, giving you 20*7=140 bits,
which is still enough to hold a full GUID.

Otherwise, you could use Base64 to give you 6 bits per byte. That means
dropping one byte from the GUID, but that would probably still be good
enough, I suspect. It may be worth finding out how the GUIDs are
generated by default in .NET - there could be one byte which is better
to get rid of than others.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 17 '05 #7

P: n/a
<"John Grandy" <johnagrandy-at-yahoo-dot-com>> wrote:
Problem is that the string must be URL encoded. The 3rd party can only
accept 20 chars *including* any potential extra chars created by URL
encoding.

So, to ensure never go over the 20 char limit, that only leaves 0-9, a-z ,
A-Z = 62 chars.


URL encoding shouldn't touch * and -, so replace the normal base 64
encoding with one which uses * instead of + and - instead of /, and you
end up with 64 characters. Not enough to hold a full GUID, but enough
to get 7 of the 8 bytes. Ditch one of the bytes, as I suggested, to get
120 useful bits.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #8

P: n/a
Where can I find information on how
Convert.ToBase64String(Guid.ToByteArray()) performs its magic?

Then I write a replacement function following your idea .... correct ?

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<"John Grandy" <johnagrandy-at-yahoo-dot-com>> wrote:
Problem is that the string must be URL encoded. The 3rd party can only
accept 20 chars *including* any potential extra chars created by URL
encoding.

So, to ensure never go over the 20 char limit, that only leaves 0-9, a-z
,
A-Z = 62 chars.


URL encoding shouldn't touch * and -, so replace the normal base 64
encoding with one which uses * instead of + and - instead of /, and you
end up with 64 characters. Not enough to hold a full GUID, but enough
to get 7 of the 8 bytes. Ditch one of the bytes, as I suggested, to get
120 useful bits.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 17 '05 #9

P: n/a
Hate to say this but what about just creating a table in your DB or where
ever your GUIDs are stored and point them to a IDENTITY column in SQL, or
the equivalent in the database you are using.

In SQL you could easily create a Stored Procedure that would accept the GUID
as a parameter and return you your "Transaction ID" to send to the other
provider. This way you also can easily look up the transaction ID for your
GUID if you needed to check status.

Just a thought.

Eric Renken
"Bill Butler" <qw****@asdf.com> wrote in message
news:kkg1f.979$la.138@trndny05...

"John Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:uT*************@tk2msftngp13.phx.gbl...
Is it possible to generate a 20 byte integer from a GUID that is "unique
enough" ( just like a GUID is not truly unique , but is "unique
enough" ).

We identify transactions with GUIDs , but a partner web service has a 20
byte limit on transaction ID passed.


Just figured I would ask the obvious.
Does the Transaction ID need to be numeric or can it be Alphanumeric?
I'm assuming numeric, because otherwise there is no problem.

Bill

Nov 17 '05 #10

P: n/a
<"John Grandy" <johnagrandy-at-yahoo-dot-com>> wrote:
Where can I find information on how
Convert.ToBase64String(Guid.ToByteArray()) performs its magic?

Then I write a replacement function following your idea .... correct ?


Well, an alternative would be to just call Convert.ToBase64, and then
call Replace on the result and trim it to 20 characters.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #11

P: n/a
> Where can I find information on how
Convert.ToBase64String(Guid.ToByteArray()) performs its magic?
in Rotor check out the \sscli\clr\src\vm\comutilnative.cpp line # 1973 to
see the magic. The Force is strong in there :-).

Ab.
http://joehacker.blogspot.com
"John Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:uR**************@TK2MSFTNGP10.phx.gbl... Where can I find information on how
Convert.ToBase64String(Guid.ToByteArray()) performs its magic?

Then I write a replacement function following your idea .... correct ?

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<"John Grandy" <johnagrandy-at-yahoo-dot-com>> wrote:
Problem is that the string must be URL encoded. The 3rd party can only
accept 20 chars *including* any potential extra chars created by URL
encoding.

So, to ensure never go over the 20 char limit, that only leaves 0-9, a-z ,
A-Z = 62 chars.


URL encoding shouldn't touch * and -, so replace the normal base 64
encoding with one which uses * instead of + and - instead of /, and you
end up with 64 characters. Not enough to hold a full GUID, but enough
to get 7 of the 8 bytes. Ditch one of the bytes, as I suggested, to get
120 useful bits.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Nov 17 '05 #12

P: n/a
That's exactly what I did.

But it looks like the loss of "uniqueness" is severe ...

loss of uniqueness = 1 - (64 ^ 20) / (2 ^ 128) = 1 - 0.00390625 = 99.61%

What I am wondering is if , in terms of uniqueness , there is any difference
between this method and randomly generating 20 base-64 chars ( using a
random generation technique at the same level of quality as the technique
used by the Guid.NewGuid() method )

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<"John Grandy" <johnagrandy-at-yahoo-dot-com>> wrote:
Where can I find information on how
Convert.ToBase64String(Guid.ToByteArray()) performs its magic?

Then I write a replacement function following your idea .... correct ?


Well, an alternative would be to just call Convert.ToBase64, and then
call Replace on the result and trim it to 20 characters.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 17 '05 #13

P: n/a
I did think of that. We do create our transaction IDs with a SQL IDENTITY
column , and keeping track of the mapping between our transaction IDs and
their transaction IDs is definitely a good idea (although I don't presently
see any need for it, it's better to be safe than sorry).

Since it's a deterministic relationship, I believe that you could even do it
as a computed column in a view.

The problem with adding another column (even a computed column) to the
Transactions table and then populating and retrieving that column's value at
the time of adding a record is that it would have a severe performance
impact in a web-farm scenario, would it not ? Seems better to calculate
their transaction id in the CLR.

Any thoughts anyone ?
"Eric Renken" <Er*********@newsgroup.nospam> wrote in message
news:Or**************@TK2MSFTNGP15.phx.gbl...
Hate to say this but what about just creating a table in your DB or where
ever your GUIDs are stored and point them to a IDENTITY column in SQL, or
the equivalent in the database you are using.

In SQL you could easily create a Stored Procedure that would accept the
GUID as a parameter and return you your "Transaction ID" to send to the
other provider. This way you also can easily look up the transaction ID
for your GUID if you needed to check status.

Just a thought.

Eric Renken
"Bill Butler" <qw****@asdf.com> wrote in message
news:kkg1f.979$la.138@trndny05...

"John Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:uT*************@tk2msftngp13.phx.gbl...
Is it possible to generate a 20 byte integer from a GUID that is "unique
enough" ( just like a GUID is not truly unique , but is "unique
enough" ).

We identify transactions with GUIDs , but a partner web service has a 20
byte limit on transaction ID passed.


Just figured I would ask the obvious.
Does the Transaction ID need to be numeric or can it be Alphanumeric?
I'm assuming numeric, because otherwise there is no problem.

Bill


Nov 17 '05 #14

P: n/a
Could you explain a little bit more? What is Rotor ?

"Abubakar" <ab*******@gmail.com> wrote in message
news:Om**************@TK2MSFTNGP10.phx.gbl...
Where can I find information on how
Convert.ToBase64String(Guid.ToByteArray()) performs its magic?


in Rotor check out the \sscli\clr\src\vm\comutilnative.cpp line # 1973 to
see the magic. The Force is strong in there :-).

Ab.
http://joehacker.blogspot.com
"John Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:uR**************@TK2MSFTNGP10.phx.gbl...
Where can I find information on how
Convert.ToBase64String(Guid.ToByteArray()) performs its magic?

Then I write a replacement function following your idea .... correct ?

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
> <"John Grandy" <johnagrandy-at-yahoo-dot-com>> wrote:
>> Problem is that the string must be URL encoded. The 3rd party can
>> only
>> accept 20 chars *including* any potential extra chars created by URL
>> encoding.
>>
>> So, to ensure never go over the 20 char limit, that only leaves 0-9, a-z >> ,
>> A-Z = 62 chars.
>
> URL encoding shouldn't touch * and -, so replace the normal base 64
> encoding with one which uses * instead of + and - instead of /, and you
> end up with 64 characters. Not enough to hold a full GUID, but enough
> to get 7 of the 8 bytes. Ditch one of the bytes, as I suggested, to get
> 120 useful bits.
>
> --
> Jon Skeet - <sk***@pobox.com>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too



Nov 17 '05 #15

P: n/a
John,
Could you explain a little bit more? What is Rotor ?


Rotor is another name for Microosft's Shared-source CLI
implementation.

http://msdn.microsoft.com/net/sscli/
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #16

P: n/a
<"John A Grandy" <johnagrandy-at-yahoo-dot-com>> wrote:
That's exactly what I did.

But it looks like the loss of "uniqueness" is severe ...

loss of uniqueness = 1 - (64 ^ 20) / (2 ^ 128) = 1 - 0.00390625 = 99.61%

What I am wondering is if , in terms of uniqueness , there is any difference
between this method and randomly generating 20 base-64 chars ( using a
random generation technique at the same level of quality as the technique
used by the Guid.NewGuid() method )


Well, the difficulty is getting the same level of quality. If you take
120 bits of the GUID, you do indeed lose out by a factor of 256 - but
there's still 2^120 possibilities, which is still a vast number!

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #17

P: n/a
Oh man, I'm terrible at cpp. Is the code for Guid creation available in c#
anywhere ?

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:ek*************@tk2msftngp13.phx.gbl...
John,
Could you explain a little bit more? What is Rotor ?


Rotor is another name for Microosft's Shared-source CLI
implementation.

http://msdn.microsoft.com/net/sscli/
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 17 '05 #18

P: n/a
I looked the at mono (open source .net for almost all platforms!) sources
and this is what I found:

--------------------
inside the inside the \mcs\class\corlib\System\Convert.cs :

public static string ToBase64String (byte[] inArray)
{
if (inArray == null)
throw new ArgumentNullException ("inArray");

return ToBase64String (inArray, 0, inArray.Length);
}

public static string ToBase64String (byte[] inArray, int offset, int length)
{
if (inArray == null)
throw new ArgumentNullException ("inArray");
if (offset < 0 || length < 0)
throw new ArgumentOutOfRangeException ("offset < 0 || length < 0");
// avoid integer overflow
if (offset > inArray.Length - length)
throw new ArgumentOutOfRangeException ("offset + length > array.Length");

// note: normally ToBase64Transform doesn't support multiple block
processing
byte[] outArr = toBase64Transform.InternalTransformFinalBlock (inArray,
offset, length);

return (new ASCIIEncoding ().GetString (outArr));
}

inside the
\mcs\class\corlib\System.Security.Cryptography\ToB ase64Transform.cs:

// Mono System.Convert depends on the ability to process multiple blocks
internal byte[] InternalTransformFinalBlock (byte[] inputBuffer, int
inputOffset, int inputCount)
{
int blockLen = this.InputBlockSize;
int outLen = this.OutputBlockSize;
int fullBlocks = inputCount / blockLen;
int tail = inputCount % blockLen;

byte[] res = new byte [(inputCount != 0)
? ((inputCount + 2) / blockLen) * outLen
: 0];

int outputOffset = 0;

for (int i = 0; i < fullBlocks; i++) {

TransformBlock (inputBuffer, inputOffset,
blockLen, res, outputOffset);

inputOffset += blockLen;
outputOffset += outLen;
}

byte[] lookup = Base64Constants.EncodeTable;
int b1,b2;

// When fewer than 24 input bits are available
// in an input group, zero bits are added
// (on the right) to form an integral number of
// 6-bit groups.
switch (tail) {
case 0:
break;
case 1:
b1 = inputBuffer [inputOffset];
res [outputOffset] = lookup [b1 >> 2];
res [outputOffset+1] = lookup [(b1 << 4) & 0x30];

// padding
res [outputOffset+2] = (byte)'=';
res [outputOffset+3] = (byte)'=';
break;

case 2:
b1 = inputBuffer [inputOffset];
b2 = inputBuffer [inputOffset + 1];
res [outputOffset] = lookup [b1 >> 2];
res [outputOffset+1] = lookup [((b1 << 4) & 0x30) | (b2 >> 4)];
res [outputOffset+2] = lookup [(b2 << 2) & 0x3c];

// one-byte padding
res [outputOffset+3] = (byte)'=';
break;
}

return res;
}
--------------------
from mono-1.1.9.1.

Ab.
http://joehacker.blogspot.com
"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:OI**************@TK2MSFTNGP12.phx.gbl...
Oh man, I'm terrible at cpp. Is the code for Guid creation available in c# anywhere ?

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:ek*************@tk2msftngp13.phx.gbl...
John,
Could you explain a little bit more? What is Rotor ?


Rotor is another name for Microosft's Shared-source CLI
implementation.

http://msdn.microsoft.com/net/sscli/
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Nov 17 '05 #19

P: n/a
Abubakar <ab*******@gmail.com> wrote:
I looked the at mono (open source .net for almost all platforms!) sources
and this is what I found:


Well, that shows Base64 conversion, but it doesn't show GUID creation
as far as I can see.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #20

P: n/a
I'm not sure a full understanding of Guid creation would help my problem.
(Apparently, MAC IDs and a host of other system-specific characteristics are
used, and with enough randomly generated bits (Guid has 128), something
approaching randomness for any practical purpose is achieved.)

The (huge) problem I'm running into is how to "split bit boundaries of
randomness".

What am I talking about ?

Well, for example, if I require that my GUID string be built utilizing a set
of 52 chars (e.g. a-z A-Z), then I need 6 random bits to cover the target
range (e.g. 0-63 covers 0-51).

RNGCryptoServiceProvider.GetBytes() will generate me as many random bits as
I want.

However, on each occasion that 6 contiguous bits in the sequence represent a
value > 51 , it spells trouble. If I translate values > 51 back into the
required 0-51 range (e.g. via mod52), I effectively double the probability
of occurrence for each of 12 distinct values within that range (e.g. 0-11).

Any other translation scheme has the same problem.

It would seem that .NET's libs would provide some base functions that would
allow generation of cryptographically strong randomness within numeric
ranges that are not powers of 2.

Anyone know how to do this ?
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Abubakar <ab*******@gmail.com> wrote:
I looked the at mono (open source .net for almost all platforms!) sources
and this is what I found:


Well, that shows Base64 conversion, but it doesn't show GUID creation
as far as I can see.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 17 '05 #21

P: n/a
yea I know, actually he wrote:
Where can I find information on how
Convert.ToBase64String(Guid.ToByteArray()) performs its magic?
so I just looked at the source of ToBase64String and pasted over here. Guide
could be got from the same sources.
The GUID source code is in \mcs\class\corlib\System\Guid.cs.

Ab.
http://joehacker.blogspot.com

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Abubakar <ab*******@gmail.com> wrote:
I looked the at mono (open source .net for almost all platforms!) sources and this is what I found:


Well, that shows Base64 conversion, but it doesn't show GUID creation
as far as I can see.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 17 '05 #22

P: n/a
<"John Grandy" <johnagrandy-at-yahoo-dot-com>> wrote:
I'm not sure a full understanding of Guid creation would help my problem.
(Apparently, MAC IDs and a host of other system-specific characteristics are
used, and with enough randomly generated bits (Guid has 128), something
approaching randomness for any practical purpose is achieved.)

The (huge) problem I'm running into is how to "split bit boundaries of
randomness".

What am I talking about ?

Well, for example, if I require that my GUID string be built utilizing a set
of 52 chars (e.g. a-z A-Z), then I need 6 random bits to cover the target
range (e.g. 0-63 covers 0-51).


But I thought you said that you just needed to be able to URL-encode
the character data without making it bigger. In that case, you should
be able to use a-z, A-Z, 0-9, *, - and = for base64 encoding. Just
convert the bytes to a base64 string using the .NET conversions, then
replace + with - and / with *. That will exactly cover the range.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #23

P: n/a
Right. I wrote that code a long time ago. Problem solved.

But that's just one of many problems. Some strings must be A-Z a-z only.
Some can also include 0-9.

I was looking at Adobe's ASCIIArmor. But that's for an 85 char set, and
seems to have some peculiarities.

Apparently, flexible solutions in this area don't exist. Probably for
advanced mathematical reasons.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<"John Grandy" <johnagrandy-at-yahoo-dot-com>> wrote:
I'm not sure a full understanding of Guid creation would help my problem.
(Apparently, MAC IDs and a host of other system-specific characteristics
are
used, and with enough randomly generated bits (Guid has 128), something
approaching randomness for any practical purpose is achieved.)

The (huge) problem I'm running into is how to "split bit boundaries of
randomness".

What am I talking about ?

Well, for example, if I require that my GUID string be built utilizing a
set
of 52 chars (e.g. a-z A-Z), then I need 6 random bits to cover the target
range (e.g. 0-63 covers 0-51).


But I thought you said that you just needed to be able to URL-encode
the character data without making it bigger. In that case, you should
be able to use a-z, A-Z, 0-9, *, - and = for base64 encoding. Just
convert the bytes to a base64 string using the .NET conversions, then
replace + with - and / with *. That will exactly cover the range.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 17 '05 #24

P: n/a
<"John A Grandy" <johnagrandy-at-yahoo-dot-com>> wrote:
Right. I wrote that code a long time ago. Problem solved.

But that's just one of many problems. Some strings must be A-Z a-z only.
Some can also include 0-9.

I was looking at Adobe's ASCIIArmor. But that's for an 85 char set, and
seems to have some peculiarities.

Apparently, flexible solutions in this area don't exist. Probably for
advanced mathematical reasons.


Well, different problems require different approaches. I was focusing
on the problem you originally asked about, which didn't specify that it
could only be A-Z a-z.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #25

P: n/a
Do you know if Microsoft implementated Guid as one of the versions of UUID ,
as specified in this doc :

http://www.webdav.org/specs/draft-le...s-guids-01.txt
"Abubakar" <ab*******@gmail.com> wrote in message
news:eQ**************@TK2MSFTNGP12.phx.gbl...
yea I know, actually he wrote:
Where can I find information on how
Convert.ToBase64String(Guid.ToByteArray()) performs its magic?


so I just looked at the source of ToBase64String and pasted over here.
Guide
could be got from the same sources.
The GUID source code is in \mcs\class\corlib\System\Guid.cs.

Ab.
http://joehacker.blogspot.com

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Abubakar <ab*******@gmail.com> wrote:
> I looked the at mono (open source .net for almost all platforms!) sources > and this is what I found:


Well, that shows Base64 conversion, but it doesn't show GUID creation
as far as I can see.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Nov 17 '05 #26

P: n/a
<"John A Grandy" <johnagrandy-at-yahoo-dot-com>> wrote:
Do you know if Microsoft implementated Guid as one of the versions of UUID ,
as specified in this doc :

http://www.webdav.org/specs/draft-le...s-guids-01.txt


I'm afraid I don't. However, looking at the way it's formatted, it
would certainly *suggest* that it's one of those versions, yes.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #27

This discussion thread is closed

Replies have been disabled for this discussion.