Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Encoder:
- import random
- text = input("Please input a text: ")
- text = list(text)
- print(text)
- l = (text.__len__()) * random.randint(10000, 20000) #random-generated characters for each input-text character
- print(l)
- dec1 = list()
- code = list()
- i = 0
- while i < l:
- dec1.append(random.randchar())
- i = i + 1
- print(dec1)
- dec = list()
- filename = input("Please choose a file name (without file-extension): ")
- filedec = open(filename + ".dec", "w")
- for i in dec1:
- dec.append(str(i))
- pos1 = 0
- for i in text:
- pos1 = random.randint(0, l)
- for i2 in dec:
- while str(pos1) in i2:
- pos1 = random.randint(0, l)
- dec[pos1] = i
- code.append(pos1)
- decstr = ""
- for i in dec:
- decstr = decstr + str(i)
- filedec.write(decstr)
- filecode = open("Decipher.txt", "w")
- filecode.write(str(code))
- Decoder:
- from ast import literal_eval
- datei = input("choose a file to decode (with file-extension): ")
- decipher = literal_eval(input("input the decipher.txt: "))
- filedec = open(datei, "r")
- dec = list(filedec.read())
- text = ""
- for i in decipher:
- text = text+dec[i]
- print(text)
Advertisement
Add Comment
Please, Sign In to add comment