AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Text verschlüsseln Windows + Android

Ein Thema von gee21 · begonnen am 13. Jan 2020 · letzter Beitrag vom 15. Jan 2020
 
philipp.hofmann

Registriert seit: 21. Mär 2012
Ort: Hannover
923 Beiträge
 
Delphi 10.4 Sydney
 
#6

AW: Text verschlüsseln Windows + Android

  Alt 13. Jan 2020, 21:52
Ganz, ganz wichtiger Unterschied in der String-Nutzung zwischen Windows/MacOS und iOS/Android:
Bei iOS und Android gilt string[0..len-1] und bei Windows/MacOS string[1..len]!

Ganz unten an der Basis und dann so unterschiedlich, kann nicht sagen, warum dies so ist.

Code:
unit Crypt;

interface

uses SysUtils, FMX.Dialogs;

  function Encrypt (const s: String; Key: Word) : string;
  function Decrypt (const s: string; Key: Word) : string;

implementation

const CKEY1 = 53761;
      CKEY2 = 32618;

function Encrypt(const S :String; Key: Word): String;
var  i         :Integer;
      RStr      :RawByteString;
      RStrB     :TBytes Absolute RStr;
begin
  Result:= '';
  RStr:= UTF8Encode(S);
  for i := 0 to Length(RStr)-1 do begin
    RStrB[i] := RStrB[i] xor (Key shr 8);
    Key := (RStrB[i] + Key) * CKEY1 + CKEY2;
  end;
  for i := 0 to Length(RStr)-1 do begin
    Result:= Result + IntToHex(RStrB[i], 2);
  end;
end;

function Decrypt(const S: String; Key: Word): String;
var  i, tmpKey :Integer;
      RStr      :RawByteString;
      RStrB     :TBytes Absolute RStr;
      tmpStr    :String;
begin
  tmpStr:= UpperCase(S);
  SetLength(RStr, Length(tmpStr) div 2);
  i:=1;
  try
    while (i<Length(tmpStr)) do
    begin
      {$IF Defined(ANDROID) or Defined(IOS)}
        RStrB[i div 2]:= StrToInt('$' + tmpStr[i-1] + tmpStr[i]);
      {$ELSE}
        RStrB[i div 2]:= StrToInt('$' + tmpStr[i] + tmpStr[i+1]);
      {$ENDIF}
      Inc(i, 2);
    end;
  except
    Result:= '';
    Exit;
  end;
  for i := 0 to Length(RStr)-1 do
  begin
    tmpKey:= RStrB[i];
    RStrB[i] := RStrB[i] xor (Key shr 8);
    Key := (tmpKey + Key) * CKEY1 + CKEY2;
  end;
  Result:=UTF8ToString(RStr);
end;

end.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:46 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz