Eudoxys Sciences LLC
mguid Command Line Python Library Package Metadata

Command Line

Generate a GUID using a magic number

Syntax: mguid [OPTION ...]

Options

Description

A magic GUID is a GUID that embeds an encoding related to the source of the GUID. Magic GUIDs can be used to determine whether two GUIDs were generated in the same context. That can be useful for applications that need to check whether a GUID is exogenous, i.e., was the GUID created by another application. It can also be used by a third application to determine whether two GUIDs were generated by two different applications or by the same application.

Magic GUIDs contain a pattern that is uniquely identifiable if the magic number is known. The random option generates a Version 4 GUID using a random magic number. If you know the magic number you can verify that a GUID was generated with the magic number by using the check option. If you have two GUIDs, you can verify that they were generated using the same magic number using the same option.

If you do not specify the magic number, a random magic number is generated the first time you use the random() function. You can set the magic number using the MAGIC module constant, e.g., MAGIC=gen(), MAGIC=123456.

Caveat

Magic GUIDs should not be used for security or identity purposes. Also, because the encoding reduces the number of valid GUIDs the probability of a GUID clash is increased somewhat. For VERSION=0 only 60 bits are available for generating unique GUIDs, meaning that there are only 1,152,921,504,606,846,976 possible magical GUIDs instead of the normal 5,316,911,983,139,663,491,615,228,241,121,378,304 possible muggle Version 4 GUIDs.

Command Line Examples

Generate a GUID using the magic number 123.

$ mguid random=123
f2ac57d8-e3e5-45d4-bf2a-c57d8e3e55af

Check whether the GUID was generated using the magic number 123.

$ mguid check=f2ac57d8-e3e5-45d4-bf2a-c57d8e3e55af,123 && echo ok || echo fail
ok

Check whether the GUID was generated using the magic number 456.

$ mguid check=f2ac57d8-e3e5-45d4-bf2a-c57d8e3e55af,456 && echo ok || echo fail
fail

Generates another GUID using the magic number 123.

$ mguid random=123
2f210452-75be-4d3b-a2f2-1045275bed40

Checks whether the two GUIDs were generated using the same magic number.

$ mguid same=f2ac57d8-e3e5-45d4-bf2a-c57d8e3e55af,2f210452-75be-4d3b-a2f2-1    045275bed40 && echo ok || echo fail
ok

Generate another GUID using the magic number 456.

$ mguid random=456
0a335b25-d565-40fd-80a3-35b25d565135

Check whether the new GUID was generared using the same magic number as the old GUID

$ mguid same=f2ac57d8-e3e5-45d4-bf2a-c57d8e3e55af,0a335b25-d565-40fd-80a3-3    5b25d565135 && echo ok || echo fail
fail

Python Examples

Import the module.

>>> import mguid as mg

Generate a GUID.

>>> mg.random()
0c7d4f21-b322-41183-8086-479cd4100f63e 

Check a GUID.

>>> mg.check(mg.random())
True 

Check whether two GUIDs are generated using the same magic number.

>>> mg.same(mg.random(magic=123),mg.random(magic=123))
True 

Check whether two GUIDs are generated using the same magic number.

>>> mg.same(mg.random(magic=123),mg.random(magic=456))
False 

See also

* https://datatracker.ietf.org/doc/html/rfc9562

Python Library

check(a:str, magic:int) → bool

Check whether a GUID was generated using a magic number

Arguments

Returns

gen() → int

Generate a N-bit random number

Arguments

Returns

main([list[str] | None]) → int

Main CLI

Arguments

Returns

random(magic:int) → int

Generate a GUID using a magic number

Arguments

Returns

same(a:str, b:str) → bool

Check whether two GUIDs were generated using the same magic number

Arguments

Returns

trick(a:int, magic:int, version:int) → int

Generate the check code using the magic number

Arguments

Returns

validate() → None

Run validation tests

Python Constants

E_ERROR = 1

E_EXCEPTION = 2

E_OK = 0

MAGIC = None

VERSION = 0

Package Metadata

Name:mguid
Version:0.0.0a1
Description:GUIDs that are verifiably generated with magic number
Authors:David P. Chassin
Maintainers:David P. Chassin
Requires-Python:>= 3.10
Dependencies:None
Keywords:guid
magic
License:MIT License
Classifiers:Development Status :: 3 - Alpha
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Programming Language :: Python :: 3 :: Only
Topic :: Software Development :: Libraries
Urls:Homepage = https://github.com/eudoxys/mguid
Documentation = https://mguid.gitub.io/
Repository = https://github.com/eudoxys/mguid.git
Issues = https://github.com/eudoxys/mguid/issues
Scripts:mguidmain()

Copyright © 2024 David P. Chassin