howtothings.co.uk
PI text encrypter for the insomniac. - Printable Version

+- howtothings.co.uk (https://www.howtothings.co.uk)
+-- Forum: Computing (https://www.howtothings.co.uk/forumdisplay.php?fid=4)
+--- Forum: Programming Support, Graphic Design and Tutorials (https://www.howtothings.co.uk/forumdisplay.php?fid=14)
+--- Thread: PI text encrypter for the insomniac. (/showthread.php?tid=953)



PI text encrypter for the insomniac. - latch - 16-08-2011

Last year, I posted some encrypted text here to see if any Mcomputers had a 'Good Will Hunting Beautiful Mind.' Evidently not. Since I wrote the encrypter in Python 2.6, it seemed fitting to post the source here. This program has no useful function unless you are passing secret messages to your buddy who possesses the same script possibly via email, but it was fun to dream up and write. There are a few artifacts in the decryption, but it is plenty readable. Play with it, it is fun.

Code:
string=raw_input('Enter the text to be encrypted or you will die: ')
newstring=''
length=len(string)
print length
print
pi='314159265358979323846264338327950'
pipos=0
for num in range(0,length):
    val=ord(string[num])
    pival=ord(pi[pipos])-48
    print chr(val+pival),''' change the + to - while decrypting this line isn't even needed- more like a progress bar- something to look at'''
    if string[num]!=' ':newstring=newstring+chr(val+pival)# change the + to - to decrypt
    else:newstring=newstring+' '
    if pipos==32:
  pipos=0
    else: pipos=pipos+1
print
print
print newstring
print

I picked that position of pi truncation because it is at that point the first zero occurs and I wanted all the numbers of the decimal system represented therein.