Der
XTEA ist ein sehr schlanker Blockziffernalgorithmus.
Dieser Algorithmus verschlüsselt 64-bit Daten-Blöcke mit einer Schlüssellänge von 128-bit.
XTEA ist keinen Patenten unterworfen.
näheres unter
Wikipedia - XTEA
Das Modul xtea.pas mit der
Implementierung
Delphi-Quellcode:
unit xtea;
interface
uses Classes;
{$OVERFLOWCHECKS OFF}
type TxteaKey =
array[0..3]
of LongWord;
type TxteaData =
array[0..1]
of LongWord;
type
Txtea =
class(TPersistent)
public
procedure Crypt (Key : TxteaKey;
var Data : TxteaData);
procedure Decrypt (Key : TxteaKey;
var Data : TxteaData);
end;
implementation
procedure Txtea.Crypt (Key : TxteaKey;
var Data : TxteaData);
var Summe : LongWord;
var Delta : LongWord;
var n : Integer;
begin
Summe := 0;
Delta := $9E3779B9;
for n := 1
to 32
do
begin
Data[0] := Data[0] +
( (((Data[1]
shl 4)
xor (Data[1]
shr 5)) + Data[1])
xor
(Summe + Key[Summe
and 3]) );
Summe := Summe + Delta;
Data[1] := Data[1] +
( (((Data[0]
shl 4)
xor (Data[0]
shr 5)) + Data[0])
xor
(Summe + Key[Summe
shr 11
and 3]) );
end;
end;
procedure Txtea.Decrypt (Key : TxteaKey;
var Data : TxteaData);
var Summe : LongWord;
var Delta : LongWord;
var n : Integer;
begin
Summe := $C6EF3720;
Delta := $9E3779B9;
for n := 1
to 32
do
begin
Data[1] := Data[1] -
( (((Data[0]
shl 4)
xor (Data[0]
shr 5)) + Data[0])
xor
(Summe + Key[Summe
shr 11
and 3]) );
Summe := Summe - Delta;
Data[0] := Data[0] -
( (((Data[1]
shl 4)
xor (Data[1]
shr 5)) + Data[1])
xor
(Summe + Key[Summe
and 3]) );
end;
end;
end.
Auszug aus einem
Beispiel
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var xtea : Txtea;
var Key : TxteaKey;
var Data : TxteaData;
begin
xtea := Txtea.Create;
try
Key[0] := 9999;
Key[1] := 8888;
Key[2] := 7777;
Key[3] := 6666;
Data[0] := 1357;
Data[1] := 2468;
xtea.Crypt (Key, Data);
xtea.Decrypt (Key, Data);
finally
xtea.Free;
end;
end;