Solved

like brute force

Posted on 2000-03-17
17
269 Views
Last Modified: 2010-04-04
This is more of a curiosity question, but i was just wondering how could you make a program that creates words based on the concept of brute force, ie. a, b, ab, aab ,abb etc up to a limit of 10 characters, i understancd ord would probably used (ie. the ascii key chart) but i don't know how to use the loops properly, any ideas.
0
Comment
Question by:frangers99
  • 9
  • 3
  • 2
  • +3
17 Comments
 

Author Comment

by:frangers99
ID: 2630686
Adjusted points from 25 to 35
0
 

Author Comment

by:frangers99
ID: 2630687
Any ideas anybody?
0
 
LVL 1

Expert Comment

by:fulvio_brasil
ID: 2630696
Do you want know how make the loops for a,b,aa,ab,... is it? Could you explain a bit more?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2631347
Could you explain a bit more?
0
 

Expert Comment

by:SuperSy
ID: 2632285
I am not exactly sure of what you are asking, but it seems fun to answer a question that I am not exactly sure of, so here I go.  A little recursive fun.  (Delphi grammer could be messed up, but what the heck.)

{Global stuff}
const
  MaxLength: UINT = 10;
  Alphabets: array or char = ['a'..'b'];
var
  WordsList: TStringList;

{Call this one}
procedure Main;
var
  Length: Integer;
begin
  WordsList := TStringList.Create;

  for Length := 1 to MaxLength do
    AddWords(Length, '');
end;

prcedure AddWords(const Length: Integer; Prefix: String);
var
  i: Integer;
begin
  if Length = 0 then
    WordsList.Add(Prefix)
  else
  for i := Low(Alphabet) to High(Alphabet) do
    AddWords(Length - 1, Prefix + Alphabet(i));
end;

If this is not what you wanted, maybe you could tell us some more.  

SY

PS No, I did not drink during the St.Patrick's Day fiasco!  

0
 

Author Comment

by:frangers99
ID: 2633923
i'm not rejecting your annswer as so i'm gonna try it soon, but what i want is loop that counts from a..z and when it completes that it adds a character aa..zz and outputs all those words and then aaa..zzz.

I want to do what our counting system does but with letters ie 0..9 and when all the 1 digit numbers are used we go 10..99 (use an extra digit) get my idea. Sorry if it's confusing.
0
 
LVL 2

Expert Comment

by:Serega
ID: 2635355
You can do it simply by using recursive procedure.
Like this simple code:

program Project1;
const
  MaxChars = 5; // length of your generated string
var
  s: set of char;  // Your predefined set of usable characters
  res: string[MaxChars]; // result of each iteration

  procedure Next(k: integer); // k - number of changing character
  var i: integer;
  begin
    for i:=0 to 255 do
      if chr(i) in s then  // check if character in your set
      begin
        res[k] := chr(i);
        if k < MaxChars then
          Next(k+1)
        else
          Writeln(res);
      end;
  end;
 
var j: integer;
begin
  s:=['A'..'Z',' ','a'..'z'];
  res:='';
  for j:=1 to MaxChars do // Generate empty string
    res:=res+chr(1);      //
   
  Next(1); // run process
end.

You can change Writeln to your own processing procedure.

There is the way to do it without recursive procedures. I don't think it is required here.
0
 

Author Comment

by:frangers99
ID: 2643300
Adjusted points from 35 to 45
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:frangers99
ID: 2643301
Sorry Serega your answer is perfect in Turbo Pascal, but i can't work out how to use this code in Delphi...if you can send me the response with Delphi source code then you got yourself the points, but thanks very much for contributing.
0
 
LVL 2

Expert Comment

by:Serega
ID: 2643694
Hi! I don't completely understand why you reject that code.
It will perfect work in Delphi if you set in your project options "Generate console application" and put the code into Project1.dpr file.
It will also work in any place of Delphi program if you change Writeln to your processing procedure (I don't think that you need only to write generated strings).
0
 

Expert Comment

by:SuperSy
ID: 2645712
Serega's solution seems fine (except for little grammar things like "Integer" is missing in "const MaxChar: Integer = 5;").  What exactly does NOT work in Delphi?  Forgive me if I offend you, but do you need help with generating an application or checking syntax in Delphi?  As you may know, all kinds of people come and ask for questions, and we have to know what level you are on exactly to help you out.  

Also, this might be a good time to ask this question too: does your curiosity allow you to use recursive functions/procedures?   You might want to check that out with your curiosity first.  Then we can try to help you better.  

 
0
 

Author Comment

by:frangers99
ID: 2646494
Sorry, I am pretty new to Delphi, i compiled the EXACT code in Turbo Pascal,  and it ran perfectly, when i put it into Delphi it seemed to treat the word Next (as i the subroutine) as a keyword.
0
 

Author Comment

by:frangers99
ID: 2646512
i spose in my ignorance i am asking if i want to make this visual what parts of the code go where.

ie. what goes in a button? do i specify the functions, even if you don't answer this Serenga, you got the points.
0
 
LVL 2

Accepted Solution

by:
Serega earned 50 total points
ID: 2648405
Ok, that is the same code with Win GUI:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

const
  MaxChars = 5; // length of your generated string

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  s: set of char;  // Your predefined set of usable characters
  res: string[MaxChars]; // result of each iteration
  j: integer;

  procedure Next(k: integer); // k - number of changing character
  var i: integer;
  begin
    for i:=0 to 255 do
      if chr(i) in s then  // check if character in your set
      begin
        res[k] := chr(i);
        if k < MaxChars then
          Next(k+1)
        else
          Memo1.Lines.Add(res);
      end;
  end;

begin
  s:=['A'..'C',' ','a'..'c'];
  res:='';
  for j:=1 to MaxChars do // Generate empty string
    res:=res+chr(1);      //
   
  Next(1); // run process
end;

end.

All generated string will be in memo1 after execution of this.
0
 
LVL 1

Expert Comment

by:nrico
ID: 2649511
Sooooooo, you're writing a password hacker, aren't you!? :-)

-- Comment: ----------------
This may sound trivial, but if you have a function "Next" which Delphi assumes is a keyword (something I cannot imagine, but okay), then just rename the function. To _Next(), FNext(), DoNext() or whatever!
0
 

Author Comment

by:frangers99
ID: 2652120
Adjusted points from 45 to 50
0
 

Author Comment

by:frangers99
ID: 2652121
thanks Serenga, your solution was excellent. Sorry for making it harder for you, but i appreciate it very much. I was wondering if you have a webpage, i'd be interested to look at some of your other progs. to learn something from.

thanks anyway.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now