Кодування 4 || Рандом





...

Made by GGsmou import asyncio import js from pyodide import ffi import random ALLDIC = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я', 'ґ', 'є', 'і', 'ї', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я', 'Ґ', 'Є', 'І', 'Ї', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '^', '_', '`', '{', '|', '}', '~', '№', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' '] dicShuffle = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я', 'ґ', 'є', 'і', 'ї', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я', 'Ґ', 'Є', 'І', 'Ї', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '^', '_', '`', '{', '|', '}', '~', '№', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' '] num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] def split(s): return [char for char in s] def split2(s): result = [] i = 0 while i < len(s): if ord(s[i]) >= 0xD800 and ord(s[i]) <= 0xDBFF: result.append(s[i:i+2]) i += 2 else: result.append(s[i]) i += 1 return result def listToString(s): str1 = "" for ele in s: str1 += ele return str1 def shuflle(seed): dicShuffleNew = dicShuffle[:] random.Random(seed).shuffle(dicShuffleNew) return (dicShuffleNew) codeButton = js.document.getElementById('code') decodeButton = js.document.getElementById('decode') def codeFunc(*args, **kwargs): text = Element('codez').element.value textsplit = split2(text) code = [] if len(textsplit) == 1: dicShuffleNew = shuflle("ChSW") if textsplit[0] in ALLDIC: code.append(dicShuffleNew[ALLDIC.index(textsplit[0])]) else: code.append(textsplit[0]) else: for i in range(len(textsplit)): seed = textsplit[-1] if i == 0 else code[i - 1] dicShuffleNew = shuflle(seed) if textsplit[i] in ALLDIC: code.append(dicShuffleNew[ALLDIC.index(textsplit[i])]) else: code.append(textsplit[i]) Element('output').write(f'{listToString(code)}') def decodeFunc(*args, **kwargs): code = Element('decodez').element.value codesplit = split2(code) codesplit = [i for i in codesplit[::-1]] text = [] if len(codesplit) == 1: dicShuffleNew = shuflle("ChSW") if codesplit[0] in ALLDIC: text.append(ALLDIC[dicShuffleNew.index(codesplit[0])]) else: text.append(codesplit[0]) else: for i in range(len(codesplit)): seed = text[0] if i == len(codesplit) - 1 else codesplit[i + 1] dicShuffleNew = shuflle(seed) if codesplit[i] in ALLDIC: text.append(ALLDIC[dicShuffleNew.index(codesplit[i])]) else: text.append(codesplit[i]) text = [i for i in text[::-1]] Element('output').write(f'{listToString(text)}') cc = ffi.create_proxy(codeFunc) ccD = ffi.create_proxy(decodeFunc) codeButton.addEventListener('click',cc) decodeButton.addEventListener('click',ccD)