Jump to content

Python Help

Red Dragon
Go to solution Solved by Nineshadow,
-/-

Because you only go through the lower case letters in the for (0-26). You should also keep in mind you have numbers.

Hello guys ill just cut to the chace. I'm doing a python brute force program for a school project the goal of it is you enter a sting of letters and numbers then it goes though every combination of letters and number untill it gets it. im pretty sure im going to need a list im just not sure how to cycle though the list and then combine different parts of the list to form a string to compare against the password that would be stored in a variable. here is what i have so far even though it is quite barebones and dosent really accomplish anything 

 

import timelistoflist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z','1', '2', '3', '4', '5', '6', '7', '8', '9', '0']guess = 'a'def Mememaker:	password = input('Gimmie Ur Password Boi')	while guess =! password:

(do note that i will clean up the names after i figure this whole thing out lol it just makes me happy when i write my variables :) )

 

Any help will be greatly appreciated thank you in advanced 

 

~ Maybe the cup is just too big ~

Link to comment
Share on other sites

Link to post
Share on other sites

Something like this:

completed=Falsewhile completed==False:    for i in listoflist:        if guess+i==password:            print("Password was: "+guess+i)            completed=True            break    else:        guess+=i

"My game vs my brains, who gets more fatal errors?" ~ Camper125Lv, GMC Jam #15

Link to comment
Share on other sites

Link to post
Share on other sites

You might want to read this : https://docs.python.org/2/library/itertools.html#itertools.combinations

 

In c++, something like this :

const char AlphabetUpper[26] ={    'A', 'B', 'C', 'D', 'E', 'F', 'G',    'H', 'I', 'J', 'K', 'L', 'M', 'N',    'O', 'P', 'Q', 'R', 'S', 'T', 'U',    'V', 'W', 'X', 'Y', 'Z'};const char AlphabetLower[26] ={    'a', 'b', 'c', 'd', 'e', 'f', 'g',    'h', 'i', 'j', 'k', 'l', 'm', 'n',    'o', 'p', 'q', 'r', 's', 't', 'u',    'v', 'w', 'x', 'y', 'z'};// Recursive function, keeps clocking characters// until length is reachedvoid Generate(unsigned int length, std::string s){    if(OK)    {        if(s == str)        {            OK = false;            std::cout << "Found string " << s;            return;        }        if(length == 0) // when length has been reached        {            std::cout << s << "\n"; // print it out            return;        }        for(unsigned int i = 0; i < 26; i++) // iterate through alphabet        {            // Create new string with next character            // Call generate again until string has reached it's length            std::string appended = s + AlphabetLower[i];            Generate(length-1, appended);        }    }}void Crack(){    while(1)    {        // Keep growing till I get it right        static unsigned int stringlength = 1;        Generate(stringlength, "");        stringlength++;    }}int main(){    str = "yes";    std::cout << "Attempting to crack...\n";    Crack();}

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Edit for @fizzlesticks correction

 

itertools.permutations won't take into account repeated characters, itertools.product will. Link here. You may have some performance problems depending on how large the word is though. The number of possible options grows very large very fast.

Word Length | Number Of Possibilities-------------------------------------          3 |                 238,328          4 |              14,776,336          5 |             916,132,832 # at this point it starts taking a long time to loop through the results          6 |          56,800,235,584In case you are wondering how you can calculate these numbersFormula: p = n^kwhere p = number of possibilities      n = number of input options (a-z, A-Z, 0-9 = 62 input options)      k = length of string you are guessing ("password" has a length of 8)For example - Use the formula to get all possibilities of an 8 letter wordp = 62 ^ 8 = 218,340,105,584,896
Link to comment
Share on other sites

Link to post
Share on other sites

I believe itertools.permutations is the correct method to use based on the requirements.

Assuming it's a normal password that can have repeated characters, itertools.product would be the function to use.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Assuming it's a normal password that can have repeated characters, itertools.product would be the function to use.

 

Damn, I never noticed permutations skipped repeated characters. I kinda felt like something was up when the formula I thought I remembered, p = n^k, wasn't matching up with the results from permutations.

Link to comment
Share on other sites

Link to post
Share on other sites

 

Edit for @fizzlesticks correction

 

