Python is a great programming language & could it be used for many useful purposes & save a lot of hard work as well as time. Here is my one story: I once forgot the password of one my Winrar archive file (.RAR) as, I did not have the password, I was not able to extract my .RAR archive file. However, I did remember some parts of my password. It was a combination of word and some numbers. 🙂

But the problem was that there were a lot of possible passwords and to manually try all of these password combinations was not time-saving at all

I had to right click the .RAR archive file, click extract, then a password prompt would appear. I had to manually type the password and try them all. This was going to be a long night.  Well, finally python came to my escape! 


Fortunately, the Winrar software support command line interface. I decided to create a dictionary based password cracking tool using python. 😀

All I needed to do was to create a list of the possible passwords in a text file and then I would use my python script to automate the whole process by trying all the passwords one-by-one. Once the correct password is found the script will exit immediately. 


The python code is provided below: 

from subprocess import Popen, PIPE
import sys, time
print ”’

Author: Prab 🙂

Usage: fileName dictionary
fileName = Name of the .RAR file
dictionary = Password dictionary
if len(sys.argv) > 2:
    fileName = sys.argv[1]
    dictionary = sys.argv[2]
    print “The filename you entered is: %s \n”%fileName
    print “The dictionary you entered is: %s \n”%dictionary
    dictFile = open(dictionary)
    passwords =
    for password in passwords:
            cmd = “unrar.exe t %s -p%s” %(fileName, password)
            print cmd+”\n”
            print “Trying %s as password” %password
            p = Popen(cmd , shell=True, stdout=PIPE, stderr=PIPE)
            out, err = p.communicate()
            print err.rstrip()
            if p.returncode == 0:
                print “\n SUCCESS the pssword is -> %s \n”%password
            print ‘\n############################\n’
   print “Finished trying all the passwords.”

Usage Example

I shall demonstrate an example. I have created a .RAR archive named secret.rar and it is password protected. I have created a dictionary file with a list of some passwords. The python script will check each password in the dictionary file and then display the provide us the correct password! First of all you need the Urar.exe file from WinRar installation directory. Usually, it is located at C:\Program Files\WinRAR , as shown in the screenshot below.

Unrar.exe location

I have created a dictionary.txt file that contains a list of the passwords. The content is shown:

dictionary.txt File

Now, I shall execute my python script to find the correct password. I shall use the Windows CMD to execute my script.  The script requires two parameters, the first one is the .RAR file name & second is the dictionary file name. 

> Parameter1 Parameter2



> secret.rar dictionary.txt



secret.rar is the password protected RAR archive & the dictionary.txt is the dictionary file.

The result is shown in the image below, the python script tries each password in the list & at founded the correct password at last!

Python script in action


The script took 1-2 seconds to complete. If I had to do check each password manually, it would take approx. 5 minutes or more. What if the dictionary contained 100 passwords? 😉

Well from that day on, I started using Password Manager. 😀
I hope you find this helpful! Please feel free to ask questions or provide your suggestion or opinions.

Thanks  🙂

For more articles from this author:

Your Remaining Votes (within 24hrs) : 10 of 10
16 votes, average: 5.00 out of 516 votes, average: 5.00 out of 516 votes, average: 5.00 out of 516 votes, average: 5.00 out of 516 votes, average: 5.00 out of 5 (16 votes, average: 5.00 out of 5)
You need to be a registered member to rate this.
(2622 total tokens earned)


  1. Teutonium

    I got to start learning python, it’s very useful and it’s the most basic coding language there is… Have you tried creating a game for a blockchain using python? Or is it a little to hard for you?

    1. Prab Post author

      I would recommend it. I started learning python when I was a student for a project & I am not a professional python coder, to be honest. Yes, a game might be a bit challenging & depends upon what type of game it is, because of the graphics & other stuff..