diff --git a/a.out b/a.out new file mode 100755 index 0000000..0af423f Binary files /dev/null and b/a.out differ diff --git a/serijske.txt b/serijske.txt new file mode 100644 index 0000000..8492f90 --- /dev/null +++ b/serijske.txt @@ -0,0 +1,100 @@ +00000001-53743621-a2b3-4d71-a3a7-f8dcfa3bd7b7 89af80b0 +00000002-302a1ec1-a152-42c5-9059-f48a4aa6349d 359700e0 +00000003-1b6bbfbe-208d-41c4-b62a-a131667ae996 4d3ecb97 +00000004-a5085947-5b9b-4e6b-b503-f640aa2cdec6 ae37fbde +00000005-979e86b7-2db8-4d63-a21f-95499a7fe040 951d72f5 +00000006-883a87e3-d696-40cc-9947-0d4573ec0d0c a59e5691 +00000007-8b94c4b8-4d42-4c31-a2b1-7bfc325c3eba 032eaa50 +00000008-97c59f6e-5cef-4bf6-b749-3dab364bb8c1 4d2e5166 +00000009-df7d7b2d-c097-4e23-8ada-217c375f38cf a9055df0 +00000010-26d73e83-c77a-4a00-83b8-acfa0465bce4 a4ab905c +00000011-e33912a4-d071-481c-8ce9-98844ad15570 b2e8fb9d +00000012-a993f371-0e6f-42d2-a91f-cd2e858b1369 bc1f7100 +00000013-c4260f95-97d8-42e4-824b-6a0e1dbf7ec7 41c40a08 +00000014-54733a62-e3ac-460d-8b04-3b518f4ebb54 0792edb3 +00000015-74cbea0d-a49d-4268-a95e-76081ef5d072 c799823d +00000016-690bd54d-b70c-4b84-9196-d6a0e592f55b 38b3aec5 +00000017-5ee06803-7f5c-4b6a-bae2-73d8d8444c42 830ed1b7 +00000018-4f239007-30eb-4b41-8363-e26af5d8c555 64d8144b +00000019-ba2e593b-8ac5-4545-a819-1f815e6cc4ad f6b76758 +00000020-9056b5c0-4342-43c6-a5e5-329cbff7f27a f0d6f206 +00000021-264cb5b1-135c-47bb-b618-3ed485038316 b25096f8 +00000022-5a39d79d-7cda-4522-8197-bf818fb2fbb6 012b3b11 +00000023-00b26913-0f62-4e85-ba0d-5b0111de176c 7aac7798 +00000024-18ef0a94-cb70-478d-8977-10982a0d502a e66c4033 +00000025-bfba3ecf-1d0d-4598-9bb0-992d90b199a9 54fde683 +00000026-a1a43e6d-16f6-4b1f-ae0c-b8991909c4d8 ac520492 +00000027-c304a9e1-11fe-4a2d-b014-5b42c5f5eb68 920116b2 +00000028-9b2bd5b1-22d1-4091-9d89-2cf793f1d158 1b56257c +00000029-f57b3a08-7bb5-462d-8991-6f90885bf824 d09b3516 +00000030-86cfd6a9-a2a8-4b81-b368-79c65a4b1f50 94288e36 +00000031-c75a5943-108f-40da-a2df-6caa3c66cfc2 3fb54b8d +00000032-36a66cd9-4fa8-4b82-91d5-4a6b226abce9 8abd31ff +00000033-c4172dd5-a69e-41c9-bf1e-74bb84457ebb 982a7178 +00000034-eceb953d-94f0-4fa6-870b-13e975d0d33b 2d88adaf +00000035-e702128f-a0c3-4920-a1ce-dc67145b2301 e627dbb4 +00000036-48b83edd-aafe-4472-8b98-5c816931bd51 014d59a6 +00000037-34cfe1d5-943b-4676-8bd3-dd1f2f022178 4520fea2 +00000038-ba605665-60db-486b-b436-ecdd67aa309b 831bd23c +00000039-7b127110-4e68-4759-bc66-796c689ae424 ede54979 +00000040-fa3c895c-1863-478c-99b5-6b01609b9ddc e22da9f2 +00000041-ae10edfc-7975-47b6-9cd0-24456c096968 b693d047 +00000042-46f3c45e-588c-4bf1-8257-f3a3f29181a2 e06b73c9 +00000043-a26f9f1c-e5f7-43c2-88f7-093502739d48 a917d49b +00000044-6763a7bf-ef93-4233-aba6-d7df395a82db 9a6fc586 +00000045-c923f8b0-1bcc-43e3-857d-1ac7f0b81059 e4a9306e +00000046-1cb71a0d-4ccc-4038-b319-18ad739a8a3e dc62a364 +00000047-bd84eed9-5263-4d18-a0d7-dfd191f02cad 7c4a99ac +00000048-a846baf5-13fb-4f87-9647-358ae2bfc8a1 b62bbfbb +00000049-44b87b96-1d3a-4ffe-938f-d1a480fd522a 3892a693 +00000050-440e2057-0a50-4e20-9815-aa7bd5741e1b f9db219e +00000051-2e9ab24c-d462-4be8-b11d-8d721be09d5f 8b32007d +00000052-eebeb7f9-0f97-4aa7-acc5-24823b439d6a fa5c2520 +00000053-dd51b6b3-b303-4ca5-a02b-193c0cb79bfb c144c47d +00000054-7653f585-ea11-4e98-9752-1c1495ba7e74 fcdc0724 +00000055-0c3628bf-39c5-4659-b080-95fd3832faae 9d27be35 +00000056-86f03572-0263-4bda-b527-ee4ce26dc0ee f369d879 +00000057-a4e9aedd-af16-48a1-96ce-a0ce019b7d88 27bcc04f +00000058-8cb3fa8f-1707-4bcd-af5a-1a12c8da016d bdb10387 +00000059-c5b04b75-c684-485d-93b8-2d5555abdee2 91f3c213 +00000060-5fd97276-e1de-4411-b95f-23023b256f01 4d2bfbcf +00000061-d5bb779c-408f-4a94-8928-e99ed3c88134 dc4e917a +00000062-a3f4aa85-d3ef-470e-8fbb-108be0808cb6 f44df742 +00000063-3c04547d-9450-42dd-b9fc-7d4ec6fe826b 44771f60 +00000064-f42ef1c9-1e89-476e-85e8-f9266987dda6 376929e2 +00000065-8b332420-8437-4efd-b57c-4cfc7cce6872 c368b705 +00000066-fc5a3c1c-e414-4a2b-bd85-52670d300e99 c27ce15f +00000067-6433bae8-6aba-46a0-b734-9db404072701 129f397e +00000068-62641e47-79a9-4377-afc5-de3df5edd75b 90c6d24c +00000069-2192448c-4d2c-4d85-a1cb-3b65d2626736 c9a0efc1 +00000070-c6857e41-2ff1-485f-b797-9dae85750aa7 8e5d05b3 +00000071-094f3457-7c62-4ddd-af19-43037cab3943 cc967352 +00000072-31b78561-aa3e-4162-9560-125cd61c04df 3045eb64 +00000073-6c3938e8-9c16-47cb-af0c-ceabb709efe9 c34278de +00000074-c1754c6c-b30f-4f8a-afe1-e747feec286b caa6a035 +00000075-266055c2-761d-4fa6-a95f-52e16843cb2a e42c70f1 +00000076-b919976d-2867-4898-8ae0-df49cd08b5f4 cf98380c +00000077-680bb8df-2948-4653-a7d9-35111d023cd6 9ce537d4 +00000078-1bd34543-3c3f-4b86-a0bc-d0eec486e32d 40b267c8 +00000079-929c0dbc-e594-408d-ae46-9f8c48db6464 8e426d92 +00000080-afaaa8ec-e984-430b-8144-f907cbde345f 82e15350 +00000081-7b421c61-d72d-4f47-b38f-d3bc6b39211c f46b318f +00000082-e4c909ce-4f7d-4a91-82d4-988eb4cded30 0938c27c +00000083-100b92e8-3882-40ab-9305-687e3e8a9b23 40915ea9 +00000084-54a5f2a4-23ce-46e5-a4ce-75599c6389ad 1e1f14af +00000085-6f1d96a7-9fc6-44b2-8cbd-320b48ce2f9d 8f069715 +00000086-74234297-f178-4e96-87f3-efe4587a93c7 e3429a28 +00000087-972a6f38-f1c4-4bbe-821f-cacaedfa6862 a5942bb4 +00000088-1eaafa10-2479-476c-ad98-51c513e48dab 7d639146 +00000089-10fde303-c2cf-4246-ae8d-11dd887a41a6 8f05ea0a +00000090-263cb74a-b660-4724-b809-ea0dee79b8fe 1ab3717b +00000091-789c033c-6dc5-425d-9394-3bdc0f7d8436 47cbb987 +00000092-b93d8170-9d39-4596-8280-a332fa5c3273 e774d649 +00000093-f935af68-fa32-454f-8602-2cd67fb00d3a 2a4104cf +00000094-ed8fab8b-c841-430c-82c6-3ebe2470321f 14f304b8 +00000095-a6e187a1-154e-40dc-911e-b3d1cec10cbd 5fc1c140 +00000096-51b8491a-fa6d-47bd-b465-7d59d6af797e 91442699 +00000097-920120a8-5012-45a2-b039-7400fb81bd4d d656b0f6 +00000098-3a086835-758f-43aa-b571-05cd227e4cb4 0ce4a285 +00000099-806d5ed1-80e3-44b0-9ee8-b11a6b7067a6 cec25d7c +00000100-78d0dbee-60d0-4957-839e-25661e711c9e 7ea2894b diff --git a/uuid-gen.c b/uuid-gen.c new file mode 100644 index 0000000..ce0e608 --- /dev/null +++ b/uuid-gen.c @@ -0,0 +1,91 @@ +#include // printf za izpis +#include // srand, rand za RNG +#include // time za seedanje PRNG +#include // fiksne velikosti int podatkov +#include // CRC32 +// Kristjan Komloši, 2024 +// UUID generator, 1. domača naloga POKS +// Program se prevede z +// gcc uuid-gen.c -lz + + +// struktura, ki skupaj poveze serijsko, nakljucni uuid in CRC32 +struct uuid_uint128 +{ + uint8_t uuid_byte[16]; + char serial; + uint32_t crc; +}; + +void get_uuid(struct uuid_uint128 *uuid) +{ + // funkcija v pokazano UUID strukturo vpise v4 uuid (nakljucni) s serijsko stevilko in CRCjem + // xx xx xx xx - xx xx - Mx xx - Nx xx - xx xx xx xx xx xx + // M = verzija (0x4) + // N = varianta (0b10xx) + // byte maske za te vrednosti + + static char serial = 1; + const uint8_t version_mask_or = 0x40; + const uint8_t version_mask_and = 0x0F; + const uint8_t variant_mask_or = 0x80; + const uint8_t variant_mask_and = 0x3F; + + uuid->serial = serial++; // nastavimo naslednjo serijsko + + + for (int c = 0; c < sizeof(uuid->uuid_byte); c++) + { + // vzamemo stevilo iz RNG, ga prestavimo v interval [0,255], vpisemo + uuid->uuid_byte[c] = (uint8_t)((double)rand() / RAND_MAX * 255); + } + + // maskiranje bitov za verzijo in varianto + uuid->uuid_byte[6] &= version_mask_and; + uuid->uuid_byte[6] |= version_mask_or; + uuid->uuid_byte[8] &= variant_mask_and; + uuid->uuid_byte[8] |= variant_mask_or; + + // Zlib ima implementacijo CRC-32 + // Glej https://refspecs.linuxbase.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/zlib-crc32-1.html + uuid->crc = crc32(0, Z_NULL, 0); // inicializacija + uuid->crc = crc32(uuid->crc, &uuid->serial, 1); // dodamo serijsko + uuid->crc = crc32(uuid->crc, uuid->uuid_byte, sizeof(uuid->uuid_byte)); // dodamo vse byte UUIDja +}; + +void print_uuid(struct uuid_uint128 uuid) +{ + // funkcija je samo alias za ta dolgovezni printf + printf("%08d-%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x %08x\n", + uuid.serial, + uuid.uuid_byte[0], + uuid.uuid_byte[1], + uuid.uuid_byte[2], + uuid.uuid_byte[3], + uuid.uuid_byte[4], + uuid.uuid_byte[5], + uuid.uuid_byte[6], + uuid.uuid_byte[7], + uuid.uuid_byte[8], + uuid.uuid_byte[9], + uuid.uuid_byte[10], + uuid.uuid_byte[11], + uuid.uuid_byte[12], + uuid.uuid_byte[13], + uuid.uuid_byte[14], + uuid.uuid_byte[15], + uuid.crc + ); +} + +int main(void) +{ + srand(time(NULL)); // seed RNG + struct uuid_uint128 uuid; + for (int i = 0; i < 100; i++) // zaradi racunanja serijske in CRC je maksimum 255 iteracij + { + get_uuid(&uuid); + print_uuid(uuid); + } + +}