473,769 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FASTEST way to try all strings (a until ZZZZZZZZZZZZZZZ ZZZZZZZZZ)

Hi,

I need to find the FASTEST way to get a string in a Loop, that goes from "a"
to "ZZZZZZZZZZZZZZ ZZZ".
So it has to go like this:

a
b
....
z
A
....
Z
aa
ab
....
az
aA
....
ZZZZZZZZZZZZZZZ ZZZZZZZZZZZZZZZ ZZZZZ

So it has to try every combination with all the 26 letters, making a
difference between upper case and lower case, and the space (" ") has to be
included too.

Does anybody knows a way to do this?
I do not need this to hack any password or stuff liek this: I'm working with
the SDK of the Belgian governemnet for the electronic identity card. For
some @%£&§*$!! reason these guys made some big mistakes in there
documentation, and used the parameters with the info on a stupid way. Half
of them aren't working.... So the only ways to find out the missing
paramters is:
1. ask them for info, but they seem to be to stupid to knwo anything about
the stuff they made themselves...
2. Try avery combination of letters... So that's what I want to do :-)
I came up with this: but it doesn't work as fast as I want to...

dblBegin = 0
dblEnd = 52 ^ 30
For dblTeller = dblBegin To dblEnd
strT = GiveWord()
TestValue(strT)
txtWord.Text = strT
Application.DoE vents()
Next
Private Function GiveWord() As String
Dim strA As String = ""
Dim dblRest As Double
Dim dblQuotient As Double
dblQuotient = dblTeller
Do
dblRest = dblQuotient Mod 53
'1-26 = a-z
'27-52 = A-Z
If dblRest = 0 Then
dblRest = 32 'space
ElseIf dblRest < 27 Then
dblRest = dblRest + 96
Else
dblRest = dblRest + 38
End If
strA = Chr(dblRest) & strA
dblQuotient = dblQuotient \ 53
Loop Until dblQuotient = 0
GiveWord = strA
End Function
Jul 21 '05 #1
17 2330
DraguVaso <pi**********@h otmail.com> wrote:
I need to find the FASTEST way to get a string in a Loop, that goes from "a"
to "ZZZZZZZZZZZZZZ ZZZ".


Even using just 17 characters (unlike the last one you've given below)
there are a ridiculous number of combinations. You just *won't* be able
to test every one of them. With 53 symbols (a-z, A-Z, space) you get
205442259656281 392806087233013 combinations.

Assuming you could process 100 *billion* of them every second, it would
still take you 65145313183 years to go through them all. Do you really
have that much time?

Now, as for speeding up what you've got: using a StringBuilder instead
of repeated string concatenation would be a good start. Alternatively
you could use a char array. (I haven't checked your actual algorithm
for correctness, btw.)

I note that you're using 52^30 as the number of possible combinations,
which I don't quite understand if you're including space, but even so,
that makes the length of time taken even greater.

Suppose you have a million computers *each* processing 100 billion
combinations a second, to get through 52^30 combinations I suspect
you'd have to wait until way after the sun had gone cold to see the
end.

In other words: you'll need to find a different way of approaching your
problem...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Hehe, well, I found alreaddy some of them that had 4 our 5 characters, but
offcourse, for every character more it would take me exponential more time
to find it out. And I assumed aleaddy I would get very soon to my limit
(getting to 5 characters took already 10 minutes...).

But nevertheless, I've been lucky: The governement doesn't care a lot about
us, but the company that wants to sell to us the card-readers doesn't want
to miss a contract with some of the biggest chains of stores in belgium, and
they gave me the parameters, hehe :-)

In cae somebody else needs them:

ID Keys:
-----------
CardNumber, ChipNumber, BeginValidityDa te, EndValidityDate ,
IssuingMunicipa lity, NationalNumber, Name, FirstName1, FirstName2,
FirstName3,
Nationality, BirthPlace, BirthDate, Gender, NobilityTitle, DocumentType,
WhiteCane, YellowCane, ExtendedMinorit y