itertools.permutations won't take into account repeated characters, itertools.product will. Link here. You may have some performance problems depending on how large the word is though. The number of possible options grows very large very fast.

Word Length | Number Of Possibilities-------------------------------------          3 |                 238,328          4 |              14,776,336          5 |             916,132,832 # at this point it starts taking a long time to loop through the results          6 |          56,800,235,584In case you are wondering how you can calculate these numbersFormula: p = n^kwhere p = number of possibilities      n = number of input options (a-z, A-Z, 0-9 = 62 input options)      k = length of string you are guessing ("password" has a length of 8)For example - Use the formula to get all possibilities of an 8 letter wordp = 62 ^ 8 = 218,340,105,584,896

 Hey thank you for the help! Do i assign the product of this to a variable for a while loop or does this replace the while loop entirely. it it replaces the whole thing what am i going to have to use compare the output against the variable for the password. I read the documentation on itertools.product but im still unsure on how to use its output. Thank you in advanced :)

~ Maybe the cup is just too big ~

Link to comment
Share on other sites

Link to post
Share on other sites

 Hey thank you for the help! Do i assign the product of this to a variable for a while loop or does this replace the while loop entirely. it it replaces the whole thing what am i going to have to use compare the output against the variable for the password. I read the documentation on itertools.product but im still unsure on how to use its output. Thank you in advanced :)

 

You can loop over the results like so

import itertoolsinput = "abc...890"  # didn't want to type out everything but you get the idealength = 3  # for getting 3 letter wordsfor product in itertools.product(input, repeat=length):    # use product for something    # product will be a tuple like    # ('a', 'a', 'a')
Link to comment
Share on other sites

Link to post
Share on other sites

@madknight3 ok so somethign like this should work 

import itertoolslist1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z','1', '2', '3', '4', '5', '6', '7', '8', '9', '0']password = raw_input('Gimmie Ur Password Boi')while true		variablename1 = itertools.product(list , [4])    if password = variablename1:         print it worked

do i have to convert the user input into a tuple or will it just work automagicly thank you for all your help so far :) 

~ Maybe the cup is just too big ~

Link to comment
Share on other sites

Link to post
Share on other sites

 

You might want to read this : https://docs.python.org/2/library/itertools.html#itertools.combinations

 

In c++, something like this :

const char AlphabetUpper[26] ={    'A', 'B', 'C', 'D', 'E', 'F', 'G',    'H', 'I', 'J', 'K', 'L', 'M', 'N',    'O', 'P', 'Q', 'R', 'S', 'T', 'U',    'V', 'W', 'X', 'Y', 'Z'};const char AlphabetLower[26] ={    'a', 'b', 'c', 'd', 'e', 'f', 'g',    'h', 'i', 'j', 'k', 'l', 'm', 'n',    'o', 'p', 'q', 'r', 's', 't', 'u',    'v', 'w', 'x', 'y', 'z'};// Recursive function, keeps clocking characters// until length is reachedvoid Generate(unsigned int length, std::string s){    if(OK)    {        if(s == str)        {            OK = false;            std::cout << "Found string " << s;            return;        }        if(length == 0) // when length has been reached        {            std::cout << s << "\n"; // print it out            return;        }        for(unsigned int i = 0; i < 26; i++) // iterate through alphabet        {            // Create new string with next character            // Call generate again until string has reached it's length            std::string appended = s + AlphabetLower[i];            Generate(length-1, appended);        }    }}void Crack(){    while(1)    {        // Keep growing till I get it right        static unsigned int stringlength = 1;        Generate(stringlength, "");        stringlength++;    }}int main(){    str = "yes";    std::cout << "Attempting to crack...\n";    Crack();}

 alright ive looked into it and figured i should just use c++ i did find a program very similar to this on the internet and tried to fix it up myself

i ended up at this

