Autor Beitrag
mtin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 177

Win XP SP2
BDS2006 Enterprise
BeitragVerfasst: Mo 07.11.05 18:20 
Ich habe ein Array of Bytes, inwelchem die Hex-Zahlen eines TCP Pakets gespeichert sind.
nun muss ich in eines dieser Pakete ein mit SHA1 verschlüsseltes Passwort einfügen...
Hab mir also von irgendwoher eine Komponente besorgt die mir den SHA1 von einem string geben kann.

Diese gibt mir den hash als string der aus Hexadezimalzahlen besteht aus. z.B:
8ea31b3eaf31e8d6f16d7dda4931854acfb87619

wie bekomme ich jetzt diesen string in mein array of Byte?
ich müsste theoretisch folgendes machen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
packet[1]:=$8E;
packet[2]:=$A3;
packet[3]:=$LB;
packet[4]:=$3E;
packet[5]:=$AF;


nur eben irgendwie automatisieren...
ich hab sowieso generell Probleme mit diesen hex-zeichen bzw. Byte, IntToHex liefert mir ja auch nur einen String und kein Byte :(

wäre nett wenn mich einer mal mit allen möglichen Umformungsfunktionen rund um Byte versorgen könnte ;)

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt.
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Mo 07.11.05 18:22 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
I := 1;
P := 0;
while I<Length(S) do
begin
  ByteArray[P] := StrToInt('$'+S[I]+S[I+1];
  Inc (P);
  Inc (I,2);
end:

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
mtin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 177

Win XP SP2
BDS2006 Enterprise
BeitragVerfasst: Mo 07.11.05 20:35 
tschuldigung, hab mich geirrt, jeder Buchstabe dieses langen strings muss in eine Hexadezimalzahl umgewandelt werden und nicht einfach nur zwei Buchstaben hitnereinander reinschreiben....

also praktisch paket[x]:=BuchstabeToHex(x.Buchstabe d. Stings)

kann mir da nochmal jemand helfen?
tzotzdem danke für das andere, das brauch ich auch noch aber erst später ;)
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: Mo 07.11.05 20:45 
IntToHex + Ord ...

_________________
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.
mtin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 177

Win XP SP2
BDS2006 Enterprise
BeitragVerfasst: Mo 07.11.05 20:53 
eben genau das funktioniert nich, so hab ich mir das auch gedacht:

packet[29]:=IntToHex(ord('f'),2);

Allerdings bekomm ich da rechts nen string raus und das muss aber n Byte sein:

"Incompatible Types: 'Byte' and 'string'"
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: Mo 07.11.05 21:12 
ausblenden Delphi-Quelltext
1:
2:
BA[2N+0] := Ord(S[N]) and $F0 shr 4;
BA[2N+1] := Ord(S[N]) and $0F;

_________________
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.
mtin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 177

Win XP SP2
BDS2006 Enterprise
BeitragVerfasst: Mo 07.11.05 21:22 
achsooooo, danke, wusste nicht das ich einem Byte auch einfach die Integer zuweisen konnte, hab gedacht da muss ich immer Hexadezimalzahlen nehmen...

aber ich versteh trotzdem nicht was bei deinem quelltest das
and $F0 shr 4; und and $0F; bedeuten/bewirken soll :roll:

aber is auch egal, danke für die Hilfe ;)
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Di 08.11.05 09:57 
Warum so kompliziert? Es gibt doch auch HexToBin, mit dem man den ganzen Hex-String mit einem Rutsch konvertieren kann:

ausblenden Delphi-Quelltext
1:
HexToBin(PChar(s), PChar(packet), packetSize);					


Stefan
mtin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 177

Win XP SP2
BDS2006 Enterprise
BeitragVerfasst: Di 08.11.05 19:35 
-.-

hinterher (nachdem man jedes Zeichen einzeln per Hand eingetippt hat) ist man immer schlauer ;)

nochma großes Dankeschön :D