Einzelnen Beitrag anzeigen

DaCoda

Registriert seit: 21. Jul 2006
Ort: Hamburg
74 Beiträge
 
Delphi 12 Athens
 
#6

AW: Passwort in Ini-datei speichern

  Alt 8. Nov 2022, 15:27
Also XOR ist nicht gerade schön und wirklich nicht zu empfehlen.
Wenn es minimale Sicherheit sein soll, dann würde ich das eventuell so machen:

Delphi-Quellcode:
const
  Code64 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/';

function Encode64(S: string): string;
function Decode64(S: string): string;

{-------------------------------------------------------------------------------}

function Encode64(S: string): string;
var
  I: Integer;
  a: Integer;
  x: Integer;
  b: Integer;
begin
  Result := '';
  a := 0;
  b := 0;
  for I := 1 to Length(S) do begin
      x := Ord(S[I]);
    b := b * 256 + x;
    a := a + 8;
    while a >= 6 do begin
      a := a - 6;
      x := b div (1 shl a);
      b := b mod (1 shl a);
      Result := Result + Code64[x + 1];
    end;
  end;
  if a > 0 then begin
      x := b shl (6 - a);
    Result := Result + Code64[x + 1];
  end;
end;

function Decode64(S: string): string;
var
  I: Integer;
  a: Integer;
  x: Integer;
  b: Integer;
begin
  Result := '';
  a := 0;
  b := 0;
  for I := 1 to Length(S) do begin
    x := Pos(S[I], Code64) - 1;
    if x >= 0 then begin
        b := b * 64 + x;
      a := a + 6;
      if a >= 8 then begin
          a := a - 8;
        x := b shr a;
        b := b mod (1 shl a);
        x := x mod 256;
        Result := Result + chr(x);
      end;
    end else
      Exit;
  end;
end;
Debuggers don’t remove bugs, they only show them in slow-motion.
  Mit Zitat antworten Zitat