How To: C++ Hash Cracker

C++ Hash Cracker

This is my first ever how-to so I apologize in advance for any grammar mistakes or spelling errors.


This is what I'm planning on being a series of c++ coding articles. This one in particular are gonna be a series of programs for various password cracking methods. Mind you, if you are gonna be a script kiddie please at least try to bother learning the language.


Obviously all programs don't just pop out of the air, but take time to plan what's gonna be in the final product.


  • Be able to allow the user to input a hash
  • Be able to allow the user to input a text file for dictionary attack
  • Be able to take each word in text file and compare to the hash
  • Be able to tell the user which password matches with the hash

I should mind you that this type of attack requires a rainbow table like file.

Code Part 1

So now we must do actual code:

char string inHash()
char string passHash

cout << "Enter in the password hash: \n" <<
cin >> passHash >>

Firstly we must be able to allow to type any hash that we please and store that hash in a variable for future reference. The 'char string inHash()' is pretty much separating this part of the code from the rest so that we may concentrate on this part individually. Pretty simple, eh?

Code Part 2

Now the main big part of the code:

int main()

ifstream inFile;
string fileName;

cout << "Enter in File: \n" <<
cin >> fileName >>

Obviously for all you educated in this programming language you can tell what I'm doing here. ifstream is part of a declaration that I haven't bothered to mention until now

#include <cstido>
#include <cstdlib>
#include <fstream>
#include <cstring>
#include <string>

These are all the declarations that is part of this program and should be at the top before the rest of the code.

Code Part 3

Ok so now since we got the file saved in a variable we must now be able to read and compare the contents of the file to the hash right?

int nLine = 1
int nNewline

getline (fileName, line nline);

While nLine != passHash
nNewline = nLine + 1
nLine = nNewline
getline (fileName, line nNewline);

I've actually used a simple equation to check each line by line. The 'getline(fileName, line nNewline);' is where the program takes each line that equals to the equation 'nNewline = nLine + 1' and compares that line to the hash. The while loop was the best option for this type of method, thus this program continues until nLine = passHash.

Code Part 4

cout << "The password is: \n" <<
<< passHash "=" nLline <<

cout << "Press Enter to exit" <<
return 0;

Of course we needed to finish the program up in a nice and tidy way and thus if you can't flatly see, pretty much the program tells what the password is.


Please leave your comments down below and give me some loveins. I would gladly take any ways to improve in both my how-to's and my coding. Finally, feel free to test this code out and edit the code as you like. :D

The link to the full code is down below, mind you that I did add my own little gizmo to the code, but here it is:

Oh, I didn't test the code out ;)

Just updated your iPhone? You'll find new features for Podcasts, News, Books, and TV, as well as important security improvements and fresh wallpapers. Find out what's new and changed on your iPhone with the iOS 17.5 update.


Nice! +1

As a side note, it's much easier to take screenshots of your source code and upload them instead of typing your code out, the editor isn't very code friendly!

Also, if you could please link the source code through pastebin! It makes the whole process much easier!


Thank you.... and I'm on a chromebook so there's a few issues with the whole screen shots.

Ah, I understand completely!


Good tutorial! +1

Just FYI: You're missing quite a lot of semicolons. Not only did you not test the code, but you must not have compiled it either.

Share Your Thoughts

  • Hot
  • Latest