ARTICLE AD BOX
I'm new on python, so i know there must be a way better to do this, if you know, please, tell me.
The videos I found talked about using the module "cryptography.fernet", however, looking at the module page, I saw that to use it with password, you need to use some other modules to be able to insert a password, so I tried to do a basic form of encryption with password by myself.
So I got this function you can see, but a problem I’m finding, is that I can not think of a way to implement the code part that scrambles the character list and add the scrambling order to the password to be decrypted.
If you run this code, it will encrypt, but I want to put this scrambling so I can make it safer and maybe someday use it in some project of mine, in case I still can’t use a better way.
If you want, can take and use, but as missing this part is not yet 100%
I'm sorry, my english isnt good.
import random def coddecod (senha, texto, modo = 'd'): '''String <=> List\n texto (String / List) is the text to be coded or decoded.\n modo ('c'/'d') is how the function will be used, it can be 'c' (Encode) or 'd' (Decode).\n senha (String) is the password to be used to encode.\n (Still in construction)\n -MatheusF 06/12/2025''' lista = ["0Mbm1cdA2fga3iTj4thk5Hle6nEo7up8UqrS9vwxyszBCDFGIJKLNOPQRVWXYZ! |@#$%&*()_+-=[]°ºª^~`", 0, "", [], []] for idx, char in enumerate("0" + senha): for i2, c2 in enumerate(lista[0]): if char == c2: lista[1] += i2 * idx if lista[1] == 0: lista[1] += len(senha) if modo == 'c': senha = [] #this part till the 2 "print" is the scrambling code, but isnt conected to the actually encription code so doesnt break, since isnt finnished. step = 0 for _ in range(5): lista[3].append(lista[0][0 + step: 17 + step]) step += 17 dados = [0, 0, 0, 0, 0] while True: teste2 = random.randint(0, 4) if dados[teste2] == 1: continue lista[2] += "".join(lista[3][teste2]) lista[4] += str(teste2) dados[teste2] = 1 if dados[0] + dados[1] + dados[2] + dados[3] + dados[4] == 5: break print(lista[2]) print(lista[4]) for _, char in enumerate(texto): for idx, c2 in enumerate(lista[0]): if char == c2: senha.append(idx * lista[1]) return senha if modo == 'd': s = [] try: for i in range(len(texto)): letra = texto[i] // lista[1] s.append(lista[0][letra]) senha = "".join(s) return senha except: print("Senha errada.") #it allready encrypts the text as you can see when running the code: test = coddecod("FeijaoTropeiro2015", "", "c") print(test) wrong = coddecod("ihfujfk768hih", test, "d") print(wrong) right = coddecod("FeijaoTropeiro2015", test, "d") print(right)It allready works, its basic, but i need help to make better or to change everything for something really better.