#include "stdafx.h"#include <iostream>#include <string>using namespace std;char chars[] = {	'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',	'a', 'b', 'c', 'd', 'e', 'f', 'g',	'h', 'i', 'j', 'k', 'l', 'm', 'n',	'o', 'p', 'q', 'r', 's', 't', 'u',	'v', 'w', 'x', 'y', 'z',	'A', 'B', 'C', 'D', 'E', 'F', 'G',	'H', 'I', 'J', 'K', 'L', 'M', 'N',	'O', 'P', 'Q', 'R', 'S', 'T', 'U',	'V', 'W', 'X', 'Y', 'Z',};// Recursive function, keeps clocking characters// until length is reachedstring password;int num = 0;void Generate(unsigned int length, string s){	if (length == 0) // when length has been reached	{		num = num + 1;		cout << s << "\n";		if (s == password){			cout << "Crack Complet. It took" << num << "tries to complet";			exit(0);		}		else{ return; }	}	for (unsigned int i = 0; i < 26; i++) // iterate through alphabet	{		// Create new string with next character		// Call generate again until string has reached it's length		string appended = s + chars[i];		Generate(length - 1, appended);	}}void Crack(){	while (1)	{		// Keep growing till I get it right		static unsigned int stringlength = 1;		Generate(stringlength, "");		stringlength++;	}}int main(){	cout << "yo its you freindly nabrohood pasta chef gimmie ur password" << endl;	cin >> password;	cout << "Attempting to crack...";	Crack();	return 0;}

but what for some reason it does not include capital letters and numbers when cycling through... do you know why. thank you for helping :)

@Nineshadow

~ Maybe the cup is just too big ~

Link to comment
Share on other sites

Link to post
Share on other sites

-/-

Because you only go through the lower case letters in the for (0-26). You should also keep in mind you have numbers.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Because you only go through the lower case letters in the for (0-26). You should also keep in mind you have numbers.

 Ahh silly me thank you very much :) 

~ Maybe the cup is just too big ~

Link to comment
Share on other sites

Link to post
Share on other sites

 alright ive looked into it and figured i should just use c++ i did find a program very similar to this on the internet and tried to fix it up myself

 

Well...that's one way to solve the problem I guess...

 

I kind of find it funny that you went from an easy Python solution (the hardest part was already given to you) to a recursive C++ solution.

Link to comment
Share on other sites

Link to post
Share on other sites

Well...that's one way to solve the problem I guess...

 

I kind of find it funny that you went from an easy Python solution (the hardest part was already given to you) to a recursive C++ solution.

well... i basically just got frustrated and ditched my original approach because this project was time sensitive because it was for school . side note i don't get why people think recursion is so weird (not specifically you just if found the general consensus is that its really funky)  its just a function things that calls its self... Any way i do thank you for helping along the way :) ☻☺☻

~ Maybe the cup is just too big ~

Link to comment
Share on other sites

Link to post
Share on other sites

well... i basically just got frustrated and ditched my original approach because this project was time sensitive because it was for school

 

That's too bad. Adding a few more lines to the Python solution would have gotten part of the requirements working.

 

Code I posted above

import itertoolsinput = "abc...890" # didn't want to type out everything but you get the idealength = 3 # for getting 3 letter wordsfor product in itertools.product(input, repeat=length):    # use product for something    # product will be a tuple like    # ('a', 'a', 'a') 

After a few changes

import itertoolspassword = tuple("hey")input = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"length = 3for product in itertools.product(input, repeat=length):    if password == product:        print "Solved" 

Then from there, you start modifying it to meet the rest of the requirements.

 

Still, I guess you're fortunate that you were able to change languages. Many people don't have that luxury. If the class was teaching a specific language, I doubt they'd accept a submission in a different language. If your job had you working in a specific language, they might not accept a solution in another language. etc

 

 

side note i don't get why people think recursion is so weird (not specifically you just if found the general consensus is that its really funky)  its just a function things that calls its self...

 

Yeah, recursion isn't weird or anything, it's usually just a more complicated topic for a lot of people who start out learning an imperative language and do everything with loops (which is most programmers).

Link to comment
Share on other sites

Link to post
Share on other sites

  • 3 weeks later...

@madknight3 Hey i Finally got back on the forum after getting slammed by all my class work! My project was about the time it takes to brute force things depending on there length characters ect. so the language didnt matter. however even though this project is done i think im going to try using the program you made to see how it compares against the one i ended up using. Ill get back to you once ive got the results any way thank you for the help YOUR A COOL DUDE xD ha ha ha

~ Maybe the cup is just too big ~

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×