944,138 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 22265
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 20th, 2006
0

Creating Bruteforce Program

Expand Post »
I'm interested in creating a bruteforce program. What is the most computer resource efficient method to count in base 62? (1,2,3...a,b,c...A,B,C)
Similar Threads
Reputation Points: 13
Solved Threads: 1
Light Poster
portege is offline Offline
26 posts
since Jul 2006
Jul 20th, 2006
0

Re: Creating Bruteforce Program

probably something like below: count using normal integers but convert to base62 for display.

C++ Syntax (Toggle Plain Text)
  1. #include <cstring>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main( )
  6. {
  7. long n = 1234576;
  8. char buf[255];
  9. _itoa( n, buf, 62 );
  10. cout << buf << "\n";
  11. return 0;
  12. }

Warning: The above code is not ansi standard. Here is a link you might be able to use if you need something ansi standard.

[edit]I have done a little testing with the algorithms in the link I posted and none of them produce the same result as _itoa() function. The first algorithm for my_atoi() might be a fairly simple fix -- it just leaves off the last digit.[/edit]
Last edited by Ancient Dragon; Jul 20th, 2006 at 6:53 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005
Jul 20th, 2006
0

Re: Creating Bruteforce Program

Well here is a c++ version that should be portable and returns the same as itoa().

C++ Syntax (Toggle Plain Text)
  1. string my_itoa(int value, int base)
  2. {
  3. string s;
  4. for(int i = base; value && i ; --i, value /= base)
  5. {
  6. s = "0123456789abcdefghijklmnopqrstuvwxyz"[value % base] + s;
  7. }
  8. return s;
  9.  
  10. }
Last edited by Ancient Dragon; Jul 20th, 2006 at 8:48 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005
Nov 13th, 2009
-3
Re: Creating Bruteforce Program
The problem here is that it wouldn't be able to crack a string such as 000 or 0zzz
Reputation Points: 9
Solved Threads: 0
Newbie Poster
combustion is offline Offline
4 posts
since Nov 2009
Nov 14th, 2009
0
Re: Creating Bruteforce Program
Here's my code, tested for errors:
c++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. 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'};
  5. string t;
  6. void checkPassword(string password);
  7. void recurse(int width, int position, string baseString);
  8. int main() {
  9. cout << "Enter a string: " << endl;
  10. cin >> t;
  11. int maxChars = 13;
  12. for(int i=0;i<maxChars+1;i++) {
  13. cout << "checking passwords width [" << i << "]..." << endl;
  14. recurse(i,0,"");
  15. }
  16. return 0;
  17. }
  18. void recurse(int width, int position, string baseString) {
  19. for(int i=0;i<35;i++) {
  20. if (position < width-1) {
  21. recurse(width, position + 1, baseString+chars[i]);
  22. }
  23. checkPassword(baseString+chars[i]);
  24. }
  25. }
  26. void checkPassword(string password) {
  27. if (password==t) {
  28. cout << "match [" << password << "]" << endl;
  29. exit(1);
  30. }
  31. }
it cracks the string h3ar7 in 16 seconds on my computer.
Reputation Points: 9
Solved Threads: 0
Newbie Poster
combustion is offline Offline
4 posts
since Nov 2009
Dec 10th, 2009
-1
Re: Creating Bruteforce Program
There should be 36 in for loop
regards
Reputation Points: 10
Solved Threads: 0
Newbie Poster
burmix is offline Offline
1 posts
since Dec 2009
Dec 10th, 2009
0
Re: Creating Bruteforce Program
>>it cracks the string h3ar7 in 16 seconds on my computer.

Thats pretty slow. There is no reason to use recursion here.
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,865 posts
since Dec 2008
Mar 8th, 2011
-1
Re: Creating Bruteforce Program
How do i find out what the password is after it cracks it?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Shadowlala is offline Offline
1 posts
since Mar 2011
Jun 27th, 2011
-1
Re: Creating Bruteforce Program
Great algo combustion! I have one question can anyone tell me a way with combustions code to make it so it will start with given characters? I've tried a few things but they always seem to reset back to the beginning.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Hereticbeast is offline Offline
3 posts
since Jun 2011
Jun 27th, 2011
0
Re: Creating Bruteforce Program

C++ Syntax (Toggle Plain Text)
  1. s = "0123456789abcdefghijklmnopqrstuvwxyz"[value % base] + s;
offtopic:I'm having trouble understanding this line, so you're initializing s with "01..yz"
but what does the
C++ Syntax (Toggle Plain Text)
  1. [value % base] + s
part actually do?
Last edited by CPT; Jun 27th, 2011 at 7:22 am.
CPT
Reputation Points: 10
Solved Threads: 0
Newbie Poster
CPT is offline Offline
22 posts
since Aug 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: converting STL vector size_type to const?
Next Thread in C++ Forum Timeline: General problem I have with functions causing a loop - any suggestions?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC