Re: Verschüsselungs-DLL mit Fehlern
Auch wenn ich die Art der Verschlüsselung "komisch" find ...
- Ramdom zur Verschüsselung: ließ mal in der OH nach, was dort diesbezüglich bei RandSeed steht. - das mit dem StartIndex 1 bei Strings wurde schon gesagt - die Codeformatierung ... naja zur "Verschlüsselung": - du weißt, daß die Datenmänge vermutlich so durchschnittlich um das 8- bis 12-fache ansteiget? pro crypt1, also insgesammt 8*8- bis 12*12-fach - Daten innerhalb des verschlüsselten Strings sind vierfach vorhanden und da crypt1 auch noch doppelt ausgeführt wird, sind die Daten sogar alle 8 mal vorhanden - du solltest lieber noch eine Fehlerprüfung integrieren, falls mal unzulässige Zeichen im String s vorkommen, also welche die nicht in list/list2 vorkommen - warum array of string, wo da doch nur Chars drin sind?
Delphi-Quellcode:
- wieso wert: array of byte;, wo du die Daten sofort verwendest
list: array [1..62] of char = ...
list2: array [1..62] of char = ... aber hier zumindestens mal deine Funktion, wie sie erstmal funktionieren sollte
Delphi-Quellcode:
function crypt1(s: string): string; stdcall;
var wert: array of byte; i, j: integer; begin s := s + 'A'; RandSeed := 4546464; SetLength(wert, Length(s)); Result := ''; for i := 0 to Length(s) - 1 do begin for j := 1 to 62 do begin if s[i + 1] = list[j] then wert[i] := j; end; Result := Result + Format('%d%d', [wert[i], Random(wert[i])]); end; for i := 0 to Length(s) - 1 do begin for j := 1 to 62 do begin if s[i + 1] = list2[j] then wert[i] := j; end; Result := Result + Format('%d%d', [wert[i], Random(wert[i])]); end; end;
Delphi-Quellcode:
wie gesagt, eine Prüfung ob der Variable wert innerhalb der Schleife überhaupt etwas zugewiesen wurde, wäre nicht schlecht
function crypt1(s: string): string; stdcall;
var wert: byte; i, j: integer; begin s := s + 'A'; RandSeed := 4546464; Result := ''; for i := 0 to Length(s) - 1 do begin for j := 1 to 62 do begin if s[i + 1] = list[j] then wert := j; end; Result := Result + Format('%d%d', [wert, Random(wert)]); end; for i := 0 to Length(s) - 1 do begin for j := 1 to 62 do begin if s[i + 1] = list2[j] then wert := j; end; Result := Result + Format('%d%d', [wert, Random(wert)]); end; end;
Delphi-Quellcode:
so wie es jetzt ist, hätte "wert" einen zufälligen Inhalt, wenn es keinem Zeichen in list bzw. list2 entspricht.
wert := 0;
for j := 1 to 62 do begin if s[i + 1] = list2[j] then wert := j; end; if wert = 0 then EineFehlermeldung; mit einem Array[Char] of könntest du die ganze J-For-Schleife weglassen, da man damit das Zeichen direkt als Array-Index nutzen kann:
Delphi-Quellcode:
Aber wenn du wirklich was "ordentlich" verschlüsseln willst, dann schau dich mal nach DEC/DEC (von Hagen) um
const list: array [AnsiChar] of Byte = (
{ x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf} {0x} 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {1x} 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {2x} 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {3x} 36, 27, 28, 29, 30, 31, 32, 33, 34, 35, 0, 0, 0, 0, 0, 0, {4x} 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, {5x} 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 0, 0, 0, 0, 0, {6x} 0, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, {7x} 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 0, 0, 0, 0, 0, {8x} 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {9x} 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {ax} 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {bx} 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {cx} 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {dx} 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {ex} 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {fx} 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // List2 hab ich jetzt nicht übersetzt, aber mit 'ner // ASCII-Tabelle kannst das ganz einfach selber machen. // Im Grunde ist das Ganze nur andersrum zu deinem Array: // - bei dir wurde eine fortlaufende Zahl je mit einem Zeichen verknüpft // - hier ist den entsprechenden Zeichen die passende fortlaufende Zahl zugeordnet function crypt1(s: string): string; stdcall; var wert: byte; i: integer; begin s := s + 'A'; RandSeed := 4546464; Result := ''; for i := 0 to Length(s) - 1 do begin wert := list[s[i + 1]]; if wert = 0 then HierEineFehlermeldungAusgeben; Result := Result + Format('%d%d', [wert, Random(wert)]); end; for i := 0 to Length(s) - 1 do begin wert := list2[s[i + 1]]; if wert = 0 then HierEineFehlermeldungAusgeben; Result := Result + Format('%d%d', [wert, Random(wert)]); end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:49 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz