⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 想知道程序是如何实现加密解密的嘛? 那么来下载去看看吧
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, NMURL, Menus, Buttons,ShlObj, ExtCtrls, Gauges,shellapi,registry;


type
  TForm1 = class(TForm)
    NMURL1: TNMURL;
    Image1: TImage;
    Label1: TLabel;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    N3: TMenuItem;
    N9: TMenuItem;
    N7: TMenuItem;
    N8: TMenuItem;
    N10: TMenuItem;
    N4: TMenuItem;
    N2: TMenuItem;
    N5: TMenuItem;
    Gauge1: TGauge;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    procedure N4Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
  private
    { Private declarations }

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses register;

{$R *.dfm}
function BrowseFolder:string;
var
  Info:TBrowseInfo;         //  加ExtDlgs 单元     ShlObj,
  Dir:array[0..260] of char;
  ItemId:PItemIDList;
begin
  with Info do
  begin
    hwndOwner:=Form1.Handle;
    pidlRoot:=nil;
    pszDisplayName:=nil;
    lpszTitle:='请选择保存目录:';
    ulFlags:=0;
    lpfn:=nil;
    lParam:=0;
    iImage:=0;
  end;
  ItemId:=SHBrowseForFolder(Info);
  if ItemId<>nil then
  begin
  SHGetPathFromIDList(ItemId,@Dir);
  Result:=string(Dir);
  end;
end;


procedure TForm1.N4Click(Sender: TObject);
begin
exit;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
OpenDialog1.Execute;
SpeedButton2.Enabled:=true;
SpeedButton3.Enabled:=true;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
var
dir:string;
i,j:integer;
strlist:tstringlist;
myfilename,tempstr,listtemp:string;

Reg:TRegistry;
myRegstr:string;

function encodeurl(urlstr: string):string;      //---------encodeurl
var
onelist:tstringlist;
twolist:tstringlist;
mytemp,onetemp:string;
i,total:integer;
begin
onelist:= TStringList.Create;
twolist:= TStringList.Create;
mytemp:=urlstr;             //输入未加密
total:=length(mytemp);
i:=1;
while i<=total do
begin

if ord(mytemp[i])<=126 then  //不是中文
begin
onetemp:='';
while (i<=total) and (ord(mytemp[i])<=126)  do  //--判断
begin
onetemp:=onetemp+mytemp[i];
i:=i+1;
end;
NMURL1.InputString:=onetemp;

onelist.Add(NMURL1.Encode); //加入第一个链表
end //end不是中文
else
begin
onetemp:='';
while (i<=total) and (ord(mytemp[i])>126)  do  //--判断
begin
onetemp:=onetemp+mytemp[i];
i:=i+1;
end;
twolist.Add(onetemp); //加入第一个链表
end //end是中文
end;//endwhile

mytemp:='';
i:=0;

while (i<onelist.Count) or (i<twolist.Count) do   //把字符串装配起来
begin

if i<onelist.Count then
mytemp:=mytemp+onelist.Strings[i];
if i<twolist.Count then
mytemp:=mytemp+twolist.Strings[i];
i:=i+1;

end;//endwhile
onelist.Free;
twolist.Free;
result:=mytemp;  //输出 加密


end;

begin       //++++++++++++++++++++++++++++++++++加密+++++++++++++++++++++++++++++++++

if  OpenDialog1.Files.Count=0 then
begin
  MessageBox(form1.Handle,'至少选择一个文件','网页加密',MB_ok or
                    MB_ICONQUESTION);
exit;
end;
Dir:=BrowseFolder;
if dir='' then
begin
  MessageBox(form1.Handle,'请选择目录','网页加密',MB_ok or
                    MB_ICONQUESTION);
exit;
end;


Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
Reg.OpenKey('SOFTWARE\Microsoft\DataAccess\RootBinder\nds',True);
myRegstr:=Reg.readstring('set');
reg.CloseKey;
Reg.Free;
if myRegstr<>'1' then
begin
if  OpenDialog1.Files.Count>1 then
begin
  MessageBox(form1.Handle,'未注册用户每次只能选择一个文件,如你想获得软件的完整功能,请注册本软件!','网页加密',MB_ok or
                    MB_ICONQUESTION);
                    SpeedButton2.Enabled:=false;
SpeedButton3.Enabled:=false;
                    exit;
                    end;

end;







Gauge1.Visible:=true;
Gauge1.MinValue:=0;
Gauge1.MaxValue:=OpenDialog1.Files.Count;