Adres keys:
---------------
Street, HouseNumber, BoxNumber, ZIPCode, Municipality, Country

Picture keys:
---------------
Picture
Thanks anyways guys!

Pieter
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
DraguVaso <pi**********@h otmail.com> wrote:
I need to find the FASTEST way to get a string in a Loop, that goes from "a" to "ZZZZZZZZZZZZZZ ZZZ".


Even using just 17 characters (unlike the last one you've given below)
there are a ridiculous number of combinations. You just *won't* be able
to test every one of them. With 53 symbols (a-z, A-Z, space) you get
205442259656281 392806087233013 combinations.

Assuming you could process 100 *billion* of them every second, it would
still take you 65145313183 years to go through them all. Do you really
have that much time?

Now, as for speeding up what you've got: using a StringBuilder instead
of repeated string concatenation would be a good start. Alternatively
you could use a char array. (I haven't checked your actual algorithm
for correctness, btw.)

I note that you're using 52^30 as the number of possible combinations,
which I don't quite understand if you're including space, but even so,
that makes the length of time taken even greater.

Suppose you have a million computers *each* processing 100 billion
combinations a second, to get through 52^30 combinations I suspect
you'd have to wait until way after the sun had gone cold to see the
end.

In other words: you'll need to find a different way of approaching your
problem...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3
Pieter,

I was busy with it because it is a nice chalenge, I was thinking as well to
the tale of the "grain of rice" when I was busy with it.

I brought it back to 3 in the chalenge however I do not understand you, do
you not need it anymore?

Cor
Jul 21 '05 #4
I indeed doesn't need it anymore :-) But thanks anyways for searching!

And me too found it a nice challenge, hehe :-) This is 'real' programming to
me: looking for the most effecient way to find a solution for a logical
problem... I have to adit that I like it a lot more than programming is
now...

In the past it was about intelligence, logical capabilities of the
programmer. now it's jsut about stupid knowloedge, knowing how to do
soemthing and were to find it. Now even idiots can program... :-/

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:OV******** ******@tk2msftn gp13.phx.gbl...
Pieter,

I was busy with it because it is a nice chalenge, I was thinking as well to the tale of the "grain of rice" when I was busy with it.

I brought it back to 3 in the chalenge however I do not understand you, do
you not need it anymore?

Cor

Jul 21 '05 #5
Jon,
Just out of curiosity, would you consider a StringBuilder "better" then
simply defining an array of 17 Char that you passed to New String?

As you are continually replacing a single char in the "buffer".

Something like:

Private Shared Sub FindMatch(ByVal chars() As Char, ByVal index As
Integer)
If index = chars.Length Then
Debug.WriteLine (New String(chars))
Else
FindMatch(chars , index, AscW(" "c))
For charCode As Integer = AscW("a") To AscW("z")
FindMatch(chars , index, charcode)
Next
For charCode As Integer = AscW("A") To AscW("Z")
FindMatch(chars , index, charcode)
Next
End If
End Sub

Private Shared Sub FindMatch(ByVal chars() As Char, ByVal index As
Integer, ByVal charCode As Integer)
chars(index) = ChrW(charCode)
FindMatch(chars , index + 1)
End Sub

Public Shared Sub Main()

Dim chars(16) As Char

FindMatch(chars , 0)

End Sub

I would consider inlining FindMatch(char( ), integer, integer) for
performance reasons...

Just curious
Jay

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
DraguVaso <pi**********@h otmail.com> wrote:
I need to find the FASTEST way to get a string in a Loop, that goes from
"a"
to "ZZZZZZZZZZZZZZ ZZZ".


