Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. def main():
  2. random.seed(125)
  3. #Get the file to encrypt
  4. file = input('Enter a name of a text file to mix: ')
  5. print()
  6. #open the file that will be encrypted
  7. log = open(file, 'r')
  8. #open the index file that keeps track of how the encryption works
  9. index_file = open('index.txt', 'w')
  10. #open the file where the encrypted text will be placed
  11. encrypted_file = open('encrypted.txt', 'w')
  12. contents = []
  13. encrypted_contents = []
  14. for i in log:
  15. contents.append(i)
  16. indexs = []
  17. for i in range(1, len(contents) + 1):
  18. indexs.append(i)
  19. for i in indexs * 5: #randomize the index
  20. randomize(indexs)
  21. for i in indexs:
  22. encrypted_contents.append(contents[i - 1])
  23. for i in range(len(indexs)): #write into the encrypted file and the index file
  24. encrypted_file.write(encrypted_contents[i])
  25. index_file.write(str(indexs[i]) + '\n')
  26. index_file.close()
  27. encrypted_file.close() #Always close opened files.
  28. log.close()
  29.  
  30. def randomize(indexs): #This function randomizes the order to encrypt the code.
  31. random_number_one = random.randint(0, len(indexs) - 1)
  32. random_number_two = random.randint(0, len(indexs) - 1)
  33. value_one = indexs[random_number_one]
  34. value_two = indexs[random_number_two]
  35. indexs[random_number_one] = value_two
  36. indexs[random_number_two] = value_one
  37.  
  38. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement