Created
September 5, 2016 12:37
-
-
Save Compro-Prasad/d39b02742e797e336496b1bf1d4c1bbd to your computer and use it in GitHub Desktop.
Program to character based brute force attempts to break your password. It doesn't store your passwords.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This program is free to modify, distribute, redistribute and | |
execute on any machine on this planet. So feel free and go ahead. | |
*/ | |
/* | |
This is not real hacking with the help of brute force algorithm. | |
But i would say i have neither seen a brute force attack nor | |
its source code. | |
So this C/C++ program is all about my own combination of generating | |
passwords in an order that starts from scratch till the combination | |
order finds a match. | |
The password is first taken as input from the user then its the | |
program's work to find the number of tries taken by my brute | |
force algorithm to reach the correct password. | |
Inputs : Password, Print interval of tries and character information | |
Output : Password generated currently and tries after specified the print | |
interval of tries | |
And at last the correct password along with number of tries | |
Note : This neither does any sniffing attack nor stores any of your | |
passwords to any file. So lie down and wait after you have | |
given your input untill the program finds out the number of | |
tries to reach your password. | |
*/ | |
#include <string.h> | |
#include <iostream> | |
#include <stdio.h> | |
#include <math.h> | |
#define PASSWORD_FOUND 1 | |
#define FINDING_PASSWORD 0 | |
char password[1000] = ""; | |
long double tries_interval = 0.0; | |
long double tries = 0.0; | |
using namespace std; | |
bool login(char *temp_password) | |
{ | |
tries++; | |
if (!fmod(tries, tries_interval)) | |
printf("Password Combination: \"%s\", Tries: %.0Lf\n", temp_password, tries); | |
if (!strcmp(temp_password, password)) | |
{ | |
printf("\nCorrect Password = \"%s\", Tries = %.0Lf", temp_password, tries);/* Printing correct password with number of tries taken */ | |
return PASSWORD_FOUND; | |
} | |
return FINDING_PASSWORD; | |
} | |
int main() | |
{ | |
char resume; | |
do | |
{ | |
password[0] = 0; | |
tries_interval = -1.0; | |
tries = 0.0; | |
printf("Enter your password : "); | |
cin.getline(password, 1000, '\n'); | |
printf("Enter print interval of number of tries executed : "); | |
while (tries_interval < 0.0) | |
cin >> tries_interval; | |
++stdin->_IO_read_ptr; | |
bool f = true; | |
char sc, lc, uc, d; | |
printf("Does password contains lowercase letters?(y/n): "); | |
scanf("%c", &lc), ++stdin->_IO_read_ptr; | |
printf("Does password contains uppercase letters?(y/n): "); | |
scanf("%c", &uc), ++stdin->_IO_read_ptr; | |
printf("Does password contains special characters?(y/n): "); | |
scanf("%c", &sc), ++stdin->_IO_read_ptr; | |
printf("Does password contains digits?(y/n): "); | |
scanf("%c", &d), ++stdin->_IO_read_ptr; | |
/* checking */ | |
for (unsigned int k = 0; password[k]; k++) | |
if (islower(password[k]) && lc != 'y' || | |
isupper(password[k]) && uc != 'y' || | |
isdigit(password[k]) && d != 'y' || | |
(!iscntrl(password[k]) && | |
!islower(password[k]) && | |
!isupper(password[k]) && | |
!isdigit(password[k]) && sc != 'y') | |
) | |
f = false; | |
if (f) | |
{ | |
char first, last; | |
char last_of_group1 = 127, last_of_group2 = 127, last_of_group3 = 127; | |
char first_of_group2 = 127, first_of_group3 = 127, first_of_group4 = 127; | |
if (sc == 'y' && lc == 'y' && uc == 'n' && d == 'n') | |
first = 32, last = 126, last_of_group1 = 47, first_of_group2 = 58, last_of_group2 = 64, first_of_group3 = 91; | |
else if (sc == 'y' && lc == 'n' && uc == 'y' && d == 'n') | |
first = 32, last = 90, last_of_group1 = 47, first_of_group2 = 58, last_of_group2 = 96, first_of_group3 = 123; | |
else if (sc == 'y' && lc == 'n' && uc == 'n' && d == 'y') | |
first = 32, last = 126, last_of_group1 = 64, first_of_group2 = 91, last_of_group2 = 96, first_of_group3 = 123; | |
else if (sc == 'n' && lc == 'y' && uc == 'y' && d == 'n') | |
first = 65, last = 122, last_of_group1 = 90, first_of_group2 = 97; | |
else if (sc == 'n' && lc == 'y' && uc == 'n' && d == 'y') | |
first = 48, last = 122, last_of_group1 = 57, first_of_group2 = 97; | |
else if (sc == 'y' && lc == 'n' && uc == 'n' && d == 'n') | |
first = 32, last = 126, last_of_group1 = 47, first_of_group2 = 58, | |
last_of_group2 = 64, first_of_group3 = 91, last_of_group3 = 96, first_of_group4 = 123; | |
else if (sc == 'n' && lc == 'y' && uc == 'n' && d == 'n') | |
first = 97, last = 122; | |
else if (sc == 'n' && lc == 'n' && uc == 'y' && d == 'n') | |
first = 65, last = 90; | |
else if (sc == 'n' && lc == 'n' && uc == 'n' && d == 'y') | |
first = 48, last = 57; | |
else if (sc == 'y' && lc == 'y' && uc == 'y' && d == 'n') | |
first = 32, last = 126, last_of_group1 = 47, first_of_group2 = 58; | |
else if (sc == 'y' && lc == 'y' && uc == 'n' && d == 'y') | |
first = 32, last = 126, last_of_group1 = 64, first_of_group2 = 91; | |
else if (sc == 'y' && lc == 'n' && uc == 'y' && d == 'y') | |
first = 32, last = 126, last_of_group1 = 96, first_of_group2 = 123; | |
else if (sc == 'n' && lc == 'y' && uc == 'y' && d == 'y') | |
first = 48, last = 122, last_of_group1 = 57, first_of_group2 = 65, last_of_group2 = 90, first_of_group3 = 96; | |
else if (sc == 'y' && lc == 'y' && uc == 'y' && d == 'y') | |
first = 32, last = 126; | |
char ch[] = {first, 0}, c[1000] = {first, 0}; | |
int i = strlen(c) - 1, p; | |
printf("Finding password by Brute Force algorithm.\n"); | |
printf("It may take some time.\n"); | |
while (login(c) == FINDING_PASSWORD)/* main algorithm */ | |
{ | |
c[i]++, p = i; | |
while (c[p] > last) | |
{ | |
c[p] = first; | |
if (p-- != 0) | |
c[p]++; | |
} | |
if (p < 0) | |
{ | |
strcat(c, ch); | |
i++; | |
} | |
else | |
c[p] = (c[p] == last_of_group3 + 1 ? first_of_group4 : | |
c[p] == last_of_group2 + 1 ? first_of_group3 : | |
c[p] == last_of_group1 + 1 ? first_of_group2 : c[p]); | |
} | |
} | |
else | |
cout << "Password doesnt match your options."; | |
cout << "\nEnter again?(y/n) : "; | |
scanf("%c", &resume), ++stdin->_IO_read_ptr; | |
} while (resume == 'y'); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment