python - Script encrypts, but still saves the plaintext instead of the ciphertext -


i have issue current program supposed take user input, encrypt allowing choose how want shift by, save file. unknown reasons program seems capable of saving file missing out encryption. appreciated.

text = "abcdefghijklmnopqrstuvwxyz 1234567890-=!£%^&*"  def main():     #if want save file after encrypting if statement     ans = input("would save file of read file, press w or r").lower()      if ans == "w":         text = input("what text want enter").lower()          caeser(text)         save_file()      elif ans == "r":         text = input("what file name want enter").lower()         caeser(text)  # organise loop & function def caeser(text):     shift = int(input("how shift?: "))     shifted_list = []     letter in text:         character_lower = letter.lower()         ascii = ord(character_lower)         shift = shift % 26         shifted_letter = ascii + shift         shifted_char = chr(shifted_letter)         shift_loop = shifted_letter - 26         shift_loop_char = chr(shift_loop)         if shifted_letter >= 97 , shifted_letter <= 122:             shifted_list.append(shifted_char)             text = ''.join(shifted_list)         elif shift_loop >= 97 , shift_loop <= 122:             shifted_list.append(shift_loop_char)             text = ''.join(shifted_list)         else:             shifted_list.append(character_lower)             text = ''.join(shifted_list)         encrypted = text     return encrypted  # save file shouldnt return text def save_file(text):     name = input("enter filename")     file = open(name, "w")     file.write(text)     file.close()  #load file shouldnt recieve parameter   # error protection needs added   def load_file(text):     name = input("please enter file name")     file = open(name, "r")     text = file.read()     file.close()     return text 

python strings immutable. need change this:

# returns encrypted text , nothing caeser(text) # saves 'text' module-level namespace, since send nothing save_file() 

to this:

# send encrypted text returned 'caesar(text)' save_file save_file(caeser(text)) 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -