Enquirer Home Page | Twitter | Back to Improbable Island

 Forum Index > Off-Topic > Out-of-Game New Topic Post Reply
 The Corporal's Cypher - decoder program
 |  Printable Version
wvf
 Saturday, October 01 2011 @ 09:15 AM UTC (Read 5040 times)  
Forum Badass
Badass


Status: offline

Registered: 08/30/08
Posts: 70

Hello, my comrades in arms! (Especially you mutants!) I've developed a small program, written in Python, to help decode the cyphers we've been seeing between Corporal Punishment and Sgt. Stern.

For instance, given

PHP Formatted Code
SEFUB ZRVD BQGZSKBDBH PBFFEJB KBDB,
CVU OBEWB LQ UKB TVRUEULRQ PEDNF.
and the partial cypher
PHP Formatted Code
ZEBR SC FGHIJKLMNOPQTUVWXY
we get back
PHP Formatted Code
Missing characters in cipher: AD
PeSTE YOUR ENCYPHEREh MESSeGE HERE,
BUT LEeVE IN THE QUOTeTION MeRKS.

The capitals are ciphered output, the lower-case letters are unciphered output. Can you guess where the missing letters go? Razz

Here is the python file, cipher.py. It runs on python 2. Enjoy. Post questions here.
PHP Formatted Code
#cipher.py translates incomplete ciphers. For python 2. (Released under gnu gpl by David D. Roberts on 2011. Contact: email at robertsdavidddr@gmail.com)
#run command in console: "python cipher.py" (Without the quotation marks.)
src =   "ZEBR SC FGHIJKLMNOPQTUVWXY" #You put the normal alphabet on the top to encipher. Reverse to decipher. Leave spaces in src for unknown letters. src is what the message is currently in, dst is what you want it to be.
dst =   "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #These two strings must be equal length.

message = """

SEFUB ZRVD BQGZSKBDBH PBFFEJB KBDB,
CVU OBEWB LQ UKB TVRUEULRQ PEDNF.

"
"" #This, above, is what gets translated.

lacking = ''
for character in dst:
        if not character.upper() in src.upper():
                lacking += character
if len(lacking) > 0:
        print "Missing characters in cipher:", lacking, "\n"

def cipher(char):
        if not char.isalpha(): #string not cypherable
                return char
        letter = dst.upper().find(char.upper()) #String not in destination. (incomplete alphabet)
        if letter == -1:
                return '*'
        letter = src[letter:letter+1]
        if letter == ' ':
                return char.lower()
        return letter

deciphered = ''
for character in message:
        deciphered += cipher(character)
print deciphered
 


(Yes, I expect there's a website out there that will happily decipher the messages for me, and possibly even figure out the cipher, but that would be... cheating. Somehow. And this isn't. Rolling Eyes )


 
Profile Email
Quote
Content generated in: 0.16 seconds
New Topic Post Reply



 All times are UTC. The time is now 02:26 PM.

Normal Topic Normal Topic
Locked Topic Locked Topic
Sticky Topic Sticky Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Anonymous users can post 
Filtered HTML Allowed 
Censored Content