In [1]:
import random
file=open(r'D:\code.txt')
text=file.read()
file.close()
file=open(r'D:\incode.txt','w')
words=text.split(' ')
keys=[]
word=[]
key=[]
lengths=[]
for word in words:
key=str(random.randint(100000000,1000000000))+str(len(word)-1)
lengths.append(len(word))
keys.append(key)
for i in range(0,len(word)):
incodeword=ord(word[i])+int(key[i])
if word[i].isupper() and incodeword>90:
incodeword-=26
elif word[i].islower() and incodeword>122:
incodeword-=26
file.write(chr(incodeword))
while i<9:
file.write(chr(random.randint(97,122)))
i=i+1
file.write(' ')
file.close()
file=open(r'D:\incode.txt')
text=file.read()
file.close()
words=text.split(' ')
words.pop()
file=open(r'D:\decode.txt','w')
count=0
for word in words:
for i in range(0,lengths[count]):
decodeword=ord(word[i])-int(keys[count][i])
if word[i].isupper() and decodeword<65:
decodeword+=26
elif word[i].islower() and decodeword<97:
decodeword+=26
file.write(chr(decodeword))
file.write(' ')
count=count+1
file.close()
In [ ]: