Author Topic: All 4 UUID Versions in QB64!  (Read 4413 times)

0 Members and 1 Guest are viewing this topic.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
All 4 UUID Versions in QB64!
« on: July 19, 2020, 08:50:00 pm »
I had made a post a while back about using UUIDs in QB64. Since then, I've learned a lot more about them and how to create them! I first started out only being able to produce Version 1 and 4 but now I can create Version 1, 3, 4, and 5 (version 2 is not used except in extremely specific uses and so no one uses them)!
For version 1 and 4 I use a Windows library called "rpcrt4". For version 3 and 5 I do an API call using urlmon and download a response from the website. Version 3 and Version 5 use an algorithm of hashing a previously defined UUID and a supplied string in MD5 for version 3 or SHA1 for version 5. Version 1 UUIDs contain a time stamp from the machine which created it as well as the MAC address of the machine. I have created functions for extracting this timestamp and clock sequence (which I do not know what it is for). With help from @moises1953 I was able to convert the UTC time zone stamp that I made into the local time of whatever machine is running the code. I had previously been doing it using JavaScript through a NodeJS shell call (which I will show extensively in a new post sometime showing how to use JavaScript in QB64!). There was no conceivable way to create the Version 3 and Version 5 UUIDs through C/C++ since no one online apparently knows how to make the function from scratch. See below for my full source code which creates 5 Version 1 (sequential, time & date and MAC-based) UUIDs, 1 Version 3 (MD5 namespace based) UUID, 5 version 4 (random) UUIDs, and 1 Version 5 (SHA1 namespace based) UUIDs. I also have code to retrieve the hash (for which I don't know the purpose) for the UUIDs. Use these however you see fit. The only "non random" UUIDs are the Version 3 and Version 5. If someone were to input the same data they would receive the same UUID. Version 1 is not considered to be "secure" because it contains the time stamp and MAC address. Version 4 is the most widely used version.
 
uuidwithmacvendorapi.png
 
uuidgen.png

Code: QB64: [Select]
  1. _CONSOLETITLE "UUID Generator"
  2.  
  3. TYPE GUID
  4.     Data1 AS _UNSIGNED LONG
  5.     Data2 AS _UNSIGNED INTEGER
  6.     Data3 AS _UNSIGNED INTEGER
  7.     Data4 AS _UNSIGNED _BYTE
  8.     Data5 AS _UNSIGNED _BYTE
  9.     Data6 AS _UNSIGNED _BYTE
  10.     Data7 AS _UNSIGNED _BYTE
  11.     Data8 AS _UNSIGNED _BYTE
  12.     Data9 AS _UNSIGNED _BYTE
  13.     Data10 AS _UNSIGNED _BYTE
  14.     Data11 AS _UNSIGNED _BYTE
  15.  
  16. TYPE SystemTime
  17.     wYear AS INTEGER
  18.     wMonth AS INTEGER
  19.     wDayOfWeek AS INTEGER
  20.     wDay AS INTEGER
  21.     wHour AS INTEGER
  22.     wMinute AS INTEGER
  23.     wSecond AS INTEGER
  24.     wMilliseconds AS INTEGER
  25.  
  26. TYPE TDZoneInfo 'TIME_DYNAMIC_ZONE_INFORMATION
  27.     Bias AS LONG
  28.     StandardName AS STRING * 64 'wchar32
  29.     StandardDate AS SystemTime
  30.     StandardBias AS LONG
  31.     DaylightName AS STRING * 64 'wchar32
  32.     DaylightDate AS SystemTime
  33.     DaylightBias AS LONG
  34.     TimeZoneKeyName AS STRING * 256 ' WCHAR128
  35.     DynamicDaylightTimeDisabled AS _BYTE 'BOOLEAN->BYTE
  36.  
  37.   FUNCTION SystemTimeToTzSpecificLocalTime%% (BYVAL lpTimeZoneInformation AS _UNSIGNED _OFFSET,_
  38.     BYVAL lpUniversalTime AS _UNSIGNED _OFFSET, BYVAL lpLocalTime AS _UNSIGNED _OFFSET)
  39.     FUNCTION GetDynamicTimeZoneInformation~& (BYVAL lpTimeZoneInformation AS _UNSIGNED _OFFSET)
  40.     SUB GetSystemTime (BYVAL lpSystemTime AS _UNSIGNED _OFFSET)
  41.  
  42.  
  43.  
  44.     FUNCTION UuidCreate%& (GUID AS GUID) 'Version 4 UUID
  45.     FUNCTION UuidCreateSequential%& (GUID AS GUID) 'Version 1 UUID
  46.     FUNCTION UuidHash~% (GUID AS GUID, Status AS LONG)
  47.  
  48. DECLARE LIBRARY "uuiddate"
  49.     FUNCTION uuiddate$ (BYVAL timestamp~&&) 'used to extract date from Version 1 UUID
  50.  
  51. PRINT "4 Sequential Version 1 UUIDs:"
  52. PRINT "_______________________________________________"
  53. DIM x
  54. FOR x = 1 TO 4
  55.     UUID = UUIDVer1
  56.     PRINT UUID
  57.     PRINT "Timestamp (Local): "; ExtractTimestamp(UUID)
  58.     PRINT "Clock Sequence   : "; ClockSequence(UUID)
  59.     PRINT "UUID Variant     : "; UUIDVariant(UUID)
  60.     PRINT "UUID Version     : "; UUIDVersion(UUID)
  61.     PRINT "UUID Hash        : "; _TRIM$(STR$(GUIDHash))
  62.     PRINT "MAC Address      : "; MACAddress(UUID)
  63.     PRINT "MAC Vendor       : "; MACVendor(MACAddress(UUID))
  64.     PRINT
  65.     _DELAY 0.1 'Delay so API doesn't respond with error of too many requests back to back
  66.  
  67. PRINT "4 Version 3 UUIDs using www.qb64.org as seed:"
  68. PRINT "_______________________________________________"
  69. UUID = UUIDVer3(1, "www.qb64.org")
  70. PRINT UUID, "(DNS namespace based)"
  71. PRINT "UUID Variant   : "; UUIDVariant(UUID)
  72. PRINT "UUID Version   : "; UUIDVersion(UUID)
  73. PRINT "UUID Hash      : "; _TRIM$(STR$(GUIDHash))
  74.  
  75. UUID = UUIDVer3(2, "www.qb64.org")
  76. PRINT UUID, "(URL namespace based)"
  77. PRINT "UUID Variant   : "; UUIDVariant(UUID)
  78. PRINT "UUID Version   : "; UUIDVersion(UUID)
  79. PRINT "UUID Hash      : "; _TRIM$(STR$(GUIDHash))
  80.  
  81. UUID = UUIDVer3(3, "www.qb64.org")
  82. PRINT UUID, "(OID namespace based)"
  83. PRINT "UUID Variant   : "; UUIDVariant(UUID)
  84. PRINT "UUID Version   : "; UUIDVersion(UUID)
  85. PRINT "UUID Hash      : "; _TRIM$(STR$(GUIDHash))
  86.  
  87. UUID = UUIDVer3(4, "www.qb64.org")
  88. PRINT UUID, "(x500 namespace based)"
  89. PRINT "UUID Variant   : "; UUIDVariant(UUID)
  90. PRINT "UUID Version   : "; UUIDVersion(UUID)
  91. PRINT "UUID Hash      : "; _TRIM$(STR$(GUIDHash))
  92.  
  93. PRINT "4 Random Version 4 UUIDs:"
  94. PRINT "_______________________________________________"
  95. FOR x = 1 TO 4
  96.     UUID = UUIDVer4
  97.     PRINT UUID
  98.     PRINT "UUID Variant   : "; UUIDVariant(UUID)
  99.     PRINT "UUID Version   : "; UUIDVersion(UUID)
  100.     PRINT "UUID Hash      : "; _TRIM$(STR$(GUIDHash))
  101.     PRINT
  102.  
  103. PRINT "4 Version 5 UUIDs using www.qb64.org as seed:"
  104. PRINT "_______________________________________________"
  105. UUID = UUIDVer5(1, "www.qb64.org")
  106. PRINT UUID, "(DNS namespace based)"
  107. PRINT "UUID Variant   : "; UUIDVariant(UUID)
  108. PRINT "UUID Version   : "; UUIDVersion(UUID)
  109. PRINT "UUID Hash      : "; _TRIM$(STR$(GUIDHash))
  110.  
  111. UUID = UUIDVer5(2, "www.qb64.org")
  112. PRINT UUID, "(URL namespace based)"
  113. PRINT "UUID Variant   : "; UUIDVariant(UUID)
  114. PRINT "UUID Version   : "; UUIDVersion(UUID)
  115. PRINT "UUID Hash      : "; _TRIM$(STR$(GUIDHash))
  116.  
  117. UUID = UUIDVer5(3, "www.qb64.org")
  118. PRINT UUID, "(OID namespace based)"
  119. PRINT "UUID Variant   : "; UUIDVariant(UUID)
  120. PRINT "UUID Version   : "; UUIDVersion(UUID)
  121. PRINT "UUID Hash      : "; _TRIM$(STR$(GUIDHash))
  122.  
  123. UUID = UUIDVer5(4, "www.qb64.org")
  124. PRINT UUID, "(x500 namespace based)"
  125. PRINT "UUID Variant   : "; UUIDVariant(UUID)
  126. PRINT "UUID Version   : "; UUIDVersion(UUID)
  127. PRINT "UUID Hash      : "; _TRIM$(STR$(GUIDHash))
  128.  
  129.  
  130.  
  131. FUNCTION ClockSequence$ (UUID AS STRING)
  132.     ClockSequence = _TRIM$(STR$(VAL("&H" + MID$(UUID, 21, 3))))
  133.  
  134. FUNCTION MACVendor$ (MAC AS STRING)
  135.     DIM URL AS STRING
  136.     DIM URLFile AS STRING
  137.     URLFile = "macvendorrequest"
  138.     SHELL _HIDE "curl -G " + CHR$(34) + "https://api.macvendors.com/v1/lookup/" + MAC + CHR$(34) + " -H " + CHR$(34) + "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiIsImp0aSI6IjllMmQ0YzYwLTU3NmQtNDI2OC04NDdkLWIyYTUwNGEyM2ZhMCJ9.eyJpc3MiOiJtYWN2ZW5kb3JzIiwiYXVkIjoibWFjdmVuZG9ycyIsImp0aSI6IjllMmQ0YzYwLTU3NmQtNDI2OC04NDdkLWIyYTUwNGEyM2ZhMCIsImlhdCI6MTU5NTkzMzc1OSwiZXhwIjoxOTEwNDI5NzU5LCJzdWIiOiI3NTkyIiwidHlwIjoiYWNjZXNzIn0.9MTN3PlkFxHAokvIKFFtF1aJYdXwjFpC2etMejJ-V4l9NCbT_qhqF-BpNv25h9kpDfntyGWCMXvqs6s9ShEbkw" + CHR$(34) + " -H " + CHR$(34) + "Accept: text/plain" + CHR$(34) + " -o " + URLFile
  139.     DIM U AS INTEGER
  140.     U = FREEFILE
  141.     OPEN URLFile FOR BINARY AS #U
  142.     IF LOF(U) <> 0 THEN
  143.         DIM macvendorrequest AS STRING
  144.         macvendorrequest = SPACE$(LOF(U))
  145.         GET #U, , macvendorrequest
  146.     ELSE
  147.         CLOSE #U
  148.         KILL URLFile
  149.         MACVendor = ""
  150.         EXIT FUNCTION
  151.     END IF
  152.     CLOSE #U
  153.     KILL URLFile
  154.     MACVendor = macvendorrequest
  155.  
  156. FUNCTION MACAddress$ (UUID AS STRING)
  157.     MACAddress = MID$(UUID, 25, 2) + "-" + MID$(UUID, 27, 2) + "-" + MID$(UUID, 29, 2) + "-" + MID$(UUID, 31, 2) + "-" + MID$(UUID, 33, 2) + "-" + MID$(UUID, 35, 2)
  158.  
  159. FUNCTION UUIDVersion$ (UUID AS STRING)
  160.     DIM version AS STRING
  161.     version = MID$(UUID, 15, 1)
  162.     SELECT CASE version
  163.         CASE "1"
  164.             UUIDVersion = "1 (time and node based)"
  165.             EXIT FUNCTION
  166.         CASE "3"
  167.             UUIDVersion = "3 (name based, MD5)"
  168.             EXIT FUNCTION
  169.         CASE "4"
  170.             UUIDVersion = "4 (random data based)"
  171.             EXIT FUNCTION
  172.         CASE "5"
  173.             UUIDVersion = "5 (name based, SHA-1)"
  174.             EXIT FUNCTION
  175.     END SELECT
  176.  
  177. FUNCTION UUIDVariant$ (UUID AS STRING)
  178.     DIM variant AS STRING
  179.     variant = MID$(UUID, 20, 1)
  180.     IF VAL("&H" + variant) >= 0 AND VAL("&H" + variant) <= 7 THEN
  181.         UUIDVariant = "reserved (NCS backward compatible)"
  182.         EXIT FUNCTION
  183.     ELSEIF VAL("&H" + variant) >= 8 AND VAL("&H" + variant) <= 11 THEN
  184.         UUIDVariant = "DCE 1.1, ISO/IEC 11578:1996"
  185.         EXIT FUNCTION
  186.     ELSEIF VAL("&H" + variant) >= 12 AND VAL("&H" + variant) <= 13 THEN
  187.         UUIDVariant = "reserved (Microsoft GUID)"
  188.         EXIT FUNCTION
  189.     ELSEIF VAL("&H" + variant) = 14 THEN
  190.         UUIDVariant = "reserved (future use)"
  191.         EXIT FUNCTION
  192.     ELSEIF VAL("&H" + variant) = 15 THEN
  193.         UUIDVariant = "unknown/invalid"
  194.         EXIT FUNCTION
  195.     END IF
  196.  
  197. FUNCTION ExtractTimestamp$ (UUID AS STRING)
  198.     DIM timestamp AS _UNSIGNED _INTEGER64
  199.     DIM data1 AS STRING
  200.     DIM data2 AS STRING
  201.     DIM data3 AS STRING
  202.     DIM hours
  203.     DIM minutes
  204.     DIM seconds
  205.     data1 = MID$(UUID, 16, 3)
  206.     data2 = MID$(UUID, 10, 4)
  207.     data3 = MID$(UUID, 1, 8)
  208.     timestamp = VAL("&H" + data1 + data2 + data3)
  209.     timestamp = timestamp / 10000000 - 12219292800
  210.     hours = timestamp \ 3600 MOD 24 'UTC timezone
  211.     minutes = timestamp \ 60 MOD 60
  212.     seconds = timestamp MOD 60
  213.     DIM UTCTime AS SystemTime, loctime AS SystemTime, ZoneInfo AS TDZoneInfo
  214.     DIM uuidate AS STRING
  215.     uuidate = uuiddate(timestamp)
  216.     UTCTime.wYear = VAL(MID$(uuidate, 1, 4))
  217.     UTCTime.wMonth = VAL(MID$(uuidate, 6, 2))
  218.     SELECT CASE UTCTime.wMonth
  219.         CASE IS < 10
  220.             UTCTime.wDay = VAL(MID$(uuidate, 8, 2))
  221.         CASE IS > 10
  222.             UTCTime.wDay = VAL(MID$(uuidate, 9, 2))
  223.     END SELECT
  224.     UTCTime.wHour = hours
  225.     UTCTime.wMinute = minutes
  226.     UTCTime.wSecond = seconds
  227.     DIM e~&
  228.     DIM f%%
  229.     e~& = GetDynamicTimeZoneInformation(_OFFSET(ZoneInfo))
  230.     f%% = SystemTimeToTzSpecificLocalTime(_OFFSET(ZoneInfo), _OFFSET(UTCTime), _OFFSET(loctime))
  231.     DIM year AS STRING
  232.     DIM month AS STRING
  233.     DIM day AS STRING
  234.     DIM hour AS STRING
  235.     DIM minute AS STRING
  236.     DIM second AS STRING
  237.     year = _TRIM$(STR$(loctime.wYear))
  238.     month = _TRIM$(STR$(loctime.wMonth))
  239.     IF LEN(month) <> 2 THEN
  240.         month = "0" + month
  241.     END IF
  242.     day = _TRIM$(STR$(loctime.wDay))
  243.     IF LEN(day) <> 2 THEN
  244.         day = "0" + day
  245.     END IF
  246.     hour = _TRIM$(STR$(loctime.wHour))
  247.     IF LEN(hour) <> 2 THEN
  248.         hour = "0" + hour
  249.     END IF
  250.     minute = _TRIM$(STR$(loctime.wMinute))
  251.     IF LEN(minute) <> 2 THEN
  252.         minute = "0" + minute
  253.     END IF
  254.     second = _TRIM$(STR$(loctime.wSecond))
  255.     IF LEN(second) <> 2 THEN
  256.         second = "0" + second
  257.     END IF
  258.     ExtractTimestamp = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second
  259.  
  260. FUNCTION UUIDVer1$ '  Version: 1 (Date & MAC Address) Generated from Date & time and MAC address of network card. Can be security issue.
  261.     DIM GUID AS GUID 'Variant: DCE 1.1, ISO/IEC 11578:1996
  262.     DIM UUID AS STRING
  263.     DIM a%&
  264.     DIM status AS LONG
  265.     DO
  266.         a%& = UuidCreateSequential(GUID)
  267.         IF a%& = 0 THEN
  268.             IF LEN(HEX$(GUID.Data1)) <> 8 THEN
  269.                 UUID = "0" + HEX$(GUID.Data1) + "-"
  270.             ELSE
  271.                 UUID = HEX$(GUID.Data1) + "-"
  272.             END IF
  273.             IF LEN(HEX$(GUID.Data2)) <> 4 THEN
  274.                 UUID = UUID + "0" + HEX$(GUID.Data2) + "-"
  275.             ELSE
  276.                 UUID = UUID + HEX$(GUID.Data2) + "-"
  277.             END IF
  278.             IF LEN(HEX$(GUID.Data3)) <> 4 THEN
  279.                 UUID = UUID + "0" + HEX$(GUID.Data3) + "-"
  280.             ELSE
  281.                 UUID = UUID + HEX$(GUID.Data3) + "-"
  282.             END IF
  283.             IF LEN(HEX$(GUID.Data4)) <> 2 THEN
  284.                 UUID = UUID + "0" + HEX$(GUID.Data4)
  285.             ELSE
  286.                 UUID = UUID + HEX$(GUID.Data4)
  287.             END IF
  288.             IF LEN(HEX$(GUID.Data5)) <> 2 THEN
  289.                 UUID = UUID + "0" + HEX$(GUID.Data5) + "-"
  290.             ELSE
  291.                 UUID = UUID + HEX$(GUID.Data5) + "-"
  292.             END IF
  293.             IF LEN(HEX$(GUID.Data6)) <> 2 THEN
  294.                 UUID = UUID + "0" + HEX$(GUID.Data6)
  295.             ELSE
  296.                 UUID = UUID + HEX$(GUID.Data6)
  297.             END IF
  298.             IF LEN(HEX$(GUID.Data7)) <> 2 THEN
  299.                 UUID = UUID + "0" + HEX$(GUID.Data7)
  300.             ELSE
  301.                 UUID = UUID + HEX$(GUID.Data7)
  302.             END IF
  303.             IF LEN(HEX$(GUID.Data8)) <> 2 THEN
  304.                 UUID = UUID + "0" + HEX$(GUID.Data8)
  305.             ELSE
  306.                 UUID = UUID + HEX$(GUID.Data8)
  307.             END IF
  308.             IF LEN(HEX$(GUID.Data9)) <> 2 THEN
  309.                 UUID = UUID + "0" + HEX$(GUID.Data9)
  310.             ELSE
  311.                 UUID = UUID + HEX$(GUID.Data9)
  312.             END IF
  313.             IF LEN(HEX$(GUID.Data10)) <> 2 THEN
  314.                 UUID = UUID + "0" + HEX$(GUID.Data10)
  315.             ELSE
  316.                 UUID = UUID + HEX$(GUID.Data10)
  317.             END IF
  318.             IF LEN(HEX$(GUID.Data11)) <> 2 THEN
  319.                 UUID = UUID + "0" + HEX$(GUID.Data11)
  320.             ELSE
  321.                 UUID = UUID + HEX$(GUID.Data11)
  322.             END IF
  323.             GUIDHash = UuidHash(GUID, status)
  324.             UUIDVer1 = UUID
  325.         ELSE
  326.             UUIDVer1 = NilUUID
  327.         END IF
  328.     LOOP UNTIL LEN(UUID) = 36
  329.  
  330. FUNCTION UUIDVer3$ (mode AS INTEGER, StringToHash AS STRING)
  331.     DIM URL AS STRING
  332.     DIM URLFile AS STRING
  333.     DIM UUID AS STRING
  334.     DIM Data1 AS STRING
  335.     DIM Data2 AS STRING
  336.     DIM Data3 AS STRING
  337.     DIM Data4 AS STRING
  338.     DIM Data5 AS STRING
  339.     DIM Data6 AS STRING
  340.     DIM Data7 AS STRING
  341.     DIM Data8 AS STRING
  342.     DIM Data9 AS STRING
  343.     DIM Data10 AS STRING
  344.     DIM Data11 AS STRING
  345.     DIM GUID AS GUID
  346.     DIM status AS LONG
  347.  
  348.     DIM a%
  349.     URLFile = "uuidver3"
  350.     URL = "https://www.uuidtools.com/api/generate/v3/namespace/"
  351.     SELECT CASE mode
  352.         CASE 1
  353.             URL = URL + "ns:dns/name/"
  354.         CASE 2
  355.             URL = URL + "ns:url/name/"
  356.         CASE 3
  357.             URL = URL + "ns:oid/name/"
  358.         CASE 4
  359.             URL = URL + "ns:x500/name/"
  360.     END SELECT
  361.     URL = URL + StringToHash
  362.     a% = API_request(URL, URLFile)
  363.     DIM U AS INTEGER
  364.     U = FREEFILE
  365.     OPEN URLFile FOR BINARY AS #U
  366.     IF LOF(U) <> 0 THEN
  367.         UUID = SPACE$(LOF(U))
  368.         GET #U, , UUID
  369.     ELSE
  370.         CLOSE #U
  371.         KILL URLFile
  372.         UUIDVer3 = NilUUID
  373.         EXIT FUNCTION
  374.     END IF
  375.     CLOSE #U
  376.     KILL URLFile
  377.     UUID = UCASE$(MID$(UUID, 3, 36))
  378.     Data1 = MID$(UUID, 1, 8)
  379.     Data2 = MID$(UUID, 8, 4)
  380.     Data3 = MID$(UUID, 12, 3)
  381.     Data4 = MID$(UUID, 16, 2)
  382.     Data5 = MID$(UUID, 18, 2)
  383.     Data6 = MID$(UUID, 20, 2)
  384.     Data7 = MID$(UUID, 22, 2)
  385.     Data8 = MID$(UUID, 24, 2)
  386.     Data9 = MID$(UUID, 26, 2)
  387.     Data10 = MID$(UUID, 28, 2)
  388.     Data11 = MID$(UUID, 30, 2)
  389.  
  390.     GUID.Data1 = VAL("&H" + Data1): GUID.Data2 = VAL("&H" + Data2): GUID.Data3 = VAL("&H" + Data3): GUID.Data4 = VAL("&H" + Data4): GUID.Data5 = VAL("&H" + Data5): GUID.Data6 = VAL("&H" + Data6)
  391.     GUID.Data7 = VAL("&H" + Data7): GUID.Data8 = VAL("&H" + Data8): GUID.Data9 = VAL("&H" + Data9): GUID.Data10 = VAL("&H" + Data10): GUID.Data11 = VAL("&H" + Data11)
  392.     GUIDHash = UuidHash(GUID, status)
  393.     UUIDVer3 = UUID
  394.  
  395. FUNCTION UUIDVer4$ '  Version: 4 (Random) For a truly unique UUID, use this. Can't be duplicated and doesn't reference a MAC address.
  396.     DIM GUID AS GUID 'Variant: DCE 1.1, ISO/IEC 11578:1996
  397.     DIM UUID AS STRING
  398.     DIM a%&
  399.     DIM status AS LONG
  400.     DO
  401.         a%& = UuidCreate(GUID)
  402.         IF a%& = 0 THEN
  403.             IF LEN(HEX$(GUID.Data1)) <> 8 THEN
  404.                 UUID = "0" + HEX$(GUID.Data1) + "-"
  405.             ELSE
  406.                 UUID = HEX$(GUID.Data1) + "-"
  407.             END IF
  408.             IF LEN(HEX$(GUID.Data2)) <> 4 THEN
  409.                 UUID = UUID + "0" + HEX$(GUID.Data2) + "-"
  410.             ELSE
  411.                 UUID = UUID + HEX$(GUID.Data2) + "-"
  412.             END IF
  413.             IF LEN(HEX$(GUID.Data3)) <> 4 THEN
  414.                 UUID = UUID + "0" + HEX$(GUID.Data3) + "-"
  415.             ELSE
  416.                 UUID = UUID + HEX$(GUID.Data3) + "-"
  417.             END IF
  418.             IF LEN(HEX$(GUID.Data4)) <> 2 THEN
  419.                 UUID = UUID + "0" + HEX$(GUID.Data4)
  420.             ELSE
  421.                 UUID = UUID + HEX$(GUID.Data4)
  422.             END IF
  423.             IF LEN(HEX$(GUID.Data5)) <> 2 THEN
  424.                 UUID = UUID + "0" + HEX$(GUID.Data5) + "-"
  425.             ELSE
  426.                 UUID = UUID + HEX$(GUID.Data5) + "-"
  427.             END IF
  428.             IF LEN(HEX$(GUID.Data6)) <> 2 THEN
  429.                 UUID = UUID + "0" + HEX$(GUID.Data6)
  430.             ELSE
  431.                 UUID = UUID + HEX$(GUID.Data6)
  432.             END IF
  433.             IF LEN(HEX$(GUID.Data7)) <> 2 THEN
  434.                 UUID = UUID + "0" + HEX$(GUID.Data7)
  435.             ELSE
  436.                 UUID = UUID + HEX$(GUID.Data7)
  437.             END IF
  438.             IF LEN(HEX$(GUID.Data8)) <> 2 THEN
  439.                 UUID = UUID + "0" + HEX$(GUID.Data8)
  440.             ELSE
  441.                 UUID = UUID + HEX$(GUID.Data8)
  442.             END IF
  443.             IF LEN(HEX$(GUID.Data9)) <> 2 THEN
  444.                 UUID = UUID + "0" + HEX$(GUID.Data9)
  445.             ELSE
  446.                 UUID = UUID + HEX$(GUID.Data9)
  447.             END IF
  448.             IF LEN(HEX$(GUID.Data10)) <> 2 THEN
  449.                 UUID = UUID + "0" + HEX$(GUID.Data10)
  450.             ELSE
  451.                 UUID = UUID + HEX$(GUID.Data10)
  452.             END IF
  453.             IF LEN(HEX$(GUID.Data11)) <> 2 THEN
  454.                 UUID = UUID + "0" + HEX$(GUID.Data11)
  455.             ELSE
  456.                 UUID = UUID + HEX$(GUID.Data11)
  457.             END IF
  458.             GUIDHash = UuidHash(GUID, status)
  459.             UUIDVer4 = UUID
  460.         ELSE
  461.             UUIDVer4 = NilUUID
  462.         END IF
  463.     LOOP UNTIL LEN(UUID) = 36
  464.  
  465. FUNCTION UUIDVer5$ (mode AS INTEGER, StringToHash AS STRING)
  466.     DIM URL AS STRING
  467.     DIM URLFile AS STRING
  468.     DIM UUID AS STRING
  469.     DIM Data1 AS STRING
  470.     DIM Data2 AS STRING
  471.     DIM Data3 AS STRING
  472.     DIM Data4 AS STRING
  473.     DIM Data5 AS STRING
  474.     DIM Data6 AS STRING
  475.     DIM Data7 AS STRING
  476.     DIM Data8 AS STRING
  477.     DIM Data9 AS STRING
  478.     DIM Data10 AS STRING
  479.     DIM Data11 AS STRING
  480.     DIM GUID AS GUID
  481.     DIM status AS LONG
  482.  
  483.     DIM a%
  484.     URLFile = "uuidver5"
  485.     URL = "https://www.uuidtools.com/api/generate/v5/namespace/"
  486.     SELECT CASE mode
  487.         CASE 1
  488.             URL = URL + "ns:dns/name/"
  489.         CASE 2
  490.             URL = URL + "ns:url/name/"
  491.         CASE 3
  492.             URL = URL + "ns:oid/name/"
  493.         CASE 4
  494.             URL = URL + "ns:x500/name/"
  495.     END SELECT
  496.     URL = URL + StringToHash
  497.     a% = API_request(URL, URLFile)
  498.     DIM U AS INTEGER
  499.     U = FREEFILE
  500.     OPEN URLFile FOR BINARY AS #U
  501.     IF LOF(U) <> 0 THEN
  502.         UUID = SPACE$(LOF(U))
  503.         GET #U, , UUID
  504.     ELSE
  505.         CLOSE #U
  506.         KILL URLFile
  507.         UUIDVer5 = NilUUID
  508.         EXIT FUNCTION
  509.     END IF
  510.     CLOSE #U
  511.     KILL URLFile
  512.     UUID = UCASE$(MID$(UUID, 3, 36))
  513.     Data1 = MID$(UUID, 1, 8)
  514.     Data2 = MID$(UUID, 8, 4)
  515.     Data3 = MID$(UUID, 12, 3)
  516.     Data4 = MID$(UUID, 16, 2)
  517.     Data5 = MID$(UUID, 18, 2)
  518.     Data6 = MID$(UUID, 20, 2)
  519.     Data7 = MID$(UUID, 22, 2)
  520.     Data8 = MID$(UUID, 24, 2)
  521.     Data9 = MID$(UUID, 26, 2)
  522.     Data10 = MID$(UUID, 28, 2)
  523.     Data11 = MID$(UUID, 30, 2)
  524.  
  525.     GUID.Data1 = VAL("&H" + Data1): GUID.Data2 = VAL("&H" + Data2): GUID.Data3 = VAL("&H" + Data3): GUID.Data4 = VAL("&H" + Data4): GUID.Data5 = VAL("&H" + Data5): GUID.Data6 = VAL("&H" + Data6)
  526.     GUID.Data7 = VAL("&H" + Data7): GUID.Data8 = VAL("&H" + Data8): GUID.Data9 = VAL("&H" + Data9): GUID.Data10 = VAL("&H" + Data10): GUID.Data11 = VAL("&H" + Data11)
  527.     GUIDHash = UuidHash(GUID, status)
  528.     UUIDVer5 = UUID
  529.  
  530. FUNCTION NilUUID$
  531.     NilUUID = "00000000-0000-0000-0000-000000000000"
  532.  
  533.     FUNCTION URLDownloadToFileA (BYVAL pCaller AS LONG, szURL AS STRING, szFileName AS STRING, BYVAL dwReserved AS LONG, BYVAL lpfnCB AS LONG)
  534.  
  535. FUNCTION API_request (URL AS STRING, File AS STRING)
  536.     API_request = URLDownloadToFileA(0, URL + CHR$(0), File + CHR$(0), 0, 0)
* uuiddate.h (Filesize: 0.71 KB, Downloads: 138)
« Last Edit: July 28, 2020, 09:09:53 am by SpriggsySpriggs »
Shuwatch!

Offline loudar

  • Newbie
  • Posts: 73
  • improve it bit by bit.
    • View Profile
Re: All 4 UUID Versions in QB64!
« Reply #1 on: July 20, 2020, 08:34:12 am »
It tells me it can't find the library "uuiddate", what am I missing?
Check out what I do besides coding: http://loudar.myportfolio.com/

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: All 4 UUID Versions in QB64!
« Reply #2 on: July 20, 2020, 11:37:18 am »
It tells me it can't find the library "uuiddate", what am I missing?
@loudar Sorry! I must have not attached the header file! It's there now.
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: All 4 UUID Versions in QB64!
« Reply #3 on: July 20, 2020, 03:19:38 pm »
3:18 PM:
Updated source code in original post with minor change and added another screenshot.
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: All 4 UUID Versions in QB64!
« Reply #4 on: July 28, 2020, 07:07:58 am »
7:07 AM Updated source code and screenshots with new MAC address vendor API.
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: All 4 UUID Versions in QB64!
« Reply #5 on: July 28, 2020, 08:00:38 am »
8:00 AM Updated source code with _DELAY of 0.1 in FOR loop for UUIDVer1 so the MAC Vendor API doesn't respond with an error from too many requests back to back.
« Last Edit: July 28, 2020, 08:11:24 am by SpriggsySpriggs »
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: All 4 UUID Versions in QB64!
« Reply #6 on: July 28, 2020, 09:10:30 am »
9:10 AM Updated source code with UUIDVersion$ function that returns the version number of the UUID.
Shuwatch!