诸
诸葛白痴
Unregistered / Unconfirmed
GUEST, unregistred user!
这是一个加解密函数,其中tsUserName代表是一个注册公司名称,tdDate代表注册日期,谁能帮
我解开这个函数啊,给个解密思路也行,我实在反推不出来啊,谢谢!!!
function DecryptKey(tsUserName:string;
tsKey:string;
tdDate:TDate;
lShowRegist:Boolean=True):Boolean;
var nYear,nMonth,nDay :word;
ts :string;
aPlain,aCipher :Array[1..8] of integer;
i,n :integer;
lResult :Boolean;
begin
if tdDate < EncodeDate(2002,1,1) then
begin
Result :=True;
Exit;
end;
lResult :=False;
tsUserName :=Trim(tsUserName);
if Length(tsUserName) >=8 then
if Length(tsKey) =8 then
//tsKey是注册码,我现在就是不知如何算出这个注册码
begin
ts :=Copy(UpperCase(tsKey), 1, 8);
//根据注册码换算成比较码
for i :=1 to 8 do
aPlain :=(Ord(ts) -Ord('A')) mod 26;
aCipher[1] :=23*aPlain[1] + 20*aPlain[2] + 5*aPlain[3] + 1*aPlain[4];
aCipher[2] :=2*aPlain[1] + 11*aPlain[2] + 18*aPlain[3] + 1*aPlain[4];
aCipher[3] :=2*aPlain[1] + 20*aPlain[2] + 6*aPlain[3] + 25*aPlain[4];
aCipher[4] :=25*aPlain[1] + 2*aPlain[2] + 22*aPlain[3] + 25*aPlain[4];
aCipher[5] :=23*aPlain[5] + 20*aPlain[6] + 5*aPlain[7] + 1*aPlain[8];
aCipher[6] :=2*aPlain[5] + 11*aPlain[6] + 18*aPlain[7] + 1*aPlain[8];
aCipher[7] :=2*aPlain[5] + 20*aPlain[6] + 6*aPlain[7] + 25*aPlain[8];
aCipher[8] :=25*aPlain[5] + 2*aPlain[6] + 22*aPlain[7] + 25*aPlain[8];
for i :=1 to 8 do
aCipher :=(aCipher mod 26);
DecodeDate(tdDate, nYear,nMonth,nDay);
n :=(nYear -2002) *12 +nMonth;
n :=n mod 26 +1;
//根据注册公司名生成注册原码
ts :=tsUserName;
for i :=1 to 8 do
aPlain :=n;
for i :=Length(ts) do
wnto 1 do
aPlain[i mod 8 +1] :=(aPlain[i mod 8 +1] *Ord(ts)) mod 26 +1;
for i :=1 to 8 do
aPlain :=aPlain mod 26;
//生成完毕
lResult :=True;
for i :=1 to 8 do
if aPlain <> aCipher then
begin
lResult :=False;
Break;
end;
end;
if lResult then
Result :=True
else
if lShowRegist then
begin
frmSoftRegist :=TfrmSoftRegist.Create(nil);
Result :=frmSoftRegist.ShowRegist(tdDate);
frmSoftRegist.Release;
end
else
Result :=False;
end;
我解开这个函数啊,给个解密思路也行,我实在反推不出来啊,谢谢!!!
function DecryptKey(tsUserName:string;
tsKey:string;
tdDate:TDate;
lShowRegist:Boolean=True):Boolean;
var nYear,nMonth,nDay :word;
ts :string;
aPlain,aCipher :Array[1..8] of integer;
i,n :integer;
lResult :Boolean;
begin
if tdDate < EncodeDate(2002,1,1) then
begin
Result :=True;
Exit;
end;
lResult :=False;
tsUserName :=Trim(tsUserName);
if Length(tsUserName) >=8 then
if Length(tsKey) =8 then
//tsKey是注册码,我现在就是不知如何算出这个注册码
begin
ts :=Copy(UpperCase(tsKey), 1, 8);
//根据注册码换算成比较码
for i :=1 to 8 do
aPlain :=(Ord(ts) -Ord('A')) mod 26;
aCipher[1] :=23*aPlain[1] + 20*aPlain[2] + 5*aPlain[3] + 1*aPlain[4];
aCipher[2] :=2*aPlain[1] + 11*aPlain[2] + 18*aPlain[3] + 1*aPlain[4];
aCipher[3] :=2*aPlain[1] + 20*aPlain[2] + 6*aPlain[3] + 25*aPlain[4];
aCipher[4] :=25*aPlain[1] + 2*aPlain[2] + 22*aPlain[3] + 25*aPlain[4];
aCipher[5] :=23*aPlain[5] + 20*aPlain[6] + 5*aPlain[7] + 1*aPlain[8];
aCipher[6] :=2*aPlain[5] + 11*aPlain[6] + 18*aPlain[7] + 1*aPlain[8];
aCipher[7] :=2*aPlain[5] + 20*aPlain[6] + 6*aPlain[7] + 25*aPlain[8];
aCipher[8] :=25*aPlain[5] + 2*aPlain[6] + 22*aPlain[7] + 25*aPlain[8];
for i :=1 to 8 do
aCipher :=(aCipher mod 26);
DecodeDate(tdDate, nYear,nMonth,nDay);
n :=(nYear -2002) *12 +nMonth;
n :=n mod 26 +1;
//根据注册公司名生成注册原码
ts :=tsUserName;
for i :=1 to 8 do
aPlain :=n;
for i :=Length(ts) do
wnto 1 do
aPlain[i mod 8 +1] :=(aPlain[i mod 8 +1] *Ord(ts)) mod 26 +1;
for i :=1 to 8 do
aPlain :=aPlain mod 26;
//生成完毕
lResult :=True;
for i :=1 to 8 do
if aPlain <> aCipher then
begin
lResult :=False;
Break;
end;
end;
if lResult then
Result :=True
else
if lShowRegist then
begin
frmSoftRegist :=TfrmSoftRegist.Create(nil);
Result :=frmSoftRegist.ShowRegist(tdDate);
frmSoftRegist.Release;
end
else
Result :=False;
end;