Startpage Register Members Search Help
  Login/Logout My Profile Private Messages  

Topic View [682] - Message Cipher Source Code

» Startpage - Nz17 Productions
» Nz17 Productions
  » Commonplace Chat
    · Message Cipher Source Code

0 Replies and 260 Clicks (0.10 Clicks/day)
Rating: None
Currently also reading: nobody

Style for Topic View:
Flat view Threaded view
Highlight word:

Print view Recommend posting Watch posting Report posting
offline  nz17
 Fearless Leader
 User StatusUser StatusUser StatusUser StatusUser StatusUser Status
 Topic starter Moderator

nz17 (Sean Robinson)
Profile
Sex: male
Postings: 405
0.10 Postings/day
since 07.05.2006
last Tuesday, 05:40h
from: Utah
usa

Level: 20
Experience: 100995/105000
   Show single posting
  Monday, 26 April 2010 14:56:16 +0000 ( 7y 5m 26d 20h 8m 22s )
  Subject: Message Cipher Source Code
Attached files
I hope that some of you find this code which I wrote for my message encoder/decoder for our "Secret Cypher Announcement" useful. The forum ate all the whitespace characters for this, so if you want to run the program please download the file attached to this forum post. (Or use a program smart enough to auto-indent the source code.)

#!/usr/bin/env python
####
# Copyright 2010 Nz17 Productions, Sean Robinson
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
####

# Encode a message by reversing the alphabet (a=>z, b=>y, etc.)
def reverseAlphabet(message):
cyphered = ""

for v in message:
if ord(v) >= ord('a') and ord(v) <= ord('z'):
cyphered += chr(ord(v) + 25 - (ord(v) - ord('a')) * 2)
elif ord(v) >= ord('A') and ord(v) <= ord('Z'):
cyphered += chr(ord(v) + 25 - (ord(v) - ord('A')) * 2)
else:
cyphered += v

return cyphered

# Encode a message by stepping each letter back by one (a=>z, b=>a, etc.)
def oneStepBack(message):
cyphered = ""

for v in message:
if ord(v) > ord('a') and ord(v) <= ord('z'):
cyphered += chr(ord(v) - 1)
elif ord(v) == ord('a'):
cyphered += 'z'
elif ord(v) > ord('A') and ord(v) <= ord('Z'):
cyphered += chr(ord(v) - 1)
elif ord(v) == ord('A'):
cyphered += 'Z'
else:
cyphered += v

return cyphered

# Encode a message by stepping each letter forward by one (a=>b, b=>c, etc.)
def oneStepForward(message):
cyphered = ""

for v in message:
if ord(v) >= ord('a') and ord(v) < ord('z'):
cyphered += chr(ord(v) + 1)
elif ord(v) == ord('z'):
cyphered += 'a'
elif ord(v) >= ord('A') and ord(v) < ord('Z'):
cyphered += chr(ord(v) + 1)
elif ord(v) == ord('Z'):
cyphered += 'A'
else:
cyphered += v

return cyphered

# Main section
runAgain = 'y';

while runAgain == 'y':
message = raw_input("Please input message to encypher/decypher: "winking
print

print "[Available cyphers]"
print "1) Reverse Alphabet"
print "2) One Step Back"
print "3) One Step Forward"
print
cypherMethod = raw_input("Please select cypher to use: "winking

print
print message
if cypherMethod == '1':
print reverseAlphabet(message)
elif cypherMethod == '2':
print oneStepBack(message)
elif cypherMethod == '3':
print oneStepForward(message)
print

runAgain = raw_input("Convert another message (y/n)? "winking
print
Reply Quote reply Write Mail Write PN

Vote topic
You cannot vote on this object due to missing permissions.
Topic-Navigation