S
super-ljc
Unregistered / Unconfirmed
GUEST, unregistred user!
用以下从网上得来程序加解密能加但无法还原请高手给指点!!!
//字符串加密函数
function Encrypt(const S: string
Key: Word): string;
var
I: Integer;
begin
Result := S;
for I := 1 to Length(S) do
begin
Result := char(byte(S) xor (Key shr 8));
Key := (byte(Result) + Key) * C1 + C2;
if Result = Chr(0) then
Result := S;
end;
Result := StrToHex(Result);
end;
//字符串解密函数
function Decrypt(const S: string
Key: Word): string;
var
I: Integer;
S1: string;
begin
S1 := HexToStr(S);
Result := S1;
for I := 1 to Length(S1) do
begin
if char(byte(S1) xor (Key shr 8)) = Chr(0) then
begin
Result := S1;
Key := (byte(Chr(0)) + Key) * C1 + C2
//保证Key的正确性
end
else
begin
Result := char(byte(S1) xor (Key shr 8));
Key := (byte(S1) + Key) * C1 + C2;
end;
end;
end;
以下我我写加解表字段的FUNCTION 但无法还原!其中MKMBM=STRING(9) MKMMC=STRING(40)
function encrypt_mc_bm: boolean
//加密科目名称和编码
var
s1, s2, s3, s4: string;
i:integer;
begin
with getnewdataset do
begin
try
close;
commandtext := 'select mkmbm,mkmmc from mkmbm ';
open;
while not eof do
begin
i:=recno;
if i>65535 then break;
s1 := fieldbyname('mkmbm').AsString;
s2 := fieldbyname('mkmmc').AsString;
s3 := encrypt(s1, i);
s4 := encrypt(s2, i);
edit;
fieldbyname('mkmbm').AsString := s3;
fieldbyname('mkmmc').AsString := s4;
next;
end;
if State in [dsedit, dsinsert] then post;
close;
finally
free;
end;
result := true;
end;
end;
function decrypt_mc_bm: boolean
//解密科目名称和编码
var
s1, s2, s3, s4: string;
i:integer;
begin
with getnewdataset do
begin
try
close;
commandtext := 'select mkmbm,mkmmc from mkmbm ';
open;
while not eof do
begin
i:=recno;
if i>65535 then break;
s1 := fieldbyname('mkmbm').AsString;
s2 := fieldbyname('mkmmc').AsString;
s3 := decrypt(s1, i);
s4 := decrypt(s2, i);
edit;
fieldbyname('mkmbm').AsString := s3;
fieldbyname('mkmmc').AsString := s4;
next;
end;
if State in [dsedit, dsinsert] then post;
close;
finally
free;
end;
result := true;
end;
end;
其中 mkmbm and mkmmc是不重复键!能加密无法解解出来不全或与前一个重复!
//字符串加密函数
function Encrypt(const S: string
Key: Word): string;
var
I: Integer;
begin
Result := S;
for I := 1 to Length(S) do
begin
Result := char(byte(S) xor (Key shr 8));
Key := (byte(Result) + Key) * C1 + C2;
if Result = Chr(0) then
Result := S;
end;
Result := StrToHex(Result);
end;
//字符串解密函数
function Decrypt(const S: string
Key: Word): string;
var
I: Integer;
S1: string;
begin
S1 := HexToStr(S);
Result := S1;
for I := 1 to Length(S1) do
begin
if char(byte(S1) xor (Key shr 8)) = Chr(0) then
begin
Result := S1;
Key := (byte(Chr(0)) + Key) * C1 + C2
//保证Key的正确性
end
else
begin
Result := char(byte(S1) xor (Key shr 8));
Key := (byte(S1) + Key) * C1 + C2;
end;
end;
end;
以下我我写加解表字段的FUNCTION 但无法还原!其中MKMBM=STRING(9) MKMMC=STRING(40)
function encrypt_mc_bm: boolean
//加密科目名称和编码
var
s1, s2, s3, s4: string;
i:integer;
begin
with getnewdataset do
begin
try
close;
commandtext := 'select mkmbm,mkmmc from mkmbm ';
open;
while not eof do
begin
i:=recno;
if i>65535 then break;
s1 := fieldbyname('mkmbm').AsString;
s2 := fieldbyname('mkmmc').AsString;
s3 := encrypt(s1, i);
s4 := encrypt(s2, i);
edit;
fieldbyname('mkmbm').AsString := s3;
fieldbyname('mkmmc').AsString := s4;
next;
end;
if State in [dsedit, dsinsert] then post;
close;
finally
free;
end;
result := true;
end;
end;
function decrypt_mc_bm: boolean
//解密科目名称和编码
var
s1, s2, s3, s4: string;
i:integer;
begin
with getnewdataset do
begin
try
close;
commandtext := 'select mkmbm,mkmmc from mkmbm ';
open;
while not eof do
begin
i:=recno;
if i>65535 then break;
s1 := fieldbyname('mkmbm').AsString;
s2 := fieldbyname('mkmmc').AsString;
s3 := decrypt(s1, i);
s4 := decrypt(s2, i);
edit;
fieldbyname('mkmbm').AsString := s3;
fieldbyname('mkmmc').AsString := s4;
next;
end;
if State in [dsedit, dsinsert] then post;
close;
finally
free;
end;
result := true;
end;
end;
其中 mkmbm and mkmmc是不重复键!能加密无法解解出来不全或与前一个重复!