关于算法的小小问题--请拉妹妹我一把!(20分)

  • 主题发起人 主题发起人 衫菜
  • 开始时间 开始时间

衫菜

Unregistered / Unconfirmed
GUEST, unregistred user!
我要把一个STRING类型的字符串通过位移SHL或者SHR来进行加密,
还要能解密,请大家帮我想想有什么办法吗?
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, ImgList;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
ListView1: TListView;
Button3: TButton;
Button4: TButton;
ImageList1: TImageList;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure ListView1CustomDraw(Sender: TCustomListView;
const ARect: TRect; var DefaultDraw: Boolean);
private
procedure WMGetMinMaxInfo( var Message :TWMGetMinMaxInfo );message WM_GetMinMaxInfo;
procedure e(var msg:twmnchittest);message wm_nchittest;
{ Private declarations }
public
nm,ni:integer;

{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Unit2, Unit3;

{$R *.DFM}
procedure tform1.e(var msg:twmnchittest);
begin
inherited;
if msg.Result in [HTBOTTOM,HTBOTTOMLEFT,HTBOTTOMRIGHT,HTLEFT,
HTRIGHT,HTTOP,HTTOPLEFT ,HTTOPRIGHT ]
then
msg.Result:=windows.HTNOWHERE;
end;
procedure TForm1.WMGetMinMaxInfo( var Message :TWMGetMinMaxInfo );
begin

with Message.MinMaxInfo^ do
begin
ptMaxSize.X := form1.Width;
ptMaxSize.Y := form1.Height;
ptMaxPosition.X :=form1.Left;
ptMaxPosition.Y :=form1.Top;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var a:string;
i:integer;
q:tlistitem;
begin
if not OpenDialog1.Execute then
begin
exit;
end;

if OpenDialog1.Files.Count>0 then begin

for i:=0 to OpenDialog1.Files.Count-1 do
begin
a:= OpenDialog1.Files;
q:=listview1.Items.add;
q.Caption:=a;
end;
end;
end;



procedure TForm1.Button2Click(Sender: TObject);
var
f: file of Byte;
S,t: Byte;
i,j:integer;
size:longint;
qq,ww:string;
msgs:boolean;
begin
form1.ni:=0;
form2.Edit1.Text:='';
form2.Edit2.Text:='';
form2.showmodal;
if form1.ni=0 then exit;
msgs:=true;
for j:=0 to form1.listview1.Items.Count-1 do
begin //循环起
AssignFile(F, form1.listview1.Items[j].Caption);
try
Reset(F);
except
msgs:=false;
form1.ListView1.Items[j].ImageIndex:=1;
continue;
end;
form1.ListView1.Items[j].ImageIndex:=2;
size:=filesize(f);
if size<=1 then exit;
for i:=1 to size-1 do
begin
seek(F,i-1);//移动文件F,I-1个位置。
Read(F, S);
seek(F,i);
Read(F, t);
seek(F,i);
s:=t xor s;
write(F,s);
end;
seek(F,size-1);
Read(F, t);
seek(F,0);
Read(F, s);
seek(F,0);
s:=t xor s;
write(F,s);
{}
qq:=form2.edit1.Text;
for i:=2 to length(qq) do
begin
qq:=char(byte(qq[i-1]) xor byte(qq));
end;
qq[1]:=char(byte(qq[1]) xor byte(qq[length(qq)]));
for i:=1 to length(qq) do
begin
seek(F,i+size-1);
s:=byte(qq);
write(f,s);
end;
CloseFile(F);

end; //循环止
if msgs=true then
showmessage('全部成功!')
else
showmessage('红叉标记文件不能打开,不能加密.');
end;
procedure TForm1.Button3Click(Sender: TObject);
var
f: file of Byte;
S,t: Byte;
j,i:integer;
size:longint;
qq1,qq:string;
msgs:boolean;
begin
form1.nm:=0;
form3.Edit1.Text:='';
form3.showmodal;
if form1.nm=0 then exit;
msgs:=true;
for j:=0 to form1.listview1.Items.Count-1 do
begin
qq:='';
AssignFile(F, form1.listview1.Items[j].Caption);
try
Reset(F);
except
msgs:=false;
form1.ListView1.Items[j].ImageIndex:=1;
continue;
end;
size:=filesize(f);
if size<=1+length(form3.edit1.Text) then exit;

seek(f,size-1);
read(f,s);
seek(f,size-length(form3.edit1.Text));
read(f,t);
seek(f,size-length(form3.edit1.Text));
s:= t xor s;
write(f,s);
qq1:=char(s );
for i:= size-1 downto size-length(form3.edit1.Text)+1 do
begin
seek(F,i);
Read(F, t);
seek(F,i-1);
Read(F, s);
seek(F,i);
s:=t xor s;
qq:=string(char(s))+qq;
end;
if qq1+qq<>form3.edit1.Text then
begin
seek(f,size-1);
read(f,s);
seek(f,size-length(form3.edit1.Text));
read(f,t);
seek(f,size-length(form3.edit1.Text));
s:= t xor s;
write(f,s);
form1.ListView1.Items[j].ImageIndex:=3;
msgs:=false;
continue;
end;

seek(F,size-length(form3.edit1.Text)-1);
Read(F, t);
seek(F,0);
Read(F, s);
seek(F,0);
s:=t xor s;
write(f,s);

for i:=size-length(form3.edit1.Text)-1 downto 1 do
begin
seek(F,i);
Read(F, S);
seek(F,i-1);
Read(F, t);
seek(F,i);
s:=t xor s;
write(f,s);
end;
seek(f,size-length(form3.edit1.Text));
Truncate(f);
CloseFile(F);
form1.ListView1.Items[j].ImageIndex:=0;
end;
if msgs=true then
showmessage('全部成功!')
else showmessage('红叉标记文件不能打开,不能加密.'+#10+#10+'黑叉标记文件密码不对.');
end;


procedure TForm1.Button4Click(Sender: TObject);
begin
listview1.Items.Clear;
end;

procedure TForm1.ListView1CustomDraw(Sender: TCustomListView;
const ARect: TRect; var DefaultDraw: Boolean);
begin

if listview1.Items.Count<=0 then
begin
button4.Enabled:=false;
button2.Enabled:=false;
button3.Enabled:=false;
end
else
begin
button4.Enabled:=true;
button2.Enabled:=true;
button3.Enabled:=true;
end;
end;

end.
我给你贴个例子,自己仔细提些有用的出来吧
这是网上一个例子。里面有些不要,你自己精选出加密接迷的函数了。
 
去看看base64如何做的
就如下面代码
OutBuf[0]:= B64Table[((InBuf[0] and $FC) shr 2) + 1];
OutBuf[1]:= B64Table[(((InBuf[0] and $03) shl 4) or ((InBuf[1] and $F0) shr 4)) + 1];
OutBuf[2]:= B64Table[(((InBuf[1] and $0F) shl 2) or ((InBuf[2] and $C0) shr 6)) + 1];
OutBuf[3]:= B64Table[(InBuf[2] and $3F) + 1];
 
菜鸟想法:怎么移过去的,怎么移回来
 
给你个控件吧,专做加密的各种算法都有,Crypt听说过吗?给个Mail发给你
 
用XOR吧,加解密用同一个函数就可以了
 
to:tooper
顺便也给我一份。多谢!
 
TO TOOPER:
我的邮箱是:SRFTIC3@EASTDAY.COM,谢谢拉:)
TO LLDHZ:
XOR不安全,太容易被破解拉
 
多人接受答案了。
 
pwxwabcd@371.net,请给我发一个,谢谢.
 
后退
顶部