More on UUID

Wrote a lot of code at work today so needed a bit of a break. Not much coding then tonight.

But–even tired, I was wondering about UUID and some code I did not understand. Please see the previous UUID post for more of the code. Here is the code that got my mind spinning:

boost::uuids::name_generator_sha1 mygen(boost::uuids::ns::dns());
boost::uuids::uuid udoc = mygen("To Be or not to be");
std::cout << "boost.org uuid in dns namespace, sha1 version: " << udoc << std::endl;
boost::uuids::name_generator_sha1 moregen(uuid2);
boost::uuids::uuid udoc2 = moregen("To Be or not to be");
std::cout << "boost.org uuid in random, sha1 version: " << udoc2 << std::endl;
boost::uuids::uuid udoc3 = moregen("To Be or not to be");
std::cout << "boost.org uuid in random, sha1 version: " << udoc3 << std::endl;

This code starts with defining the mygen function with a base value. It then uses a string to be the base to be turned into a UUID. A hashing of sorts. What I did not understand was that the definition defined a unique evaluation and this would create the same value for the same string. I also did not know that a different starting value would allow for a different value but always again the same value.

The execution of the code looks like this:

boost.org uuid in dns namespace, sha1 version: 49826646-175a-5fd8-9712-97f89d1e1ce3
boost.org uuid in random, sha1 version: 75255484-63d0-5332-addf-0bc4e551507c
boost.org uuid in random, sha1 version: 75255484-63d0-5332-addf-0bc4e551507c

This allows for me to create a cheap and easy proof-of-work (POW). I could pick a random UUID and share it between two implementations of the software. Each could then generate the same value, as long as they used sha1, for a given string like a random UUID. I could avoid cryptological code a bit longer. So UUIDs appear worthy of investing some code in.

I am thinking about storing some values in a table and also to compile in some values for UUID values. Specifically, I am thinking of an XML config table using the tree routines I covered in a previous post. I could including some shared UUID values. I was thinking of sharing ten values for a network​ of ten implementations with each one assigned a number. Number 0 would be a sort of master. Then I would also compile one value in for start-up and for crashes.

This was worth a second look.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s