generate 20 byte int from GUID ?

  • Thread starter Thread starter John Grandy
  • Start date Start date
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 ?
 
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.
 
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.
 
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.
 
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-leach-uuids-guids-01.txt


Abubakar said:
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
 
Back
Top