How To: Create an Encryption Program with Python

Create an Encryption Program with Python

Hello, fellow grey hat hackers and aspiring coders. I'm back again with another python tutorial. Just that this one is gonna be a lot cooler ;-). We gonna make an encryption program, that well you know encrypts all the files on your pendrive or hdd or whatever you want....Also lots of thanks to DrapsTV. They have helped me a lot with Python and making awesome programs. The video is here:

But don't watch it. Read my article...lol

StoryTime

So, I was watching Mr. Robot(Duh!!) and I was just impressed by how he encrypted his stuff with DeepSound and I have already seen OTW's tutorial on that, but I've been a script kiddie for too long and it's annoying that I can't go back even if I want to(lol!!). But anyway I wanted to make my own you know.

Besides imagine if you mess up real bad and the FBI comes knocking on your door and you know you got so much evidence on your computer and you going to jail...lol...you can just run this program and erase your hdd so even if forensics manages to pull your stuff back. It's encrypted and you might get away with it. ;-)

Also, I also wanted to do this because I wanted to make a ransomware(SHUT UP!! I'm grey hat I get bored sometimes). But I ain't gonna do it! ( or am i? muhahaha!!!)...lmao ok...now the code...hehehehe!!!!

Step 1: Import Modules

You know you gotta do this. Some of the modules, you gonna have to download it. So download pycrypto if you don't have it ok... :-)

Don't worry about the pkg-resources. That's just because I was converting it to exe with pyinstaller and it was giving me problems...but you can add it if you gonna convert it to exe as well...I guess....

Step 2: Create Encryption Part

Now this is the bomb...the encryption part I mean...this function is where all the encryption takes place...

So I'm gonna try and explain everything as best as I can.

We are using AES encryption so we will have to encrypt it in 64 bits( I think...I'm not sooo sure about the technicalities that's in the video)

But anyway you have to create an Initialization Vector(IV) that's for the encryption process and we will have to get the filesize so we can get rid of things in the file that are not needed during decryption...you will see when we get there....

Step 3: Now Decryption - FBI's Part

So you see we gonna need the IV that we stored in the file to add to our decryptor object so we can decrypt our stuff....so the truncate makes sure it gets the exact file(something like that....)

Step 4: The Main Program

This part just asks the user for the password, whether he wants to encrypt or decrypt and does the work ...

As you can see the allfiles function does a traverse of all the files in the current directory and stores it in an array which will be the files been encrypted. And also I made sure it doesn't encrypt twice and it doesn't encrypt the encryption program.(Ain't I sweet?) <3 <3 XD XD

The password will be converted to SHA256 because it will have a total of 16 characters and AES needs the number of characters of the key to be equivalent to 16 so there we go.

Same for decryption except we don't want to decrypt all the files(that's just stupid) so you can only decrypt one file at a time.....

Conclusion

That's it...This article was written in a rush. Besides I suck at writing articles so yeah....

I'm sorry if it sucks but I figured the site needed some fresh blood.(Literally, I'm a vampire...am kidding) But you know what I mean.

So that is the code, and you can have fun encrypting files on your drives. just put it in the root directory of your drive and run it....

WARNING: If you try and decrypt the file with a wrong password you will forever lose access to the file. So you might as well just delete it...lol

And the code is here on pastebin: http://pastebin.com/PthzX9Bf

Forget to leave you with something....

Matthew 6:33 - "But seek ye first the kingdom of God, and His righteousness and all these things shall be added unto you!!"

Just updated your iPhone? You'll find new emoji, enhanced security, podcast transcripts, Apple Cash virtual numbers, and other useful features. There are even new additions hidden within Safari. Find out what's new and changed on your iPhone with the iOS 17.4 update.

16 Comments

Excellent post! Also great job citing a video as well as walking through each step thoroughly. Wonderful all around.
+1 Kudos

Thanks a lot mahn!! Appreciate it

Nice explanation. always struggle with programming, this looks well enough demonstrated to have a go at. Cheers. x

Thanks, All the best....And thanks for following me.

So what if we wanted to create our own small encryption outside of AES (it wouldn't fool the feds, but it could be a fun project lol)? If you could do a tutorial on how the encryption functions here work/are written that would make my day! Thanks for the great content so far!

Hmm... I love it but I kind of want to modify the script so it doesnt show my password!

import getpass

password = getpass.getpass("Enter Password: ")

i cant decrypt after encrypting, it says file does not exit if i should type in the name of file to decrypt. i have accidentally encrypt most my file in the root. please help me

you should have given the an option to select which file to encrypt rather the encrypt all files selection in your program, think that will make it a little bit safe.

When i copied the code from pastebin and when i typed it all myself i get this error:
"File "C:\Users\JordanPlayz\Desktop\encrypt.py", line 68
print "%s is already encrypted" %str(Tfiles))"
----------------------------------------------^ (Dashes weren't there)
SyntaxError: invalid syntax

What version of python are you using to run this. What's the output of python --version

Lets upload it to VirusTotal!! Haha

Great, though it shows the password...
Simple fix

import getpass

password = getpass.getpass("Enter Password: ")

Types everything
"And here is the code: *Pastebin link* "

hello, I got this error

can some body help me ?

Share Your Thoughts

  • Hot
  • Latest