Thema: Delphi kurze Verschlüsselung

Einzelnen Beitrag anzeigen

ichbins

Registriert seit: 9. Jul 2005
Ort: Hohenaltheim
1.001 Beiträge
 
Delphi 2005 Personal
 
#5

Re: kurze Verschlüsselung

  Alt 6. Nov 2005, 12:55
Ein Beispiel für lesbare XOR-Verschlüsselung:
Delphi-Quellcode:
const
  hexes:array[0..15] of char=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');

function hextobyte(hex:string):byte;
var
  i:integer;
begin
  for i:=0 to 15 do
    if hexes[i]=hex[1] then
      result:=16*i;
  for i:=0 to 15 do
    if hexes[i]=hex[2] then
      result:=result+i;
end;

function bytetohex(b:byte):string;
begin
  result:=hexes[b div 16]+hexes[b mod 16];
end;

function encodexor(data,password:string):string;
var
  i:integer;
begin
  result:='';
  for i:=1 to length(data) do
    result:=result+bytetohex(byte(data[i]) xor byte(password[1+(i mod length(password))]));
end;

function decodexor(data,password:string):string;
var
  i:integer;
begin
  result:='';
  for i:=1 to (length(data) div 2) do
    result:=result+char(hextobyte(data[i*2-1]+data[i*2]) xor (byte(password[1+(i mod length(password))])));
end;
Beispielanwendung im Anhang.
Angehängte Dateien
Dateityp: zip xor_en-decoder_424.zip (207,7 KB, 26x aufgerufen)
Michael Enßlin
  Mit Zitat antworten Zitat