![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2006
Posts: 2
Rep Power: 0
![]() |
Encryption Help
I'm a newbie to this Python language and I've had 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. This is what I've come up with so far: def read(): a=open("news.txt","r") text=a.read() a.close return text 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("news.txt","w") b.write(string) b.close() string=[] write(string) Can someone please help. I'd really appreciate it. |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
As you're a first-time poster, I would recommend you read the forum's rules/FAQ and a "How to Post..." thread.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Surrounding your code in [code] tags would certainly help. Since Python relies on indentation, it's somewhat hard to evaluate your code without it.
Also, what exactly do you mean by n-stepped? From your code it looks like you're shifting each ascii character by 2n places, but was this the end result you were after? |
|
|
|
|
|
#4 |
|
Banned
![]() ![]() |
Just a misc fact, pressing quote on their message will show you the the version of their message without removed whitespaces.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|