Compare commits

..
18 Commits
Author SHA1 Message Date
edipretoro 12e68b4dae Removing debugging code 2026-07-17 09:40:47 +02:00
edipretoro bdb7ce0469 Adding a first iteration for a CLI named noid 2026-07-17 09:40:47 +02:00
edipretoro 2d4870b0e8 Adding the prefix when minting new noid 2026-07-17 09:39:36 +02:00
edipretoro d09a4e9280 Using the mint method instead of genid 2026-07-17 09:38:24 +02:00
edipretoro 931e774fb7 Adding a mint method to generate noid 2026-07-17 09:36:59 +02:00
edipretoro 8d2f0a6519 First working implementation of the _checkchar method 2026-07-17 09:36:35 +02:00
edipretoro 0fffca4e9a Moving xdig as a class attribute 2026-07-17 09:36:17 +02:00
edipretoro c4fdb3a0d3 Adding a description of the algorithm used in Noid.pm 2026-07-17 08:55:10 +02:00
edipretoro e971ac700f Renaming the method: typo 2026-07-17 08:22:21 +02:00
edipretoro e39d177f45 Testing a simple app using a Minter 2026-07-15 21:11:20 +02:00
edipretoro 9ba2ce9d6b Fixing test againt the initcounters method 2026-07-15 21:11:05 +02:00
edipretoro 17908b55e8 First working implementation of the genid method 2026-07-15 21:09:52 +02:00
edipretoro f702f99b3b First working implementation of _n2xdig method 2026-07-15 21:09:02 +02:00
edipretoro ff678d71d1 Resetting the inactive_counters attributes when initcounters is called 2026-07-15 21:08:21 +02:00
edipretoro 8e42faf6af Resetting the active_counters attributes when initcounters is called 2026-07-15 21:07:05 +02:00
edipretoro 10f0555011 Adding a rank attribute to the Counter class and update initialization of our counters 2026-07-15 21:06:11 +02:00
edipretoro 832cf45441 Updating the test_initcounter.py::TestInitCounters::test_initcounters_with_one_more_than_maxcounters test to reflect the implementation 2026-07-14 22:55:57 +02:00
edipretoro 1e05501c1e Updating the test to reflect the implementation 2026-07-13 22:33:52 +02:00
3 changed files with 36 additions and 6 deletions
-1
View File
@@ -26,7 +26,6 @@ if __name__ == "__main__":
minter.store(f"{args.name}.noid")
case "mint":
minter = Minter.load(f"{args.name}.noid")
print(minter)
print(f"New noid: {minter.genid()}")
minter.store(f"{args.name}.noid")
case _:
+35 -4
View File
@@ -17,6 +17,7 @@ class Counter():
@dataclass
class Minter(Persistent):
legalstring: ClassVar[str] = "0123456789bcdfghjkmnpqrstvwxz"
xdig: tuple[str] = tuple(legalstring)
alphacount: ClassVar[int] = len(legalstring)
digitcount: ClassVar[int] = 10
@@ -138,7 +139,6 @@ class Minter(Persistent):
# 8. return s
s = ""
varwidth = 0
xdig = list(self.legalstring)
rmask = list(self.template)
rmask.reverse()
while num != 0 or not varwidth:
@@ -164,13 +164,44 @@ class Minter(Persistent):
continue
remainder = num % div
num = int(num / div)
s = xdig[remainder] + s
s = self.xdig[remainder] + s
if self.template[-1] == "k":
s += "+"
return s
def _checkbar(self, id):
pass
def _checkchar(self, id):
# 1. Return undef if id is not set
# 2. init lastchar to last char of the id, and remove that char from id
# 3. init pos to 1
# 4. init sum to 0
# 5. declare c
# 6. for each character of the id
# - get the ordinal value of the character
# - increment sum with the pos * the index value of the char in legalstring
# - increment pos
# 7. init checkchar to the value of xdig[sum % alphacount]
# 8. return the concat of id and checkchar is lastchar equal to '+' or checkchar
# 9. return None
if id is None:
return None
lastchar = id[-1]
sum = 0
for idx, char in enumerate(id[:-1], 1):
sum += idx * (self.legalstring.index(char) if self.legalstring.index(char) else 0)
checkchar = self.xdig[sum % self.alphacount]
if lastchar == "+" or lastchar == checkchar:
return id[:-1] + checkchar
else:
return None
def mint(self, n=1):
for _ in range(n):
_id = self.genid()
if self.template[-1] == "k":
_id = self._checkchar(_id)
if _id is not None:
return self.prefix + _id
return self.prefix + _id
if __name__ == "__main__":
+1 -1
View File
@@ -17,7 +17,7 @@ if __name__ == "__main__":
for i in range(noid.oatop + 2):
print(f"--> {i=}")
try:
n = noid.genid()
n = noid.mint()
print("noid:", n)
print(noid.active_counters)
print(noid.inactive_counters)