: : Hi. I'm new to this Python language and I've been doing this project for the last two weeks:
: :
: : Write an n-stepped encryption program.
: :
: : This is a little different from what I told you in class, so follow these instructions.
: :
: :
: : The user should be able to set the number of steps that the encoding algorithm uses.
: :
: : The program should only encrypt upper-case letters, spaces and numbers (any other character in the message should remain unencrypted).
: : The user should create a text file with an unencrypted message. The program should create a second text file, which is the encrypted message.
: :
: :
: :
: : Coding Steps:
: :
: : 1. write a function encrypt that takes in a string and a step and implements an n-step encryption algorithm, returning the result
: : 2. write a load function, that reads in all the data in a file
: : 3. write a write function, that writes a string to a file
: : 4. Write a program flow based around these functions
: : 5. Write a program, using functions 1 through 3, to accomplish the assignment.
: :
: : AND I'M STILL EXPERIENCING PRBLEMS.This is what I've come up with so far:
: :
: : def read():
: : a=open("news.txt","r")
: : text=a.read()
: : a.close
: : return text
: : print
: :
: :
: : def encrypt(string,n):
: : result=[]
: : for char in string:
: : x=ord(char)
: : x+=2
: : result.append(chr(x))
: : return str(result)
: :
: : def write(string):
: : b=open("output.txt","w")
: : b.write(string)
: : b.close()
: : string=[]
: : write(string)
: : Can someone please help me. It's due on Monday.
:
: Sorry I didn't get to this until it was "too late". You made a good effort, so I'm willing to show you how I would've done it:
:
:
: import string
: encryptable = string.ascii_uppercase + string.digits + string.whitespace
:
: def read(path):
: f = open(path,"r")
: text = f.read()
: f.close()
: return text
:
: def encrypt(s, step=1):
: result=[]
: for c in s:
: if c in encryptable:
: x = ord(c) + step
: result.append(chr(x))
: else:
: result.append(c)
: return ''.join(result)
:
: def write(path, s):
: f = open(path,"w")
: f.write(s)
: f.close()
:
:
: Let me know if you still need help or don't understand anything here, or if you'd like a more thorough analysis of anything.
:
:
:
:
infidel
:
:
: $ select * from users where clue > 0
: no rows returned
:
:
: Thank you so much.I really do appreciate it.