当前位置:首页 > 代码 > 正文

delphi代码加密(Delphi技术)

admin 发布:2022-12-19 04:58 120


今天给各位分享delphi代码加密的知识,其中也会对Delphi技术进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

delphi 加密算法

我用的加密解密

function EncryptString(Source, Key: string): string;

//对字符串加密(Source:源 Key:密匙)

var

KeyLen: integer;

KeyPos: integer;

Offset: integer;

Dest: string;

SrcPos: integer;

SrcAsc: integer;

Range: integer;

begin

KeyLen := Length(Key);

if KeyLen = 0 then

Key := 'delphi';

KeyPos := 0;

Range := 256;

randomize;

Offset := random(Range);

Dest := format('%1.2x', [Offset]);

for SrcPos := 1 to Length(Source) do

begin

SrcAsc := (Ord(Source[SrcPos]) + Offset) mod 255;

if KeyPos KeyLen then

KeyPos := KeyPos + 1

else

KeyPos := 1;

SrcAsc := SrcAsc xor Ord(Key[KeyPos]);

Dest := Dest + format('%1.2x', [SrcAsc]);

Offset := SrcAsc;

end;

result := Dest;

end;

function UnEncryptString(Source, Key: string): string;

//对字符串解密(Src:源 Key:密匙)

var

KeyLen: integer;

KeyPos: integer;

Offset: integer;

Dest: string;

SrcPos: integer;

SrcAsc: integer;

TmpSrcAsc: integer;

begin

KeyLen := Length(Key);

if KeyLen = 0 then

Key := 'delphi';

KeyPos := 0;

Offset := strtoint('$' + copy(Source, 1, 2));

SrcPos := 3;

repeat

SrcAsc := strtoint('$' + copy(Source, SrcPos, 2));

if KeyPos KeyLen then

KeyPos := KeyPos + 1

else

KeyPos := 1;

TmpSrcAsc := SrcAsc xor Ord(Key[KeyPos]);

if TmpSrcAsc = Offset then

TmpSrcAsc := 255 + TmpSrcAsc - Offset

else

TmpSrcAsc := TmpSrcAsc - Offset;

Dest := Dest + chr(TmpSrcAsc);

Offset := SrcAsc;

SrcPos := SrcPos + 2;

until SrcPos = Length(Source);

result := Dest;

end;

Delphi加密算法

你要是只对数字进行加密,加密后的密文也是数字,其实你就加个运算就可以了。比如 对123进行加密:用 123*564 加密后是69372,,解密就用 69372去除以564 就可以了,,这个是最简单的方法了,你可以把这个运算写的复杂一些!

用Delphi制作文本文档程序,在文本中内容加密,我的思路是把文本内容打成乱码,在点击“解密”变回原来的

我以前也做过这种小程序。这个算法你可以自己设计,也可以用像什么MD5之类的加解密算法咯。

但因为不能粘贴附件,所以就贴点代码。

procedure TForm1.N2Click(Sender: TObject);//打开文件

var

tl:string;

begin

if OpenDialog1.Execute then

begin

ListBox1.Clear;

Caption:='文件加密解密器'+OpenDialog1.FileName;

AssignFile(ATextFile,OpenDialog1.FileName);

Reset(ATextFile);

while not eof(ATextFile) do

begin

Readln(ATextFile,tl);

ListBox1.Items.Add(tl);

end;

CloseFile(ATextFile);

end;

end;

function Encode(s:string):string;//加密的核心部分

var

n,i:integer;

str:string;

begin

n:=length(s);

str:='';

for i:=1 to n do

begin

str:=str+char(ord(s[i])+10);

end;

Encode:=str;

end;

function Decode(s:string):string;//解密的核心部分

var

n,i:integer;

str:string;

begin

n:=length(s);

str:='';

for i:=1 to n do

begin

str:=str+char(ord(s[i])-10);

end;

Decode:=str;

end;

procedure TForm1.N3Click(Sender: TObject);//加密

var

ln:integer;

tl,nl:string;

begin

if SaveDialog1.Execute then

begin

AssignFile(ATextFile,SaveDialog1.FileName);

Rewrite(ATextFile);

for ln:=0 to ListBox1.Items.Count-1 do

begin

tl:=ListBox1.Items[ln];

nl:=Encode(tl);//加密

Writeln(ATextFile,nl);

end;

CloseFile(ATextFile);

end;

end;

procedure TForm1.N4Click(Sender: TObject);//解密

var

ln:integer;

tl,nl:string;

begin

if SaveDialog1.Execute then

begin

AssignFile(AtextFile,SaveDialog1.FileName);

Rewrite(ATextFile);

for ln:=0 to ListBox1.Items.Count-1 do

begin

tl:=ListBox1.Items[ln];

nl:=Decode(tl);//解密

Writeln(ATextFile,nl);

end;

CloseFile(ATextFile);

end;

end;

delphi 中的 MD5 加密怎么用

1.在Delphi自带的Indy控件中其实是提供了MD2,MD4,MD5对象的,可以直接使用来完成MD5的签名算法。不需要DLL或是Pas。 2.在Uses单元中引用 IdHashMessageDigest,IdGlobal, IdHash 单元,再写如下代码即可以达到MD5的实现。

delphi 如何写代码才能连接加密的DBISAM数据库

我们要解密数据库当然是对当前要对数据库提出连接申请的那个“用户”进行密码身份验证,只有这个“用户”在通过了验证后才可以对数据库进行访问,其它的每个连接需要连接数据库时都要进行各自的密码身份验证即解密过程。明白了DBISAMSession控件的原理后,就开始看看怎么使用这个控件来达到解密数据库的功能吧。当然第一步是把DBISAMSession控件拖放到设计窗体上,接下来就是修改控件的属性和修改一些代码了。在这里只需要为这个控件的SessionName属性值取一个名字比如session1。然后先把DBISAMDatabase1控件的Connected属性值设为False,再把SessionName属性指定为session1,再在DBISAMDatabase1控件的BeforeConnect事件(点Delphi对像窗口的Event标签页)中写如下代码:DBISAMSession1.AddPassword('Your

password');注意在上面的字符串'Your

password'中必须添入你自己设定的数据库访问密码。还需要修改DBISAMTable1控件的属性,同样也是先把它的Active属性值设为False,再把SessionName属性指定为session1。

delphi实现DES字节流加密,该怎么解决

在 CnPack 提供的源代码包里,提供了 des 加解密单元文件,提供了以下四个功能函数:

function DESEncryptStr(Str, Key: AnsiString): AnsiString;

{* 传入明文与加密 Key,DES 加密返回密文,

注:由于密文可能含有扩展 ASCII 字符,因此在 DELPHI 2009 或以上版本中,请用

AnsiString 类型的变量接收返回值,以避免出现多余的 Unicode 转换而导致解密出错}

function DESDecryptStr(Str, Key: AnsiString): AnsiString;

{* 传入密文与加密 Key,DES 解密返回明文}

function DESEncryptStrToHex(Str, Key: AnsiString): AnsiString;

{* 传入明文与加密 Key,DES 加密返回转换成十六进制的密文}

function DESDecryptStrFromHex(StrHex, Key: AnsiString): AnsiString;

{* 传入十六进制的密文与加密 Key,DES 解密返回明文}

delphi代码加密的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于Delphi技术、delphi代码加密的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/2753.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载