Even using just 17 characters (unlike the last one you've given below)
there are a ridiculous number of combinations. You just *won't* be able
to test every one of them. With 53 symbols (a-z, A-Z, space) you get
205442259656281 392806087233013 combinations.

Assuming you could process 100 *billion* of them every second, it would
still take you 65145313183 years to go through them all. Do you really
have that much time?

Now, as for speeding up what you've got: using a StringBuilder instead
of repeated string concatenation would be a good start. Alternatively
you could use a char array. (I haven't checked your actual algorithm
for correctness, btw.)

I note that you're using 52^30 as the number of possible combinations,
which I don't quite understand if you're including space, but even so,
that makes the length of time taken even greater.

Suppose you have a million computers *each* processing 100 billion
combinations a second, to get through 52^30 combinations I suspect
you'd have to wait until way after the sun had gone cold to see the
end.

In other words: you'll need to find a different way of approaching your
problem...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #6
Jay B. Harlow [MVP - Outlook] <Ja************ @msn.com> wrote:
Just out of curiosity, would you consider a StringBuilder "better" then
simply defining an array of 17 Char that you passed to New String?
Yes - because it doesn't require creating an extra string each time.
The StringBuilder contains a string which is mutable until you call
ToString on it.
As you are continually replacing a single char in the "buffer".


That actually suggests an even better strategy: create *and keep* a
StringBuilder, calling ToString on it each time you've finished that
iteration, but then still using it on the next iteration as a
StringBuilder which will automatically create a copy with "mostly" the
right data in.

Of course, if you could get your "test" procedure to work on array of
chars instead of a string, you could have the best of all worlds - a
basically static memory footprint, with no extra objects to create.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #7
Jay B.

I think that an array of bytes would in this case be the fastest and also
would help to minimize the used space.

Cor
Jul 21 '05 #8
Jon,
Yes - because it doesn't require creating an extra string each time.
The StringBuilder contains a string which is mutable until you call
ToString on it. Its the "mutable until you call ToString" part that "confuses" me, hence my
question.

Presumably you would need to call StringBuilder.T oString on each iteration,
as you want to pass the string to another function. Does the StringBuilder
then need to create a new buffer (aka a new "string") so that you can modify
the char, or does it simply call New String(char[]) & copy the existing
buffer.

I was under the impression that it will create a new buffer when you modify
the StringBuilder after calling ToString (copy on write, not copy on read).
Of course, if you could get your "test" procedure to work on array of
chars instead of a string, you could have the best of all worlds Yes, that would be the best of both worlds...

Thanks for the thoughts
Jay

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... Jay B. Harlow [MVP - Outlook] <Ja************ @msn.com> wrote:
Just out of curiosity, would you consider a StringBuilder "better" then
simply defining an array of 17 Char that you passed to New String?


Yes - because it doesn't require creating an extra string each time.
The StringBuilder contains a string which is mutable until you call
ToString on it.
As you are continually replacing a single char in the "buffer".


That actually suggests an even better strategy: create *and keep* a
StringBuilder, calling ToString on it each time you've finished that
iteration, but then still using it on the next iteration as a
StringBuilder which will automatically create a copy with "mostly" the
right data in.

Of course, if you could get your "test" procedure to work on array of
chars instead of a string, you could have the best of all worlds - a
basically static memory footprint, with no extra objects to create.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #9
Cor,
How would saving 17 bytes really be saving anything?

How would an array of Byte be any faster then an array of Char? Especially
when I would expect the function that the OP is calling needs a String? I
agree if the OP's function needed an array of Byte, then an array of Byte is
needed, however the OP suggested Chars (A to Z, a to z and space).

My routine works directly with Unicode Chars there is no encoding involved
(an array of Byte would need an "expensive" Encoding object to convert from
Bytes to Chars or String.

Just curious where you are coming from.

Jay

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:Om******** ******@TK2MSFTN GP10.phx.gbl...
Jay B.

I think that an array of bytes would in this case be the fastest and also
would help to minimize the used space.

Cor

Jul 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
1209
by: DraguVaso | last post by:
Hi, I need to find the FASTEST way to get a string in a Loop, that goes from "a" to "ZZZZZZZZZZZZZZZZZ". So it has to go like this: a b .... z
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10212
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.