for i:=0 to OpenDialog1.Files.Count-1 do
begin
strlist:= TStringList.Create;
strlist.LoadFromFile(OpenDialog1.Files.Strings[i]); //读入文件
strlist.Text:=encodeurl(strlist.Text);                     //加密
tempstr:='';
listtemp:=strlist.Text;
for j:=1 to strlen(pchar(listtemp)) do
begin
if  listtemp[j]='+' then
 tempstr:=tempstr+' '
 else if (listtemp[j]<>#13)  and  (listtemp[j]<>#10) then
 tempstr:=tempstr+listtemp[j];
end;
tempstr:='<SCRIPT>var Words="'+tempstr+'";document.write(unescape(Words))</SCRIPT>';
strlist.Text:=tempstr;


myfilename:=ExtractFileName(OpenDialog1.Files.Strings[i]);
myfilename:=dir+'\'+myfilename;
if FileExists(myfilename) then
begin
tempstr:=myfilename+#13+'此文件已存在,是否覆盖';
case Application.MessageBox(pchar(tempstr),'资料管理器',MB_YESNO or
                    MB_ICONQUESTION) of

IDyes:
begin
FileSetAttr(myfilename,faArchive);    //去掉只读属性
DeleteFile(myfilename);
end;
end;
end;

strlist.SaveToFile(myfilename);
Gauge1.Progress:=Gauge1.Progress+1;

end; //endfor
sleep(1000);
Gauge1.Visible:=false;
Gauge1.Progress:=0;
SpeedButton2.Enabled:=false;
SpeedButton3.Enabled:=false;
end;       //+++++++++++++++++++++++++++++++加密+++++++++++++++++++++++++++++++++++++++




procedure TForm1.SpeedButton3Click(Sender: TObject);
var
dir:string;
i,j:integer;
strlist:tstringlist;
myfilename,tempstr,listtemp:string;

Reg:TRegistry;
myRegstr:string;

function Decodeurl(urlstr: string):string;      //---------Decodeurl
var
onelist:tstringlist;
twolist:tstringlist;
mytemp,onetemp:string;
i,total:integer;
begin
onelist:= TStringList.Create;
twolist:= TStringList.Create;
mytemp:=urlstr;             //输入未加密
total:=length(mytemp);
i:=1;
while i<=total do
begin

if ord(mytemp[i])<=126 then  //不是中文
begin
onetemp:='';
while (i<=total) and (ord(mytemp[i])<=126)  do  //--判断
begin
onetemp:=onetemp+mytemp[i];
i:=i+1;
end;
NMURL1.InputString:=onetemp;

onelist.Add(NMURL1.Decode); //加入第一个链表
end //end不是中文
else
begin
onetemp:='';
while (i<=total) and (ord(mytemp[i])>126)  do  //--判断
begin
onetemp:=onetemp+mytemp[i];
i:=i+1;
end;
twolist.Add(onetemp); //加入第一个链表
end //end是中文
end;//endwhile

mytemp:='';
i:=0;

while (i<onelist.Count) or (i<twolist.Count) do   //把字符串装配起来
begin

if i<onelist.Count then
mytemp:=mytemp+onelist.Strings[i];
if i<twolist.Count then
mytemp:=mytemp+twolist.Strings[i];
i:=i+1;

end;//endwhile
onelist.Free;
twolist.Free;
result:=mytemp;  //输出 加密


end;

begin    //++++++++++++++++++解密++++++++++++++++++++++++++++++++++++++++++++++

if  OpenDialog1.Files.Count=0 then
begin
  MessageBox(form1.Handle,'至少选择一个文件','网页加密',MB_ok or
                    MB_ICONQUESTION);
exit;
end;
Dir:=BrowseFolder;
if dir='' then
begin
  MessageBox(form1.Handle,'请选择目录','网页加密',MB_ok or
                    MB_ICONQUESTION);
exit;
end;



Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
Reg.OpenKey('SOFTWARE\Microsoft\DataAccess\RootBinder\nds',True);
myRegstr:=Reg.readstring('set');
reg.CloseKey;
Reg.Free;
if myRegstr<>'1' then
begin
if  OpenDialog1.Files.Count>1 then
begin
  MessageBox(form1.Handle,'未注册用户每次只能选择一个文件,如你想获得软件的完整功能,请注册本软件!','网页加密',MB_ok or
                    MB_ICONQUESTION);
                    SpeedButton2.Enabled:=false;
SpeedButton3.Enabled:=false;
                    exit;
                    end;

end;







Gauge1.Visible:=true;
Gauge1.MinValue:=0;
Gauge1.MaxValue:=OpenDialog1.Files.Count;

for i:=0 to OpenDialog1.Files.Count-1 do
begin
strlist:= TStringList.Create;
strlist.LoadFromFile(OpenDialog1.Files.Strings[i]); //读入文件
strlist.Text:=Decodeurl(strlist.Text);                     //解密
tempstr:='';
listtemp:=strlist.Text;
 {
for j:=1 to strlen(pchar(listtemp)) do
begin
if  listtemp[j]='+' then
 tempstr:=tempstr+' '
 else if (listtemp[j]<>#13)  and  (listtemp[j]<>#10) then
 tempstr:=tempstr+listtemp[j];
end;
strlist.Text:=tempstr; }
delete(listtemp,1,19);
delete(listtemp,strlen(pchar(listtemp))-43,43);
strlist.Text:=listtemp;
myfilename:=ExtractFileName(OpenDialog1.Files.Strings[i]);
myfilename:=dir+'\'+myfilename;
if FileExists(myfilename) then
begin
tempstr:=myfilename+#13+'此文件已存在,是否覆盖';
case Application.MessageBox(pchar(tempstr),'资料管理器',MB_YESNO or
                    MB_ICONQUESTION) of

IDyes:
begin
FileSetAttr(myfilename,faArchive);    //去掉只读属性
DeleteFile(myfilename);
end;
end;
end;

strlist.SaveToFile(myfilename);
Gauge1.Progress:=Gauge1.Progress+1;

end; //endfor
sleep(1000);
Gauge1.Visible:=false;
Gauge1.Progress:=0;
SpeedButton2.Enabled:=false;
SpeedButton3.Enabled:=false;
end;     //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -