Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 25.01.06 22:09 
Hallo,

ich wolltet mal schnell einen Keygen coden. Er soll achtstellige Strings ausgeben, welche aus Klein-/Großbuchstaben und Zahlen bestehen. Dafür habe ich folgenden Code:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
procedure MachArrayVoll;
begin
  arr[1]:='a';
  arr[2]:='b';
  arr[3]:='c';
  arr[4]:='d';
  arr[5]:='e';
  arr[6]:='f';
  arr[7]:='g';
  arr[8]:='h';
  arr[9]:='i';
  arr[10]:='j';
  arr[11]:='k';
  arr[12]:='l';
  arr[13]:='a';
  arr[14]:='n';
  arr[15]:='o';
  arr[16]:='p';
  arr[17]:='q';
  arr[18]:='r';
  arr[19]:='s';
  arr[20]:='t';
  arr[21]:='u';
  arr[22]:='v';
  arr[23]:='w';
  arr[24]:='x';
  arr[25]:='y';
  arr[26]:='z';
  arr[27]:='A';
  arr[28]:='B';
  arr[29]:='C';
  arr[30]:='D';
  arr[31]:='E';
  arr[32]:='F';
  arr[33]:='G';
  arr[34]:='H';
  arr[35]:='I';
  arr[36]:='J';
  arr[37]:='K';
  arr[38]:='L';
  arr[39]:='M';
  arr[40]:='N';
  arr[41]:='O';
  arr[42]:='P';
  arr[43]:='Q';
  arr[44]:='R';
  arr[45]:='S';
  arr[46]:='T';
  arr[47]:='U';
  arr[48]:='V';
  arr[49]:='W';
  arr[50]:='X';
  arr[51]:='Y';
  arr[52]:='Z';
  arr[53]:='0';
  arr[54]:='1';
  arr[55]:='2';
  arr[56]:='3';
  arr[57]:='4';
  arr[58]:='5';
  arr[59]:='6';
  arr[60]:='7';
  arr[61]:='8';
  arr[62]:='9';


end;


function BerechneKey(laenge:integer) : string;
var i:integer;
begin
  randomize;
  result:='';
  for i :=1 to laenge do
  begin
    result:=result+arr[random(62+1)];
  end;
end;


procedure TForm1.Button5Click(Sender: TObject);
var i:integer;
begin
MachArrayVoll;
memo1.lines.clear;
for i := 1 to 100 do
begin
  memo1.lines.add(berechnekey(8));
end;
end;



Jedoch ist dann im Memo folgendes:


Zitat:

