Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: text file encryption/decryption program! rate it!
PostPosted: February 23rd, 2006, 8:44 pm 
Runite Member
User avatar
Offline

Joined: October 16th, 2005, 4:06 pm
Posts: 446
Location: In ur forumz, postin mah thredz
RS Status: Classic
my programming teacher and I came up with a "scramble" and "unscramble" python code that allows people to encrypt their text files so that they are unreadable, and then fix them again at any time. here is how to do it:

    copy the code below into notepad or a python editor; for mac users, i think you use "textedit" or a python editor; i am unsure how to do this for linux; and save as a .py in the same folder as the file you wish to alter

    run the file like you would an application, or open a text file: just double-click on it

    follow the input menus and press "enter" or "return" after you enter the information at each prompt


voila! an encrypted/decrypted file!

oh, and here is the code:
Code:
#Text encryption program.
#Written by Asa S. and Ben A.
#----------------------------------

import binascii, string

#This function converts an integer to hexadecimal
def iToHex(a):
    div=a/16
    rem=a%16
    if rem==10: rem="a"
    if rem==11: rem="b"
    if rem==12: rem="c"
    if rem==13: rem="d"
    if rem==14: rem="e"
    if rem==15: rem="f"
    if div > 0:
        return (str(iToHex(div)) + str(rem))
    else:
        return (str(rem))

#This funciton converts an ascii character to an integer
def aTob(as):
    bs=binascii.b2a_hex(as)
    return (int(bs,16))

#This function converts an integer to an ascii character   
def bToa(sb):
    e=iToHex(sb)
    if len(e)%2:
        e="0"+e
    return (binascii.a2b_hex(e))

# Scramble file function
#--------------------------------------------
def scrambleFile (srcName, destName):
    #Open src
    f=open(srcName, "r")
    #Read its contents
    s=f.read()
   
    #Close src
    f.close()

    #Open dest
    f=open(destName, "w")
    #Write the contents
    for x in s:
        if x<>"":
            #Convert our unencrypted text to a number
            num=aTob(x)
            #Shift that character over by 15 and wrap it
            num=num+10       
            if num>255:
                num=num-256
            #Convert the new encrypted number back to a character
            ascii=bToa(num)
            #Write that character into the file
            f.write(ascii)
       
    #Close dest
    f.close()
#--------------------------------------------
   
#Unscramble file function
#--------------------------------------------
def unscrambleFile (srcName, destName):
    #Open src
    f=open(srcName, "r")
    #Read its contents
    s=f.read()

    #Close src
    f.close()

    #Open dest
    f=open(destName, "w")
    #Write the contents
    for x in s:
        #If "x" isn't blank:
        if x!="":
            #Convert our encyrpted text into a number
            num=aTob(x)
            #Shift that character over by 15 and wrap it
            num=num-10
            if num<0:
                num=num+256
            #Convert the new unencrypted number back to a character
            ascii=bToa(num)
            #Write that character back into the file
            f.write(ascii)

    #Close dest
    f.close
#---------------------------------------
#Call functions in an infinite loop
while True:
    #Ask what the user wants to do
    function=input("Enter 1 to encrypt; enter 2 to decrypt; enter 3 to quit. >>> ")
    #See if the user wants to encrypt a file
    if function==1:
        x=raw_input("Enter the name of the file you wish to encrypt. >>> ")
        print ("Encrypting file...")
        scrambleFile(x, x)
        print ("Encryption successful.")
        see=input("Press 1 to read " + x + "; press 2 to continue to the main menu. >>> ")
        #Ask if they want to read the file
        if see==1:
            openx=open (x, "r")
            readx=openx.read()
            print (readx)
        if see==2:
            pass
    #See if the user wants to decrypt a file
    if function==2:
        x=raw_input("Enter the name of the file you wish to decrypt. >>> ")
        print ("Decrypting file...")
        unscrambleFile(x, x)
        print ("Decryption successful.")
        see=input("Press 1 to read " + x + "; press 2 to continue to the main menu. >>> ")
        #Ask if they want to read the file
        if see==1:
            openx=open (x, "r")
            readx=openx.read()
            print (readx)
        if see==2:
            pass
    #See if they want to quit; if they do, then break the loop
    if function==3:
        break


have fun :twisted:

_________________
Image

Image

I'm lean, I'm mean... I'm famished. Make me a sandwich.

SOTW Wins
|51|


Top
 Profile  
 
 Post subject: Register and login to get these in-post ads to disappear
PostPosted: February 23rd, 2006, 8:44 pm 
Runite Member

Joined: September 9th, 2004, 1:47am
Posts: 9047
Location: In your web browserz


Top
  
 
 Post subject:
PostPosted: February 26th, 2006, 4:47 pm 
Dragon Member
User avatar
Offline

Joined: March 17th, 2005, 11:44 pm
Posts: 1197
Location: Georgia, USA us
RS Name: Deborahone
RS Status: P2P
Clan Name: Elven Alliance
I cant execute the .py file on my windows pc

_________________
Image
Image
Image
Image
SOTW Judge (Sep 14, 2005 1:38 pm - Feb 06, 2009 8:58 pm)
Spoiler for Everything else:

Image
A Kid asked Jesus, "How much do you love me?" and Jesus said. "This much."
And spread his arms out on the cross and died.
If you believe that he did this for you put this in your signature.


Top
 Profile  
 
 Post subject:
PostPosted: February 26th, 2006, 5:17 pm 
Rsbandb Donor
User avatar
Offline

Joined: December 22nd, 2004, 12:51 am
Posts: 6391
RS Name: Stanley1943
RS Status: F2P
I don't know what this encryption program's purpose is.
If you encrypt it, someone can crack it really easy seeing the algorithm your using there.
Or even faster if they get hold of this script . :wink:

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: February 27th, 2006, 8:37 am 
Dragon Member
User avatar
Offline

Joined: March 17th, 2005, 11:44 pm
Posts: 1197
Location: Georgia, USA us
RS Name: Deborahone
RS Status: P2P
Clan Name: Elven Alliance
youve got a good point there Jeff, maybe you should make this code pm access only kingofrogue0?

_________________
Image
Image
Image
Image
SOTW Judge (Sep 14, 2005 1:38 pm - Feb 06, 2009 8:58 pm)
Spoiler for Everything else:

Image
A Kid asked Jesus, "How much do you love me?" and Jesus said. "This much."
And spread his arms out on the cross and died.
If you believe that he did this for you put this in your signature.


Top
 Profile  
 
 Post subject:
PostPosted: March 7th, 2006, 7:26 pm 
Runite Member
User avatar
Offline

Joined: October 16th, 2005, 4:06 pm
Posts: 446
Location: In ur forumz, postin mah thredz
RS Status: Classic
point well taken... :oops:

it is kinda pointless though. I was just...REALLY bored :P

you can change the way it encrypts by going to the place in the "scrambleFile" and "unscrambleFile" functions where it says to shift the number over by 15 or whatever and change it to the number you like. meaning try this:

Code:
#Shift that character over by a number and wrap it
            num=num-x
            if num<0:
                num=num+256


do that in both of the functions and replace "x" with the number you want. make sure it is the SAME NUMBER though. I'm not very good at explaining troubleshooting :( so if you have trouble, I don't know if I can help you...but I can try :)

_________________
Image

Image

I'm lean, I'm mean... I'm famished. Make me a sandwich.

SOTW Wins
|51|


Top
 Profile  
 
Display posts from previous:  Sort by  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron