Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Problem mit altem Code (Stringlänge ?)

Empfohlene Antworten

Veröffentlicht

Hi,

hab ein Problem mit einem alten Verschlüsselungsalgorithmus.

Verschlüsselt wird zwar aber nur bis zu einer bestimmten länge und ab da wird nichts mehr ausgegeben.

Bin echt ratlos, PLEASE HELP !!!!

Hier mal der Code:

type TRC4 = class(TObject)

private

FInText : String;

FOutText : String;

FKey : String;

FMainKey : String;

FSBox : Array[0..255] of Integer;

public

constructor Create;

procedure InitKey;

procedure Encrypt;

property MainKey : String read FMainKey write FMainKey;

property Key : String read FKey write FKey;

property KlarText : String read FInText write FInText;

property VerschluesselterText : String read FOutText write FOutText;

end;

implementation

constructor TRC4.Create;

var

i : Integer;

begin

inherited;

FOutText := '';

FInText := '';

FKey := '';

for i := 0 to 255 do FSBox := 0; // Variablen und Array werden "geleert".

end;

procedure TRC4.Encrypt;

var

i, j, z : Integer;

t : Byte;

swapbyte : Byte;

begin // Verschlüsseln

i := 0;

j := 0;

FOutText := '';

if length(FInText) = 0 then exit;

for z := 0 to length(FInText) do

begin

i := (i + 1) mod 256;

j := (j + FSBox) mod 256;

swapbyte := FSBox[j];

FSBox[j] := FSBox;

FSBox := swapbyte;

t := (FSBox + FSBox[j]) mod 256;

FOutText := FOutText + chr(FSBox[t] xor ord(FInText[z+1]))

end;

end;

Verschlüsselt wird zwar aber nur bis zu einer bestimmten länge und ab da wird nichts mehr ausgegeben.

Bis zu welcher Länge denn? Und vorallem, welche Delphi Version und welches System?

Eine begrenzende Länge in dem code ist die Variable z in der Encrypt Methode. z ist ein Integer Wert und ein Integer ist nunmal beschränkt groß. Bei 32bit Implementationen wäre 2147483647 der größte Wert. Das sind 2GB.

Wenn du aber keine 32bit Version benutzt (also 16bit), ist ein Integer nur 32767 groß (jeweils die Version mit Vorzeichen, wie sie ja hier benutzt wird).

Wenn du den Typ bei der 32bit Version auf Cardinal änderst (oder Longword), verdoppelst du diese Größe. Bei der 16bit Version sollte es genauso gehen, bin mir aber wegen den Typen dort nicht 100% sicher.

Wenn es noch größer werden soll, musst du auf einen reelen Typ umsteigen (Extended kann max. 1.1 x 10^4932 groß werden), aber entsprechend den Code etc. anpassen (for-Schleife geht nur mit Integer Typen z.B.).

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.