3HVaOoxV
C3MKYiFC
4NKBUlsT
Yi
5_EÈA‘ >W{ÂÝn(€èQŠœ›ì”ãvÆY–aæöo™$³ˆQÝåLÕ¡'³,*Fa¹ š%2·™ªÄeÈØm?ð ̹Ê20*ê)ÿs«i¾‚r`å†Ú¾¶{\•WQÝc¿2šHqÂl@ÈÇÛÙnq£xª˜ÚQ|q7ðè<›ŽIÀÈâ…<ÅòO¬P’EãóÙd^¼ ,F©BäÀèÄ
ùØcnEÈœ«¬¢áC:i¹š|ÝeQBÄ0êP
QLohiNyy
hyQc0HnB
NDBkQJOa
YABGiEZN
eb6pICDy
1FdlyaIE
eEhMsKDe
Ih4Lxiiv
sVRDZoxp
bqAe3PU5
HKulKAoJ
4v0OZlzK
lPQuNJ9O
iP5JLnn1
x9224zbS
Ezw75bEd
FZep3rC8
44arMpza
Yj67aj3v
CrOHGvRX
a7Lf2T6M
3sfUiRJZ
fUxMaPGL
QjWtcyK4
Z7xbse1q
lefTpTfe
0oaezkYq
ptigiiVG
KfYpXRfi
7i2aelro
tU2AhyCd
l3RFq6e5
AVUUoh3A
1bAfeMUQ
wiFKVoar
TlJIcTyy
3N8aKGL7
Cai8KaVF
4xQZ75Kn
ueB5bSCU
ZF
YORW67dT
EF
Rc3LXCOn
8SX1yAqj
VUaT4ju6
QUo7xsRZ
YRELouh8
1aegsd2R
EiXRLpPi
rkbJg9U4
OnfHzE6F
6fSXdqD2
Qf2KhHWE
Go1wQ1I7
3F
A6MReLa1
7iyF
aG3BuwlD
L7nSXnlF
hR6rZPKy
YLvl2ulu
pPj1qn8c
ywdV5Ws2
F3qOHFRU
lWQJJlsQ
SHxhMNQJ
unlOfsMv
zilDkgo5
Txec9pLT
klQOKCAT
R6yaN4ZL
vF
St3VqzTe
IC2GZTFH
GrAZQGSN
jYUgDiFI
nhtLH2pr
atinJaru
kThZ7xF7
YSE19rth
1aewcbd1
7jF
voh9nxKc
Nvg8eNoo
2vkyEGai
Y9kxoXto
ZZXUHcrD
f6VUxt6Q
MQCtAUtJ
18fo3wgI
ehP48tcu
QZMgwrF
0kjexPoh
ihN0I2TD
hWHaZtXW


Könnt ihr mir sagen. wo der Fehler liegt?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
LLCoolDave
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 212

Win XP
Delphi 2005
BeitragVerfasst: Mi 25.01.06 22:27 
Setz mal in Zeile 77 das +1 hinter die Klammer, also Random(62)+1
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 25.01.06 22:29 
:autsch: :autsch: :autsch: :autsch: :autsch: :autsch: :autsch: :autsch: :autsch: :autsch: :autsch: :autsch: :autsch: :autsch: :autsch: :autsch: :autsch: :autsch:


Danke, da lag der Fehler!!!!

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 25.01.06 22:31 
erstmal ist das hier:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
procedure MachArrayVoll;
begin
  arr[1]:='a';
  arr[2]:='b';
  arr[3]:='c';
  arr[4]:='d';
  arr[5]:='e';
  arr[6]:='f';
  arr[7]:='g';
  arr[8]:='h';
  arr[9]:='i';
  arr[10]:='j';
  arr[11]:='k';
  arr[12]:='l';
  arr[13]:='a';
  arr[14]:='n';
  arr[15]:='o';
  arr[16]:='p';
  arr[17]:='q';
  arr[18]:='r';
  arr[19]:='s';
  arr[20]:='t';
  arr[21]:='u';
  arr[22]:='v';
  arr[23]:='w';
  arr[24]:='x';
  arr[25]:='y';
  arr[26]:='z';
  arr[27]:='A';
  arr[28]:='B';
  arr[29]:='C';
  arr[30]:='D';
  arr[31]:='E';
  arr[32]:='F';
  arr[33]:='G';
  arr[34]:='H';
  arr[35]:='I';
  arr[36]:='J';
  arr[37]:='K';
  arr[38]:='L';
  arr[39]:='M';
  arr[40]:='N';
  arr[41]:='O';
  arr[42]:='P';
  arr[43]:='Q';
  arr[44]:='R';
  arr[45]:='S';
  arr[46]:='T';
  arr[47]:='U';
  arr[48]:='V';
  arr[49]:='W';
  arr[50]:='X';
  arr[51]:='Y';
  arr[52]:='Z';
  arr[53]:='0';
  arr[54]:='1';
  arr[55]:='2';
  arr[56]:='3';
  arr[57]:='4';
  arr[58]:='5';
  arr[59]:='6';
  arr[60]:='7';
  arr[61]:='8';
  arr[62]:='9';


end;

sehr unschön, das geht um einiges kürzer:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
var
  x, y, z, c: integer;
begin
  c := 0;
  for x := 65 to 90 do
  begin
    inc(c);
    arr[c] := chr(x);
  end
  for y := 97 to 122 do
  begin
    inc(c);
    arr[c] := chr(y);
  end
  for z := 48 to 57 do
  begin
    inc(c);
    arr[c] := chr(z);
  end
end;

geht eventuell noch kürzer ;)
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 25.01.06 22:33 
Hallo,

das mag ja sein, aber ich versteh nur Bahnhof :wink:

Wie kommst du bei 'for' dort auf die Zahlen (57 usw.) ?

Und was macht chr?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
LLCoolDave
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 212

Win XP
Delphi 2005
BeitragVerfasst: Mi 25.01.06 22:34 
Ja, wir schmeissen den array einfach ganz raus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function BerechneKey(laenge:integer) : string;
var i:integer;
begin
  randomize;
  result:='';
  for i :=1 to laenge do
  begin
    case random(3of
      0: result:=result+chr(65+Random(26));
      1: result:=result+chr(97+Random(26));
      2: result:=result+chr(48+Random(10));
    end;
  end;
end;
0xCC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 150



BeitragVerfasst: Mi 25.01.06 22:35 
guck mal in die ascii-tabelle (MS-DOS 6.22 Handbuch, Seite 264)
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 25.01.06 22:37 
Wo soll ich ein MSDOS-Handbuch hernehmen???? :wink:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 25.01.06 22:38 
hast du ne formelsammlung ? such einfach nach ascii tabelle

ich frag mich nur, wie du den key auf gültigkeit prüfen willst, ich denke nicht, dass du damit beim 2. anlauf die gleiche checksumme rausbekommen wirst ;)

(außer du lässt randomize weg und startest dein programm neu, bei der gleichen anzahl versuche hast du wieder den gleich key);
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 25.01.06 22:40 
Mein Kumpel brauchte eine lange Liste von achtstelligen Strings. Die hätte man sich auch ohne Computer ausdenken können, das Wort 'Key-Generator' passt hier nicht ganz, das stimmt.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 25.01.06 22:42 
vielleicht solltest du mal nach bruteforcing gucken, weil ich weiß nicht, was man mit 8 stelligen zufälligen (und dann auch noch merkwürdig kompliziert zufälligen) strings anfangen soll :shock:

oder wird das ein passwort generator ?
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 25.01.06 22:45 
Das sind Zugangscodes für Mitglieder unseres Vereins für die Vereinswebsite.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Mi 25.01.06 22:46 
0xCC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 150



BeitragVerfasst: Mi 25.01.06 23:19 
Darth Sitthiander
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 95



BeitragVerfasst: Mi 01.03.06 17:10 
ich würde es eher so machen:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

function BerechneKey(laenge:integer) : string;
var i:integer;
begin
  randomize;
  result:='';
  for i :=1 to laenge do
  begin
    case random(3of
      0: result:=result+chr(65+Random(26));
      1: result:=result+chr(97+Random(26));
      2: result:=result+chr(48+Random(10));
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
memo1.lines.clear;
for i := 1 to 100 do
begin
  memo1.lines.add(berechnekey(4)+'-'+berechnekey(4)+berechnekey(4)+'-'+berechnekey(4));
end;
end;
end.

wobei man hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
memo1.lines.clear;
for i := 1 to 100 do
begin
  memo1.lines.add(berechnekey(4)+'-'+berechnekey(4)+berechnekey(4)+'-'+berechnekey(4));
end;


Statt 4 überall ne 5 oder 6 einsetzen kann. Sorry wenns als pushen gilt.

PS: Weiss einer wie ich die Buchstaben grossgeschrieben kriege?

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt
Moderiert von user profile iconChristian S.: Size-Tags entfernt
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 01.03.06 17:57 
upcase oder uppercase
Darth Sitthiander
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 95



BeitragVerfasst: Mi 01.03.06 18:04 
THXXXXXXXXXXXXXXXXXXXXXXXX
Ich hab noch ein paar sachen eingebaut:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
unit serialnummer;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

function BerechneKey(laenge:integer) : string;
var i:integer;
begin
  randomize;
  result:='';
  for i :=1 to laenge do
  begin
    case random(3of
      0: result:=result+chr(65+Random(26));
      1: result:=result+chr(97+Random(26));
      2: result:=result+chr(48+Random(10));
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
a, b:string;
begin
a:= Inputbox ('Anzahl Keys''Gib die anzahl Keys an, die generiert werden sollen','');
b:= Inputbox ('Anzahl Zahlen''Gib die anzahl Zahlen an, die nach dem - stehen solen','');
memo1.lines.clear;
for i := 1 to strtoint(a) do
begin
  memo1.lines.add(UpperCase(berechnekey(strtoint(b))+'-'+berechnekey(strtoint(b))+'-'+berechnekey(strtoint(b))+'-'+berechnekey(strtoint(b))));
end;
savedialog1.execute;
if savedialog1.execute then
Memo1.lines.SaveToFile(savedialog1.FileName);
end;
end.


Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 01.03.06 18:37 
user profile iconDarth Sitthiander hat folgendes geschrieben:
PS: Weiss einer wie ich die Buchstaben grossgeschrieben kriege?

Jup. Ganz einfach:
ausblenden Delphi-Quelltext
1:
Font.Size := 500;					


Ansonsten mal UpperCase ausprobieren *g*

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 01.03.06 21:06 
gehört zwar nicht hier her, aber deine zeichenkette aus der du dein passwort zusammensetzt kannst du auch einfacher haben.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
 keystring: string;
begin
 zufallstr := '';
 keystring:= 'abcdefghijklmnopqrstuvwxyz1234567890'//string;
 for i = 0 to länge do 
  zufallstr:= zufallstr + keystring[random(length(keystring))];

....


da kannst du das ganze auch in einer ini ablegen und den anwender seinen favorisierten zeichencode festlegen lassen.

noch viel spass
Darth Sitthiander
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 95



BeitragVerfasst: Mi 01.03.06 21:27 
Wie soll man das genau in dei unit einbinden? wo? beim button? oder function? kannste das bei meinem quelltext zeigen? thx