# def preroute(spellword):
#     spellword = spellword.strip()
#     spellword = spellword.split("/")[0]
#     spellword = spellword.split(".")[0]
#     spellword = spellword.replace("-", " ")
#     spellword = spellword.replace("_", " ")
#     spellword = spellword.replace("'", " ")
#     spellword = spellword.split(" ")
#     return [subword.strip() for subword in spellword if not subword.strip() == ""]

# def paratangle(data):
#     return [
#         hex(zlib.adler32(data.encode("utf-8")))[2:],
#         hex(zlib.crc32(data.encode("utf-8")))[2:]
#     ]

# def get_authenticity(stringtoshorten):
#     stringtoshorten = stringtoshorten.strip()
    
#     strtokens = preroute(stringtoshorten)#stringtoshorten.replace("-", " ").replace("_", " ").replace("'", " ").split(" ")
#     chainA12Y = list()
#     pretanglants = ["-".join(paratangle(stringtoshorten))]
#     print(strtokens)
#     print(pretanglants)
#     for talkEn in strtokens:
#         print(talkEn)
#         pretanglants.append("-".join(paratangle(talkEn)))
#         if len(talkEn)>3:
#             chainA12Y.append([
#                 talkEn.lower()[0],
#                 len(talkEn),
#                 talkEn.lower()[-1]
#             ])
#         else:
#             chainA12Y.append([
#                 "_",
#                 talkEn.upper()
#                 ])
#     chainA12Y.append(list(set(pretanglants)))
#     return chainA12Y

# def routingA12Y(spellword):
#     wordchain = get_authenticity(spellword)
    
    
#     #word.replace("-", " ").replace("_", " ").replace("'", " ").split(" ")

# lineindex = 0
# with open("./slowa.txt", "r") as wordgame_sjp_file:
#     linereader = wordgame_sjp_file.readline()
#     while not linereader == "":
#         if linereader[-1] == "\n":
#             linereader=linereader[-1]
#         routingA12Y(linereader)





import unicodedata
import zlib
import re

def preroute(spellword):
    spellword = spellword.strip()
    spellword = spellword.split("/")[0]
    spellword = spellword.split(".")[0]
    spellword = spellword.replace("-", " ")
    spellword = spellword.replace("_", " ")
    spellword = spellword.replace("'", " ")
    spellword = spellword.split(" ")
    return [subword.strip() for subword in spellword if not subword.strip() == ""]

def get_i13l_text(input_str):
    output_str = unicodedata.normalize('NFKD', input_str)
    output_str = output_str.encode('ASCII', 'ignore')
    output_str = output_str.decode('ASCII')
    return output_str

def paratangle(data):
    return [
        hex(zlib.adler32(data.encode("utf-8")))[2:],
        hex(zlib.crc32(data.encode("utf-8")))[2:]
    ]

def check_a12y(testdata):
    acsii_letter_pattern = '[a-zA-Z]'
    check = re.compile(acsii_letter_pattern)
    return (check.match(testdata[0]) and check.match(testdata[-1]))

def a12y(input_str):
    output_str = []
    if len(input_str) and check_a12y(input_str):
        output_str = [
            input_str.lower()[0],
            str(len(input_str)),
            input_str.lower()[-1]
        ]
        
    else:
        output_str = [
            "0",
            "-",
            hex(ord(input_str[0]))[2:],
            "-",
            hex(len(input_str))[2:],
            "-",
            hex(ord(input_str[-1]))[2:]
        ]
    return "".join(output_str)

def get_authenticity(stringtoshorten):
    stringtoshorten = stringtoshorten.strip()
    
    strtokens = preroute(stringtoshorten)#stringtoshorten.replace("-", " ").replace("_", " ").replace("'", " ").split(" ")
    chainA12Y = list()
    pretanglants = ["-".join(paratangle(stringtoshorten))]
    #print(strtokens)
    #print(pretanglants)
    for talkEn in strtokens:
        #print(talkEn)
        pretanglants.append("-".join(paratangle(talkEn)))
        if len(talkEn) and check_a12y(talkEn):
            print(check_a12y(talkEn))
            chainA12Y.append([
                talkEn.lower()[0],
                len(talkEn),
                talkEn.lower()[-1]
            ])
        else:
            chainA12Y.append([
                "0",
                hex(ord(talkEn[0]))[2:], 
                len(talkEn),
                hex(ord(talkEn[-1]))[2:]
                ])
    chainA12Y.append(list(set(pretanglants)))
    return chainA12Y

def routingA12Y(spellword):
    wordchain = get_authenticity(spellword)
    return wordchain[:-1]
    
    
    

# Example with international text
text = "mącenie- d 12"
normalized = get_i13l_text(text)
print(preroute(normalized))
print(routingA12Y(normalized))
print(a12y("sodoromolo"))
print(a12y("sodoromolo12"))