Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- random.seed(125)
- #Get the file to encrypt
- file = input('Enter a name of a text file to mix: ')
- print()
- #open the file that will be encrypted
- log = open(file, 'r')
- #open the index file that keeps track of how the encryption works
- index_file = open('index.txt', 'w')
- #open the file where the encrypted text will be placed
- encrypted_file = open('encrypted.txt', 'w')
- contents = []
- encrypted_contents = []
- for i in log:
- contents.append(i)
- indexs = []
- for i in range(1, len(contents) + 1):
- indexs.append(i)
- for i in indexs * 5: #randomize the index
- randomize(indexs)
- for i in indexs:
- encrypted_contents.append(contents[i - 1])
- for i in range(len(indexs)): #write into the encrypted file and the index file
- encrypted_file.write(encrypted_contents[i])
- index_file.write(str(indexs[i]) + '\n')
- index_file.close()
- encrypted_file.close() #Always close opened files.
- log.close()
- def randomize(indexs): #This function randomizes the order to encrypt the code.
- random_number_one = random.randint(0, len(indexs) - 1)
- random_number_two = random.randint(0, len(indexs) - 1)
- value_one = indexs[random_number_one]
- value_two = indexs[random_number_two]
- indexs[random_number_one] = value_two
- indexs[random_number_two] = value_one
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement