Hash with SHA-1 (namespace ID and name concatenated)
Set all of the bytes to the hash bytes
if using SHA-1, discard the last 32 bits/4 bytes since SHA-1's output is 160 bits, but UUIDs are 128 bits
MD5 is already 128 bits
On byte 8, set bits 5-8 to the version bits
0011 for v3
0101 for v5
Set bits 8 + 7 of byte 8 to zero and one
Make scene for UUID/GUID namespaces
Make scene for UUIDv3 hashing vs UUIDv5 hashing
Script
word-count
Let's take a look at how version 3 and 5 UUIDs (also called GUIDs) are created, as specified by RFC 4122.
There are two inputs, the namespace UUID and the name. The namespace UUID is itself a UUID (of any version), that identifies the intended use of the UUID. For example, it can indicate it's a domain name UUID, an OID UUID, a UUID that repersents a message in a particular messenger app, or for any other purpose. In this example, I've just chosen a random namespace UUID. The name input is the unique part. The meaning of the name is determined by the namespace. For example, in the DNS namespace it's the canonical form of the domain. In the OID namespace, it's the OID. Often, it's just randomly generated. I'm using the string "example" as the name here.
We take the namespace UUID as raw bytes and the name, and concatenate them together. This concatenation is then passed through a hash function. For version 3 UUIDs, this is MD5. For version 5 UUIDs, this is SHA-1. The hashing function is the only difference between version 3 and version 5 UUIDs. I'll stick with version 5 in this example, since it's newer and less prone to collisions. Dashes are added after the 8th, 12th, 16th, and 20th hex characters. Since SHA-1 has 160 output bits, but UUIDs are 128 bits, the extra 32 bits at the end are discarded. Since MD5 hashes are 128 bits long, there is no need to do this for version 3 UUIDs.
Next, the version number is added to the UUID. Hex character 13 (or bits 97-100) is replaced with the version number: 3 for version 3 UUIDs, and 5 for version 5 UUIDs. Finally, the variant specifier. This specifies how the UUID is encoded. The only spec-complaint value is "10", which indicates big-endian (also called network order). Some Microsoft products use "110" to designate little-endian UUIDs, which are encoded differently, however this is non-standard and should not be used. The first 2 bits (or three in the non-standard case) of the 17th hex character (or 9th byte) are overwritten with the variant specifier. The UUID is now complete. Thanks for watching!