Respuesta :
Answer:
The following are the program in the Python Programming Language.
#get input from the user
inputFile = input("Enter the input file name: ")
#get input from the user
outputFile = input("Enter the output file name: ")
#get input from the user
dist = int(input("Enter the distance value: "))
#open file for only read
infile = open(inputFile, "r")
#open file for only write
outfile = open(outputFile, "w")
#read lines from the file
get = infile.readlines()
#set the for loop
for text in get:
#set variable as empty string variable
code = ""
#then, set the for loop
for char in text:
#store the unicode of the variable
Value = ord(char)
#perform calculation
cipher = Value + dist
#check that the calculation is greater than 127
f(cipher > 127):
#then, again perform another calculation
cipher = dist - (127 - Value | 1)
#convert it into the character
code += chr (cipher)
#write the following converted character in it.
outfile.write(code)
Explanation:
The following are the description of the program.
- Firstly, set three variables 'inputfile', 'outputfile' and 'dist' that get input from the user, the first one gets the input file name, second one gets the output file name and the last one gets the distance.
- Then, set two variables 'infile' and 'outfile' which open the 1st file for only read and second one open file for only write then, set the variable 'get' that read the line from the read-only file.
- Set the for loop that stores that lines in the variable 'text' and then, set the empty string type variable 'code'. Set the for loop that store the variable of the 'text' in the 'char' then, set the variable 'Value' that store the Unicode of the variable 'char' and perform calculation between the variables 'Value' and 'char' and store it in the variable 'cipher'.
- Then, set the if conditional statement that checks the variable 'cipher' is greater than 127 and perform the another calculation, then convert the variable 'cipher' into the character and store it in the variable 'code'.
- Finally, we close all the following open files.