Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 11th, 2006, 6:52 PM   #1
jade_casey
Newbie
 
Join Date: Feb 2006
Posts: 2
Rep Power: 0 jade_casey is on a distinguished road
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
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("news.txt","w")
b.write(string)
b.close()
string=[]
write(string)

Can someone please help. I'd really appreciate it.
jade_casey is offline   Reply With Quote
Old Feb 11th, 2006, 7:00 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Feb 12th, 2006, 5:04 AM   #3
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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?
Arevos is offline   Reply With Quote
Old Feb 17th, 2006, 5:32 PM   #4
Sane
Banned
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,101
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
Just a misc fact, pressing quote on their message will show you the the version of their message without removed whitespaces.
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:35 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC