Hi,so I am supposed to encrypt a text file chosen by a user at the moment I have completed most of it (offset factor/shift), I have got each separate character from the text file and put it into a list and converted it into ASCII, I am wondering how you are meant to change the ASCII number 32(space) into an actual space to separate the list and only them. Then i will need to create a string based on this and save it onto the user's computer and i am not too sure how to do this either.
Any help/advice will be appreciated
Thanks very much!
Here is the code:
import random #=============================================Main Menu============================================= print("Hi, Welcome to Text Encyrption") print("This program will encrypt or decrypt a text file chosen by you.") print('Make a choice') print('1. Encrypt Message') print('2. Decrypt Message ') print('3. Exit program ') print() #the user only has 3 choices menu_choice = 0 #menu_choice cannot = 3 while menu_choice != 3: menu_choice = int(input("Choose an option (1-3): ")) #=====================================Encryption======================================================= if menu_choice == 1: print("ENCRYPTING MESSAGE") print("For this task the file is Text File1.txt") text_file = input(str("Enter the file you want to be Encyrpted")) #this will find the text file the user has inputter apple = open(text_file,"r") #this puts the text file so it can only be read apple =(apple.read()) print(apple) n = 0 number = [] texting = [] #================================Offset Factor=================================================== #while n is less than 8 while n<8: #it will convert a random number between 33 and 126 into ascii random_number = chr(random.randint(33, 126)) print(random_number) #every time n + 1 #one turn out of 8 n = n + 1 #the number is put into ascii characters = ord(random_number) #it is put into the number list number.append(characters) print(number) #this rounds each of the eight integers in number and divides by 8 and takes away 3 offset_number = round((number[0]+number[1]+number[2]+number[3]+number[4]+number[5]+number[7])/8)-32 #this prints the offset factor print(offset_number) #=============================Task 5===================================================================== newString = [] #this is the only part of ascii allowed validLetters = "#$%&'()*+,-./:;<=>?@[\]^_`{|}~""#$%&'()*+,-./0123456789:;<=> @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghiklmnopqrstuvwxyz{|}~" space = [' '] new = [] old = [] x = 0 #this splits the text file into singukar characters from 0 to 1 chrsplit = [apple for i in range(0, len(apple),1)] #this puts into ascii every character ascii_conversion = [ord(a) for a in chrsplit] #this replaces each 32 in the list with a space ascii_conversion = [s.replace('32', ' ') for s in ascii_conversion] #this prints it print(ascii_conversion)
https://community.esri.com/people/curtvprice/blog/2014/09/25/posting-code-blocks-in-the-new-geonet