Frustrated Python Coder
Frustrated Python Coder

Reputation: 1593

How to make a python script that encrypts any type of file

I'm trying to make my programs for the public (freeware) and I just want to know the code for making a file encrypted. (Python language 2.7.3)

Upvotes: 1

Views: 3291

Answers (2)

Rahul Gautam
Rahul Gautam

Reputation: 4837

here what you need

def encoder(path,pwd,topath):
    """
    @path: file path you wish to encrypt including filename
    @pwd: seek value 'you should remember that if you want to decrypt it'
    @topath: file path for encrypted file included filename
    """
    k = long(pwd) # key   # password in int
    f1 = open( path, "rb") # file path you wish to encrypt
    bytearr = map (ord, f1.read() ) 
    f1.close()
    f2 = open( topath, "wb" ) # path for encrypt file to write
    random.seed(k)
    for i in range(len(bytearr)):
        byt = (bytearr[i] + random.randint(0, 255)) % 256
        f2.write(chr(byt))
    f2.close()        

Have you tried to search google for it, or even stackoverflow.

Upvotes: 3

Oren
Oren

Reputation: 2807

Check out PyCrypto

You can also search for native python implementations, but they will be less efficient.

Upvotes: 3

Related Questions