📄 crypt.pas
字号:
unit crypt;
interface
uses Classes , Windows , SysUtils , Registry , IniFiles , WinSock , dbtables ,
Forms , dmmain,dialogs;
Type
TCpuType = (cpu8086, cpu286, cpu386, cpu486, cpuPentium); //类出CPU的各种类,目前出现的类
Function CpuType : TCpuType;
function GetCpuSerial:String; //获取CPU的型号
function GetWindowVersion : String; //获取WINDOWS的版本号
function GetPhysicalMemory : String; //获取系统的内存的大小
function getIPs: TStrings; //获取本机固定IP地址
function GetLastIP:string; //获取本机动态IP地址
function Get_IP:string;
function PingByName(ComputerName : String) : String;
function Encrypt(const S: String; Key: Word): String;
function Decrypt(const S: String; Key: Word): String;
function Encrypt_Zengzc(const Pwd: String; KeyCrypt: String): String;
function Decrypt_Zengzc(const Pwd: String; KeyCrypt: String): String;
function HexToInt(HexNum : String) : Integer; //16进制的数值转化为10进制的数
function HexToStr(HexNum : String) : String; //16进制的数值转化为ASCII码
function SearchByPYIndexStr(SourceStrs:TStrings;PYIndexStr:string):string;
function GetPYIndexChar( hzchar:string):char;
function GetNormal_Month( Current_Date : TDateTime):String; //获取正常出帐月
function GetCurrentMax_Month( Current_Date_YYYYMMDD : String):String; //获取指定月份的最大出帐年月日
function GetCurrentMin_Month( Current_Date_YYYYMMDD : String):String; //获取指定月份的最小出帐年月日
function GetNextSeq(FilePath : String ; Section : String ; KeyWord : String ; Step : Integer) : String;
//获取指定文件中的指定Section中的关键字的累加Step的数值
function HasInternetConnect:boolean;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function UserEnter_Log(EntryModule : String ; //操作人员登陆时候的模块名称
EntryEvt : String ; //操作人员登陆时候操作的模块的某一个按钮或者事件的名称
Login_Seq : Integer ; //登陆唯一序列号,如果传入参数为-1,则登入;否则为退出登陆
Wk_no : String ; //操作人员登陆工号
Sm : String //具体的操作事件的说明
):Integer; //系统返回登陆序列号
function SaveAndGetSeq(Form_Name : String ; NewSeq : Integer ) : integer ;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function To_Char(DateTimeToChange : TDateTime ; FormatString : String) :string; //根据字符串的格式进行日期型数据的转化。
implementation
const
C1 = 52845;
C2 = 22719;
function Encrypt(const S: String; Key: Word): String;
var
// I: byte; 2000/05/12
i,j: integer; //2000/05/12
begin
//BEGIN 新加密算法2000/05/12
Result := s;
j := 1;
for i := Length(S) downto 1 do
begin
Result[j] := S[i];
j := j + 1;
end;
//END 新加密算法2000/05/12
{原算法,2000/05/12注释
Result := s;
for I := 1 to Length(S) do begin
Result[I] := char(byte(S[I]) xor (Key shr 8));
Key := (byte(Result[I]) + Key) * C1 + C2;
end;
}
end;
function Decrypt(const S: String; Key: Word): String;
//var
// I: byte; 2000/05/12
begin
//BEGIN 新解密算法2000/05/12
Result := Encrypt(S,Key);
//END 新解密算法2000/05/12
{原算法,2000/05/12注释
Result := s;
for I := 1 to Length(S) do begin
Result[I] := char(byte(S[I]) xor (Key shr 8));
Key := (byte(S[I]) + Key) * C1 + C2;
end;
}
end;
function Encrypt_Zengzc(const Pwd: String; KeyCrypt: String): String;
var
Tmp_Pwd : String;
i : integer;
Resu : String;
begin
//曾忠诚写的解密模块 2001/08/21 注释
//解密的方式为:把16进制数按照四个码位的方式转化为ASCII码,在进行倒置,然后扣除CRC码即可
//例如 密码为:0041006300620061 CRC码为:A 则先形成Acba,在形成abcA,然后把‘abcA’扣除A德:abc
// hex --> dec --> ascii
Tmp_Pwd := '' ;
Resu := '';
Encrypt_Zengzc := '';
For i:= 0 to round(Length(Pwd)/4)-1 do
begin
Tmp_Pwd := Copy(Pwd,1+4*i,4); //四个码位的字符(16进制数)
Resu := Resu + HexToStr(Tmp_Pwd);
end;
For i:=Length(Resu) downto Length(KeyCrypt)+1 do
Result := Result + Resu[i];
end;
function Decrypt_Zengzc(const Pwd : String; KeyCrypt : String): String;
var
Pwd_Length , i , Pwd_Int: Integer;
Password_all , Password_all_temp , Pwd_Decrypt : String;
Pwd_Sgl : Char;
begin
//曾忠诚写的加密模块 2001/08/21 注释
//加密的方式为: 密码加一个CRC码后进行倒置在转化为16进制
//例如 密码为:abc CRC码为:A 则先形成abcA,在形成Acba,然后把‘Acba’转化为16进制(四个码位)得:0041006300620061
Password_all_temp:=Pwd+KeyCrypt;
Password_all:='';
for i := Length(Password_all_temp) downto 1 do
Password_all:=Password_all+Password_all_temp[i];
Pwd_Length := Length(Password_all);
Pwd_Decrypt := '';
for i := 1 to Pwd_Length do
begin
Pwd_Sgl := Password_all[i];
Pwd_Int := Ord(Pwd_Sgl);
Pwd_Decrypt := Pwd_Decrypt + IntToHex(Pwd_Int,4);
end;
Result := Pwd_Decrypt;
end;
function HexToInt(HexNum : String) : Integer; //单个16进制(不限制码位)的数值转化为10进制的数
var
HexLeng , I , Tmp_HexSEQ : Integer;
Tmp_Hex : String;
begin
HexLeng := Length(HexNum);
Tmp_HexSEQ := 1 ;
Result:=0;
For I := HexLeng downtO 1 do
begin
Tmp_Hex := HexNum[I];
if (Tmp_Hex='a') or (Tmp_Hex='A') then Tmp_Hex:='10';
if (Tmp_Hex='b') or (Tmp_Hex='B') then Tmp_Hex:='11';
if (Tmp_Hex='c') or (Tmp_Hex='C') then Tmp_Hex:='12';
if (Tmp_Hex='d') or (Tmp_Hex='D') then Tmp_Hex:='13';
if (Tmp_Hex='e') or (Tmp_Hex='E') then Tmp_Hex:='14';
if (Tmp_Hex='f') or (Tmp_Hex='F') then Tmp_Hex:='15';
Result:=Result + StrToInt(Tmp_Hex) * Tmp_HexSEQ ;
Tmp_HexSEQ := Tmp_HexSEQ * 16;
end;
end;
function HexToStr(HexNum : String) : String; //16进制的数值转化为ASCII码
begin
Result := Chr(HexToInt(HexNum));
end;
function PingByName(ComputerName : String) : String;
var
Const_Version_Major : Integer;
Const_Version_Minor : Integer;
Data : WSADATA;
HostEntry : PHostEnt;
// Address : DWORD ;
// IPaddress : LPSTR;
HostNameChar : array[0..63] of Char;
begin
Const_Version_Major:=1;
Const_Version_Minor:=1;
if WSAStartup(MakeWord(Const_Version_Major,Const_Version_Minor),Data)<>0
then Result:='对不起,你的winsock1.1没有安装';
StrPCopy(HostNameChar,ComputerName);
HostEntry := GetHostByName(HostNameChar);
if HostEntry<>nil then
// IPaddress:=Pchar(AnsiString(HostEntry^.h_addr^))
// else
Exit;
// Address := inet_addr(IPaddress);
WSACleanup;
Result := '';
end;
Function Get_IP : String ;
var
I,J : Integer ;
S : String ;
F : Tregistry;
begin
//by zengzc
Result := '' ;
I := 0 ;
F := TRegIstry.create ;
F.RootKey := HKEY_LOCAL_MACHINE ;
F.OpenKey('SYSTEM',false);
F.OpenKey('CurrentControlSet',false);
F.OpenKey('Services',false);
F.OpenKey('Class',false);
F.OpenKey('NetTrans',false);
//打开注册表:HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Class/NetTrans
S := IntToStr(I) ;
for J :=1 to 4-length(S) do S := S+'0' ; //S='0000'
while ((F.OpenKey(S,false)) or (I<100)) do //SET TO THE MAX NIC ADOPTER
begin
if (F.ReadString('IPAddress') <> '') and (F.ReadString('IPAddress') <> '0.0.0.0') then
begin
Result := F.ReadString('IPAddress') ;
F.CloseKey ;
F.Free ;
Exit ;
end;
F.CloseKey ;
F.OpenKey('SYSTEM',false);
F.OpenKey('CurrentControlSet',false);
F.OpenKey('Services',false);
F.OpenKey('Class',false);
F.OpenKey('NetTrans',false);
I := I+1 ;
S := IntToStr(I) ;
for J :=1 to 4-length(S) do
S := '0'+S ;
end ;
F.Free ;
end;
function GetPYIndexChar( hzchar:string):char;
// 获取指定汉字的拼音索引字母,如:“曾”的索引字母是“Z”
begin
case WORD(hzchar[1]) shl 8 + WORD(hzchar[2]) of
$B0A1..$B0C4 : result := 'A';
$B0C5..$B2C0 : result := 'B';
$B2C1..$B4ED : result := 'C';
$B4EE..$B6E9 : result := 'D';
$B6EA..$B7A1 : result := 'E';
$B7A2..$B8C0 : result := 'F';
$B8C1..$B9FD : result := 'G';
$B9FE..$BBF6 : result := 'H';
$BBF7..$BFA5 : result := 'J';
$BFA6..$C0AB : result := 'K';
$C0AC..$C2E7 : result := 'L';
$C2E8..$C4C2 : result := 'M';
$C4C3..$C5B5 : result := 'N';
$C5B6..$C5BD : result := 'O';
$C5BE..$C6D9 : result := 'P';
$C6DA..$C8BA : result := 'Q';
$C8BB..$C8F5 : result := 'R';
$C8F6..$CBF9 : result := 'S';
$CBFA..$CDD9 : result := 'T';
$CDDA..$CEF3 : result := 'W';
$CEF4..$D188 : result := 'X';
$D1B9..$D4D0 : result := 'Y';
$D4D1..$D7F9 : result := 'Z';
else
result := char(0);
end;
end;
// 在指定的字符串列表SourceStrs中检索符合拼音索引字符串PYIndexStr的所有字符串,并返回。
function SearchByPYIndexStr(SourceStrs:TStrings;PYIndexStr:string):string;
label NotFound;
var
i,j :integer;
hzchar :string;
begin
for i:=0 to SourceStrs.Count-1 do
begin
for j:=1 to Length(PYIndexStr) do
begin
hzchar:=SourceStrs[i][2*j-1]+ SourceStrs[i][2*j]; //一个汉字两个字节, by zengzc
if (PYIndexStr[j]<>'?') and (UpperCase(PYIndexStr[j])<>GetPYIndexChar(hzchar))
then goto NotFound;
end;
if result=''
then result := SourceStrs[i]
else result := result + Char(13) + SourceStrs[i];
exit;
NotFound: result:='';
end;
end;
function GetNextSeq(FilePath : String ; Section : String ; KeyWord : String ; Step : integer ) : String;
{输入: FilePath : Sequence所在的路径和文件名 Section : 指定的区域 KeyWord : 指定的关键字
Step : 步长
结果:指定的序列号的内容.初始默认值为:1 }
var
MyIniFile : TIniFile;
NextVal : string;
begin
{具体的例子如下:
有一个文件(序列号),其名称:c:\program files\Sequences_Vip.ini
其中详细的内容如下:
[test_seq]
kkk=1
此时: FilePath = c:\program files\Sequences_Vip.ini
Section = test_seq
KeyWord = kkk
Step = 需要增加的步长
}
MyIniFile:=TIniFile.Create(FilePath);
GetNextSeq:=IntToStr(StrToInt(MyIniFile.ReadString(Section,KeyWord,'1'))+Step);
NextVal:=IntToStr(StrToInt(MyIniFile.ReadString(Section,KeyWord,'1'))+Step);
MyIniFile.WriteString(Section,KeyWord,NextVal);
MyIniFile.Free;
end;
function GetNormal_Month( Current_Date : TDateTime):String;
// 输入 日期型数据,
// 输出 ’YYYYMM ' ,该数据为正常出帐的年月
// 错误 返回'190001'
Var
Current_Year , Current_Month , Current_Day : String;
begin
//获取正常的出帐月
Try
Current_Year := Copy(DateTimeToStr(Current_Date),1,4);
Current_Month := Copy(DateTimeToStr(Current_Date),6,2);
Current_Day := Copy(DateTimeToStr(Current_Date),9,2);
if (StrToInt(Current_Day)<=20) and (Current_Month='01') then
//该月份为正常出帐月的12月
Result:=IntToStr(StrToInt(Current_Year)-1)+'12' //去年的12月
else
begin
if ((StrToInt(Current_Day)>20) and (Current_Month='11')) or (Current_Month='12') then
Result:=Current_Year+'11' //正常的11月份
else
begin
if StrToInt(Current_Month)=11 then //正常的10月份,日期为两个位数
Result:=Current_Year+'10'
else
begin
if StrToInt(Current_Day)>20 then
Result:=Current_Year+Current_Month
else
Result:=Current_Year+'0'+IntToStr(StrToInt(Current_Month)-1);
end
end;
end;
except
Result := '190001';
end;
end;
function GetCurrentMax_Month( Current_Date_YYYYMMDD : String):String;
//输入:年月 ’ YYYYMMDD ' (年月日为当前年月日)
//输出:正常出帐月的最大的出帐日期
//错误的时候输出:111111
var
Current_Year , Current_Month , Current_Day : String;
begin
//获取指定月份的最大出帐年月日
try
Current_Year := Copy ( Current_Date_YYYYMMDD , 1 , 4 ) ;
Current_Month := Copy ( Current_Date_YYYYMMDD , 5 , 2 );
Current_Day := Copy ( Current_Date_YYYYMMDD , 7 , 2 );
if (Current_Month='12') or ((Current_Month='11') and (StrToInt(Current_Day)>20)) then
//正常出帐月为11月,其最大的出帐日期为:1120
Result := Current_Year+'1120'
else
begin
if (StrToInt(Current_Day)<=20) and (Current_Month='01') then
//正常出帐月为12月,其最大的出帐日期为:去年的1231
Result := IntToStr(StrToInt(Current_Year)-1) + '1231'
else
if (StrToInt(Current_Month)>10) then
Result:=Current_Year+IntToStr(StrToInt(Current_Month)-1)+'20'
else
begin
if (StrToInt(Current_Day)>20) then //正常的10月份,日期为两个位数
Result:=Current_Year+Current_Month+'20'
else
Result:=Current_Year+'0'+IntToStr(StrToInt(Current_Month)-1)+'20';
end;
end;
except
Result := '111111';
end;
end;
function GetCurrentMin_Month( Current_Date_YYYYMMDD : String):String;
//输入:年月 ’ YYYYMMDD ' (年月日为当前年月日)
//输出:正常出帐月的最小的出帐日期
//错误的时候输出:111111
var
Current_Year , Current_Month , Current_Day : String;
begin
//获取指定月份的最小出帐年月日
try
Current_Year := Copy ( Current_Date_YYYYMMDD , 1 , 4 ) ;
Current_Month := Copy ( Current_Date_YYYYMMDD , 5 , 2 );
Current_Day := Copy ( Current_Date_YYYYMMDD , 7 , 2 );
if (Current_Month='12') or ((Current_Month='11') and (StrToInt(Current_Day)>20)) then
//正常出帐月为11月,其最大的出帐日期为:1120
Result := Current_Year+'1021'
else
begin
if (StrToInt(Current_Day)<=20) and (Current_Month='01') then
//正常出帐月为12月,其最大的出帐日期为:去年的1231
Result := IntToStr(StrToInt(Current_Year)-1) + '1121'
else
begin
if ((Current_Month='01') and (StrToInt(Current_Day)>20)) or ((Current_Month='01') and (StrToInt(Current_Day)>20)) then
Result:=Current_Year+'0101'
else
if (StrToInt(Current_Month)>11) then
Result:=Current_Year+IntToStr(StrToInt(Current_Month)-2)+'21'
else
begin
if (StrToInt(Current_Day)>20) then //正常的10月份,日期为两个位数
Result:=Current_Year+'0'+IntToStr(StrToInt(Current_Month)-1)+'21'
else
Result:=Current_Year+'0'+IntToStr(StrToInt(Current_Month)-2)+'21';
end;
end;
end;
except
Result := '111111';
end;
end;
function HasInternetConnect:boolean;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -