38 lines
1002 B
Python
38 lines
1002 B
Python
import hashlib, uuid, random, string
|
|
|
|
def anki_guid1(text: str) -> str:
|
|
#return hashlib.sha1(text.encode('utf-8')).hexdigest()[:10]
|
|
guid = str(uuid.uuid4())[:10]
|
|
return guid
|
|
|
|
#print(anki_guid1("jag och du"))
|
|
|
|
|
|
def generate_guid():
|
|
chars = string.ascii_letters + string.digits + "!#$%&()*+,-./:;<=>?@[]^_`{|}~"
|
|
return ''.join(random.choices(chars, k=10))
|
|
|
|
|
|
import hashlib
|
|
|
|
# Base91-Zeichensatz wie in Anki
|
|
base91chars = (
|
|
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
|
|
'0123456789!#$%&()*+,-./:;<=>?@[]^_`{|}~'
|
|
)
|
|
|
|
def anki_guid(text: str) -> str:
|
|
# SHA1-Hash des Front-Felds berechnen
|
|
h = hashlib.sha1(text.encode('utf-8')).digest()
|
|
x = int.from_bytes(h[:8], 'little') # Anki nimmt die ersten 8 Bytes, little-endian
|
|
|
|
# Kodierung in Base91-Zeichenkette (10 Zeichen)
|
|
chars = []
|
|
for _ in range(10):
|
|
chars.append(base91chars[x % len(base91chars)])
|
|
x //= len(base91chars)
|
|
|
|
return ''.join(chars)
|
|
|
|
|
|
print(anki_guid("ich und du")) |