alphabet counter

i need some help getting this code to finish executing in my life time

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 3309 Views - Last Post: 06 January 2009 - 01:31 PM Rate Topic: -----

#1 ben104  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 24-May 08

alphabet counter

Posted 05 January 2009 - 01:25 PM

i need some help to shorten this code so that it finishes faster
#include <cstdlib>
#include <iostream>
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{

		int ccounter[32];
		string ccombo[38];
		string whole_string;
		for (ccounter[1]=0; ccounter[1]<27; ccounter[1]++)
		{		
		for (ccounter[2]=0; ccounter[2]<27; ccounter[2]++)
		{
		for (ccounter[3]=0; ccounter[3]<27; ccounter[3]++)
		{
		for (ccounter[4]=0; ccounter[4]<27; ccounter[4]++)
		{
		for (ccounter[5]=0; ccounter[5]<27; ccounter[5]++)
		{
		for (ccounter[6]=0; ccounter[6]<27; ccounter[6]++)
		{
		for (ccounter[7]=0; ccounter[7]<27; ccounter[7]++)
		{
		for (ccounter[8]=0; ccounter[8]<27; ccounter[8]++)
		{
		for (ccounter[9]=0; ccounter[9]<27; ccounter[9]++)
		{
		for (ccounter[10]=0; ccounter[10]<27; ccounter[10]++)
		{
		for (ccounter[11]=0; ccounter[11]<27; ccounter[11]++)
		{
		for (ccounter[12]=0; ccounter[12]<27; ccounter[12]++)
		{
		for (ccounter[13]=0; ccounter[13]<27; ccounter[13]++)
		{
		for (ccounter[14]=0; ccounter[14]<27; ccounter[14]++)
		{
		for (ccounter[15]=0; ccounter[15]<27; ccounter[15]++)
		{
		for (ccounter[16]=0; ccounter[16]<27; ccounter[16]++)
		{
		for (ccounter[17]=0; ccounter[17]<27; ccounter[17]++)
		{
		for (ccounter[18]=0; ccounter[18]<27; ccounter[18]++)
		{
		for (ccounter[19]=0; ccounter[19]<27; ccounter[19]++)
		{
		for (ccounter[20]=0; ccounter[20]<27; ccounter[20]++)
		{
		for (ccounter[21]=0; ccounter[21]<27; ccounter[21]++)
		{
		for (ccounter[22]=0; ccounter[22]<27; ccounter[22]++)
		{
		for (ccounter[23]=0; ccounter[23]<27; ccounter[23]++)
		{
		for (ccounter[24]=0; ccounter[24]<27; ccounter[24]++)
		{
		for (ccounter[25]=0; ccounter[25]<27; ccounter[25]++)
		{
		for (ccounter[26]=0; ccounter[26]<27; ccounter[26]++)
		{
		for (ccounter[27]=0; ccounter[27]<27; ccounter[27]++)
		{
		for (ccounter[28]=0; ccounter[28]<27; ccounter[28]++)
		{
		for (ccounter[29]=0; ccounter[29]<27; ccounter[29]++)
		{
		for (ccounter[30]=0; ccounter[30]<27; ccounter[30]++)
		{
		for (ccounter[31]=0; ccounter[31]<27; ccounter[31]++)
		{
		for (ccounter[32]=0; ccounter[32]<27; ccounter[32]++)
		{
		for (ccounter[32]=0; ccounter[32]<27; ccounter[32]++)
		{

		for (int i=1; i<33; i++)
		{
		if (ccounter[i]==0)
		{
		ccombo[i]=" ";
		}
		if (ccounter[i]==1)
		{
		ccombo[i]="a";
		}
		if (ccounter[i]==2)
		{
		ccombo[i]="b";
		}
		if (ccounter[i]==3)
		{
		ccombo[i]="c";
		}
		if (ccounter[i]==4)
		{
		ccombo[i]="d";
		}
		if (ccounter[i]==5)
		{
		ccombo[i]="e";
		}
		if (ccounter[i]==6)
		{
		ccombo[i]="f";
		}
		if (ccounter[i]==7)
		{
		ccombo[i]="g";
		}
		if (ccounter[i]==8)
		{
		ccombo[i]="h";
		}
		if (ccounter[i]==9)
		{
		ccombo[i]="i";
		}
		if (ccounter[i]==10)
		{
		ccombo[i]="j";
		}
		if (ccounter[i]==11)
		{
		ccombo[i]="k";
		}
		if (ccounter[i]==12)
		{
		ccombo[i]="l";
		}
		if (ccounter[i]==13)
		{
		ccombo[i]="m";
		}
		if (ccounter[i]==14)
		{
		ccombo[i]="n";
		}
		if (ccounter[i]==15)
		{
		ccombo[i]="o";
		}
		if (ccounter[i]==16)
		{
		ccombo[i]="p";
		}
		if (ccounter[i]==17)
		{
		ccombo[i]="q";
		}
		if (ccounter[i]==18)
		{
		ccombo[i]="r";
		}
		if (ccounter[i]==19)
		{
		ccombo[i]="s";
		}
		if (ccounter[i]==20)
		{
		ccombo[i]="t";
		}
		if (ccounter[i]==21)
		{
		ccombo[i]="u";
		}
		if (ccounter[i]==22)
		{
		ccombo[i]="v";
		}
		if (ccounter[i]==23)
		{
		ccombo[i]="w";
		}
		if (ccounter[i]==24)
		{
		ccombo[i]="x";
		}
		if (ccounter[i]==25)
		{
		ccombo[i]="y";
		}
				if (ccounter[i]==26)
		{
		ccombo[i]="z";
		}
		


		}
			   whole_string="" + ccombo[32] + "" + ccombo[31] + "" + ccombo[30] + "" + ccombo[29] + "" + ccombo[28] + "" + ccombo[27] + "" + ccombo[26] + "" + ccombo[25] + "" + ccombo[24] + "" + ccombo[23] + "" + ccombo[22] + "" + ccombo[21] + "" + ccombo[20] + "" + ccombo[19] + "" + ccombo[18] + "" + ccombo[17] + "" + ccombo[16] + "" + ccombo[15] + "" + ccombo[14] + "" + ccombo[13] + "" + ccombo[12] + "" + ccombo[11] + "" + ccombo[10] + "" + ccombo[9] + "" + ccombo[8] + "" + ccombo[7] + "" + ccombo[6] + "" + ccombo[5] + "" + ccombo[4] + "" + ccombo[3] + "" + ccombo[2] + "" + ccombo[1] + "\n";
			   ofstream writer("hi.count", ios::app);
			   writer << whole_string;
	   

		
		}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
	system("PAUSE");
	return EXIT_SUCCESS;
}


i kno this code works the only problem is that it will take way to long to finish. basically what's happening in this code is each nested "for" loop represents a 26 character long digit place. when the program starts the most nested "for" loop goes up till it reaches 26 then the second for loop goes up one till it gets to 26 and so on and so forth. every time the first for loop goes up one i add letter assignments to each digit place then i combine all the digit places to make a string that i write to the bottom of a file every time the first digit place goes up.
i wanna kno if i can get the same output but without taking as much time to complete it

This post has been edited by ben104: 05 January 2009 - 02:33 PM


Is This A Good Question/Topic? 0
  • +

Replies To: alphabet counter

#2 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: alphabet counter

Posted 05 January 2009 - 01:59 PM

OMG, what a mess..

The reason your program is slow is because you're nesting the for loops in a way that they iterate 26^33 times with a workload of 26 if-statements. that makes 26^34 if-statements. (<- That's a shitload of many statements)

I'm not sure what you're trying to do but you need to rethink the algorithm. Maybe read about ascii-values..
Was This Post Helpful? 0
  • +
  • -

#3 learningcprogram  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 13
  • Joined: 04-January 09

Re: alphabet counter

Posted 05 January 2009 - 02:28 PM

How about this?
lCp

#include <stdio.h>
#include <stdlib.h>
void main()
{ 
char letter;  
  for (letter='A'; letter<='Z'; letter++)
  { 
	  printf("%c",letter);
  } 
  printf("\n");
  for (letter='a'; letter<='z'; letter++)
  {
	  printf("%c",letter);
  }
  printf("\n");  
 }


This post has been edited by learningcprogram: 05 January 2009 - 02:29 PM

Was This Post Helpful? 0
  • +
  • -

#4 learningcprogram  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 13
  • Joined: 04-January 09

Re: alphabet counter

Posted 05 January 2009 - 02:34 PM

Here is an example of doing it using ascii values.

lCp

#include <stdio.h>
#include <stdlib.h>
void main()
{ 
char i;  
  for (i = 97; i <= 122; i++)
  { 
	 printf("%c",i);
  } 
	
  printf("\n");
  
  for (i = 65; i <= 90; i++)
  {
	 printf("%c", i);
  }
  
  printf("\n");
 
 }


Was This Post Helpful? 0
  • +
  • -

#5 ben104  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 24-May 08

Re: alphabet counter

Posted 05 January 2009 - 02:36 PM

i just modified my code( i found a few errors)


the ultimate goal of this code is to create a list of all the possible combinations of the letters a-z up to 32 digits
Was This Post Helpful? 0
  • +
  • -

#6 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: alphabet counter

Posted 05 January 2009 - 06:08 PM

View Postben104, on 5 Jan, 2009 - 01:36 PM, said:

the ultimate goal of this code is to create a list of all the possible combinations of the letters a-z up to 32 digits


What you're trying to create is also called a brute-forcer, and it's quite simple to create.
If you want to save the characters to an array, you just use a char array.
If you want to just output them, you use a for loop.
Was This Post Helpful? 0
  • +
  • -

#7 ben104  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 24-May 08

Re: alphabet counter

Posted 05 January 2009 - 06:53 PM

View PostHyper, on 5 Jan, 2009 - 05:08 PM, said:

View Postben104, on 5 Jan, 2009 - 01:36 PM, said:

the ultimate goal of this code is to create a list of all the possible combinations of the letters a-z up to 32 digits


What you're trying to create is also called a brute-forcer, and it's quite simple to create.
If you want to save the characters to an array, you just use a char array.
If you want to just output them, you use a for loop.

do you know the code for a brute forcer?
Was This Post Helpful? 0
  • +
  • -

#8 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: alphabet counter

Posted 05 January 2009 - 07:12 PM

A brute forcer tries every combination possible, on a password.
Therefore what you're asking is relative to everything that it's in context to.

I can construct a brute-forcer for a variety of things, so can most of the coders on this site.
Was This Post Helpful? 0
  • +
  • -

#9 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: alphabet counter

Posted 05 January 2009 - 07:14 PM

The problem with brute-force techniques is (as in this case) they usually don't end within your lifetime or even the lifetime of the universe.
Was This Post Helpful? 0
  • +
  • -

#10 ben104  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 24-May 08

Re: alphabet counter

Posted 05 January 2009 - 07:21 PM

i need a brute-forcer that outputs to a file in this format

a
b
c
d
e
f
and so on
it should go to 32 places and consist characters a-z and spaces. by what i just looked up on google it sounds like that is almost impossible.
Was This Post Helpful? 0
  • +
  • -

#11 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: alphabet counter

Posted 05 January 2009 - 07:25 PM

To give you an idea about what you're working with, if you approximate 26^34 operations by 10^34 which you easily realize is alot smaller. Let's say your computer can perform 1,000,000,000,000 = 10^12 such operations per second (which it can't coz it's not that fast), it would still take 10^22 seconds to finish. In one year, you got (alot) less than 10^8 seconds. So you have to wait oh about 10^14 years. So if you're patient it'll be done by then. Unless you have a power shortage.

10^14 years = 100,000,000,000,000 years

This post has been edited by Gloin: 05 January 2009 - 07:27 PM

Was This Post Helpful? 0
  • +
  • -

#12 ben104  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 24-May 08

Re: alphabet counter

Posted 05 January 2009 - 07:27 PM

lol i know, i did that math too
Was This Post Helpful? 0
  • +
  • -

#13 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: alphabet counter

Posted 05 January 2009 - 07:38 PM

View PostGloin, on 5 Jan, 2009 - 06:25 PM, said:

To give you an idea about what you're working with, if you approximate 26^34 operations by 10^34 which you easily realize is alot smaller. Let's say your computer can perform 1,000,000,000,000 = 10^12 such operations per second (which it can't coz it's not that fast), it would still take 10^22 seconds to finish. In one year, you got (alot) less than 10^8 seconds. So you have to wait oh about 10^14 years. So if you're patient it'll be done by then. Unless you have a power shortage.

10^14 years = 100,000,000,000,000 years


The new i7 Core, has hyper-threading. Assume you overclock it (and your RAM).
Also assume you're not running M$ or anything else with a GUI.

The possibilities of pure processing power have just jolted dramatically.
Now imagine you build your own console specifically designed for brute-forcing,
and nothing else. Now you have a decent machine to crack passwords.

As far as Gloin's math, I disagree. Math and theorys are usually correct, especially when it comes to computers but; You're calculating it out as it taking the maximum possibilities EVERY time. Do not forget, the brute-forcer might also get the password on the first try.

EDIT: Fixed grammar, added boldness~

This post has been edited by Hyper: 05 January 2009 - 07:39 PM

Was This Post Helpful? 0
  • +
  • -

#14 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: alphabet counter

Posted 05 January 2009 - 07:43 PM

Oh, and since I'm a nice girl, here's a huge hint and direction towards the answers you so desperately seek:

#include <iostream>
using namespace std;

int main() {

    for (int x = 25; x <= 256; x++) { printf("%c", x); }

    cin.get();
    return 0;
}


You should also look up the ASCII tables to find which digits represent the alphabet (62, 102!).
Was This Post Helpful? 0
  • +
  • -

#15 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: alphabet counter

Posted 05 January 2009 - 08:04 PM

Well, you're not taking probability into account. It's not very likely to find the solution on the first try. Considering I was rather generous when rounding the numbers down you could expect it to take longer than that. When calculating complexity the general assumption is worst case.. I mean, hell, you can find solutions to TSP in one try as well but is it likely to happen every time? Fortunately not.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2