加密高手请进!
用它加密登录密码时, 空密码可以用任何单字密码进去。并且奇数密码不可用 !
请高手指点!!
unit EncodeText;
interface
uses
SysUtils;
type
TPasswordEncode = Class
private
FKey: Char;
FDecodeText: string;
FEncodeText: string;
protected
procedure Encode; virtual;
procedure Decode; virtual;
public
constructor Create;
property Key: Char read FKey write FKey default 'A';
function GetEncodeText(const DecodeText: string): string;
function GetDecodeText(const EncodeText: string): string;
end;
implementation
{ TPasswordEncode }
constructor TPasswordEncode.Create;
begin
FKey := 'A';
end;
{--------------------------------------------------------------
----------------------- 加密算法 ------------------------------
---------------------------------------------------------------}
//我的加密算法很简单,只是每个Char加上Key,你若需要复杂的算法,可以重载它
procedure TPasswordEncode.Encode;
var
iLength, I, EncVal: Integer;
begin
iLength := Length(FDecodeText);
SetLength(FEncodeText, iLength);
for I := 1 to iLength do
begin
EncVal := (Ord(FDecodeText[I]) + Ord(Key)) mod 256;
FEncodeText[I] := Chr(EncVal);
end;
end;
{--------------------------------------------------------------
----------------------- 解密算法 ------------------------------
---------------------------------------------------------------}
procedure TPasswordEncode.Decode;
var
iLength, I, EncVal: Integer;
begin
iLength := Length(FEncodeText);
SetLength(FDecodeText, iLength);
for I := 1 to iLength do
begin
EncVal := (Ord(FEncodeText[I]) - Ord(Key)) mod 256;
FDecodeText[I] := Chr(EncVal);
end;
end;
function TPasswordEncode.GetEncodeText(const DecodeText: string): string;
begin
FDecodeText:= DecodeText;
Encode;
Result := FEncodeText;
end;
function TPasswordEncode.GetDecodeText(const EncodeText: string): string;
begin
FEncodeText := EncodeText;
Decode;
Result := FDecodeText;
end;
end.