Delphi程序的时限和加密
Delphi日期时间函数详解
Delphi⽇期时间函数详解各种时间类型之间的转换函数●DateTimeToFileDate函数:定义:DateTimeToFileDate(DateTime: TDateTime): Integer;作⽤:将⼀个TDateTime类型的时间转化为Dos环境中的时间,Dos环境下对时间的访问⽅法和VCL中的TdateTime类型不⼀样,在进⾏⽂件操作时,为了保持时间的⼀致性,需要使⽤DateTimeToFileDate函数进⾏转化,返回的Integer的值就是Dos下的⽤于描述时间的值。
●DateTimeToSystemTime 过程:定义:procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TS ystemTime);作⽤:将⼀个TDateTime类型的时间转换为Win API函数所使⽤的TSystemTime类型,在使⽤WinApi函数操纵时间时⽤到。
●SystemTimeToDateTime 函数:定义:function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTim e;作⽤:将⼀个在WinApi函数中得到的TSysTemTime类型的数转换为TDateTime类型。
●DateTimeToTimeStamp 函数: TimeStampToDateTime 函数:定义:DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;作⽤:⽤于在TDataTime类型与TTimeStamp之间进⾏互相转换。
TDataTime ⽤⼀个doubl e描绘⼀个时间,⽽TTimeStamp则是采⽤两个整形数分别描述时间。
Delphi程序的使用限制和注册
Delphi程序的使用限制和注册
牛世民;何立明;惠晓滨
【期刊名称】《计算机时代》
【年(卷),期】2003(000)001
【摘要】介绍在Delphi环境下,利用注册表类Tregistryinifile为应用程序添加注册要求及对使用次数和使用日期的限制,同时在注册后自动解除这种限制.
【总页数】2页(P24-25)
【作者】牛世民;何立明;惠晓滨
【作者单位】空军工程大学工程学院,陕西,西安,710038;空军工程大学工程学院,陕西,西安,710038;空军工程大学工程学院,陕西,西安,710038
【正文语种】中文
【中图分类】TP3
【相关文献】
1.Delphi数据库应用程序安装注册的完美解决方案 [J], 周凤石
2.如何在Delphi程序中直接使用C语言程序代码 [J], 秦艳友;张云浩;姜迎新
3.用Delphi设计软件注册程序 [J], 王磊;张红梅
4.使用SRP的隐藏安全级别来保护你的桌面安全:使用软件限制策略和受限制的访问令牌,你无需拦截关键应用程序就可以把恶意代码拒之门外 [J], Russell Smith; 黄思维(译者)
5.未经许可,不得非法使用!—利用注册表限制程序的运行 [J], Purple_ti
因版权原因,仅展示原文概要,查看原文内容请购买。
delphi 程序做加密解密
unit dm;interfaceusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Db, ADODB,shellapi,inifiles,Registry, ExtDlgs, Buttons, Grids, DBGrids,nb30,Menus,ComCtrls;typeTdm1 = class(TForm)Function UncrypKey (Src:String; Key:String):string;Function EncrypKey (Src:String; Key:String):string;Function Tdm1.EncrypKey (Src:String; Key:String):string;varidx :integer;KeyLen :Integer;KeyPos :Integer;offset :Integer;dest :string;SrcPos :Integer;SrcAsc :Integer;TmpSrcAsc :Integer;Range :Integer;beginKeyLen:=Length(Key);if KeyLen = 0 then key:='Think Space';KeyPos:=0;SrcPos:=0;SrcAsc:=0;Range:=256;Randomize;offset:=Random(Range);dest:=format('%1.2x',[offset]);for SrcPos := 1 to Length(Src) dobeginSrcAsc:=(Ord(Src[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;Result:=Dest;end;//解密函数Function Tdm1.UncrypKey (Src:String; Key:String):string;varidx :integer;KeyLen :Integer;KeyPos :Integer;offset :Integer;dest :string;SrcPos :Integer;SrcAsc :Integer;TmpSrcAsc :Integer;Range :Integer;beginKeyLen:=Length(Key);if KeyLen = 0 then key:='Think Space';KeyPos:=0;SrcPos:=0;SrcAsc:=0;Range:=256;offset:=StrToInt('$'+ copy(src,1,2));SrcPos:=3;repeatSrcAsc:=StrToInt('$'+ copy(src,SrcPos,2));if KeyPos < KeyLen Then KeyPos := KeyPos + 1 else KeyPos := 1; TmpSrcAsc := SrcAsc xor Ord(Key[KeyPos]);if TmpSrcAsc <= offset thenTmpSrcAsc := 255 + TmpSrcAsc - offsetelseTmpSrcAsc := TmpSrcAsc - offset;dest := dest + chr(TmpSrcAsc);offset:=srcAsc;SrcPos:=SrcPos + 2;until SrcPos >= Length(Src);Result:=Dest;end;//合法性验证procedure Tdm1.Button3Click(Sender: TObject);Reg :TRegistry;Path,path1,t2,str1 :String;beginReg :=TRegistry.Create;Reg.RootKey :=HKEY_LOCAL_MACHINE;if Reg.OpenKey('software\zjzl',True) thenbegintry str1:=Reg.readString('dw');dw:=str1;//UncrypKey (str1,'123');str1:=Reg.readString('authkey');except end;tryif isauth(str1)=false thenbeginshowmessage('您还未注册,请先运行注册程序!');application.Terminate;close;end;except end;end;end;。
delphi制作EXE文件加密器、捆绑、自解压文件及安装程序
delphi制作EXE文件加密器、捆绑、自解压文件及安装程序delphi制作EXE 文件加密器、捆绑、自解压文件及安装程序2007-01-09 13:39:22| 分类: Delphi |字号订阅我们先来说一下如何制作一个EXE 文件加密器吧。
EXE 文件加密器的原理:建立两个文件,一个用来添加资源到另外一个EXE 文件里面,称为添加程序。
另外一个被添加的EXE 文件称为头文件。
该程序的功能是把添加到自己里面的文件读出来。
Windows 下的EXE 文件结构比较复杂,有的程序还有校验和,当发现自己被改变后会认为自己被病毒感染而拒绝执行。
所以我们把文件添加到自己的程序里面,这样就不会改变原来的文件结构了。
我们先写一个添加函数,该函数的功能是把一个文件当作一个流添加到另外一个文件的尾部。
函数如下:Function Cjt_AddtoFile(SourceFile,TargetFile:string):Boolean?varTarget,Source:TFileStream?MyFileSize:integer?begintrySource:=TFileStream.Create(SourceFile,fmOpenRead or fmS hareExclusive)?Target:=TFileStream.Create(TargetFile,fmOpenWrite or fmSh areExclusive)?tryTarget.Seek(0,soFromEnd)?//往尾部添加资源Target.CopyFrom(Source,0)?MyFileSize:=Source.Size+Sizeof(MyFileSize)?//计算资源大小,并写入辅程尾部Target.WriteBuffer(MyFileSize,sizeof(MyFileSize))?finallyTarget.Free?Source.Free?end?exceptResult:=False?Exit?end?Result:=True?end?有了上面的基础,我们应该很容易看得懂这个函数。
Delphi程序示例
Delphi程序加密示例以下为具有读写、限时功能的五型加密锁加密示例加密对象Delphi环境下编写的程序(DelphiSample),在本例中DelphiSample是一个简单的界面程序。
加密目的对DelphiSample程序进行内嵌加密后,只有通过对应的加密锁才能打开DelphiSample 程序(即显示界面),否则不能打开。
通过限时控制(设定一至三个期限及解开期限的相应密码),控制用户的使用期限;达到加密强度高、程序运行稳定、使用便捷的目的;加密工具五型加密锁(序列号617622)、随锁KEY值(key1=51004,key2=11410,key3=46486,key4=12938)、动态库CDLL5.dll、CDLL5.lib、接口程序、读写函数、密码修改工具、限时限次工具等;加密准备先开发一个程序write来向加密锁中相应的地址写入数据。
现在向加密锁中的1号地址(该锁有32个地址,可任选)写入数据”12345”。
步骤如下:1、将CDLL5.dll复制到write的同一目录下; (参见步骤三)2、在程序代码code中定义动态库函数;(参见步骤四)3、写入数据程序代码,并运行:password : ='abcdefgh';LockAddr: =1;Lockdata: =12345;WriteLock(LockAddr,Lockdata,password);4、成功写入数据后关闭该程序。
加密过程步骤一:首先在Delphi6.0环境下打开DelphiSample程序,运行几次,确保程序正常运行。
确定加密位置,现在根据需要确定在界面运行前进行加密。
步骤二:将光盘中的所有文件拷贝到计算机硬盘上,打开tools,使用工具ModPassw修改密码。
新密码值根据个人需要设置,这里我把它设置为“009lirog”。
步骤三:通过路径:\内嵌加密\实例\ Delphi\代码找到CDLL5.dll并将CDLL5.dll复制到DelphiSample的同一目录下。
Delphi编程入门讲解
常用工具按钮介绍
9
定制代码编辑器 Tools—Editor Properties
10
保存定制开发环境 View—Desktop—Save Desktop
11
项目目录设置 Project—Options
12
组件库路径设置 Tools—Environment Options
13
从当前工程已有基类继承
14
断点设置与调试
15
常用快捷键
F3:继续查找 F4:运行程序至光标处 F5:设置断点 F7:跟踪调试 F8:单步调试 F9:运行程序 F11:在Form/Unit和Object Inspector(对象查看器)之间切换 F12:在Form和Unit之间切换 Ctrl+F9:编译 Ctrl+Alt+F11:弹出Project Options(工程管理器) Ctrl+Shift+上/下方向键:在过程的声明和实现间切换 Ctrl+J:插入标准语法代码 Ctrl+Shift+U,Ctrl+Shift+I:将所选择的代码整体右移或者左移 Ctrl+Shift+C:完成已声明类的实现 Shift+Alt+F11:对象树状视图
ch1,ch2:letter; 39
2、子界类型数据的运算规则
①凡可使用基类型的运算规则同样适用该类 型的子界类型。 ②基类型相同的不同子界类型数据可以进行 混合运算。
var liInt1: 1..10;
liInt2: 10..20; liInt3: Integer; begin liInt1 := 5; liInt2 := 11; liInt3 := liInt1+liint2; ShowMessage(IntToStr(liInt3)); end;
Delphi日期时间函数详解
Delphi日期时间函数详解Delphi 日期时间函数详解2010-08-29 21:23:42| 分类:默认分类 |字号订阅各种时间类型之间的转换函数DateTimeToFileDate函数:定义:DateTimeT oFileDate(DateTime: TDateTime): Integer;作用:将一个TDateTime类型的时间转化为Dos环境中的时间,Dos环境下对时间的访问方法和VCL中的TdateTime类型不一样,在进行文件操作时,为了保持时间的一致性,需要使用DateTimeToFileDate函数进行转化,返回的Integer的值就是Dos下的用于描述时间的值。
DateTimeToSystemTime 过程:定义:procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);作用:将一个TDateTime类型的时间转换为Win API函数所使用的TSystemTime类型,在使用WinApi函数操纵时间时用到。
SystemTimeT oDateTime 函数:定义:function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;作用:将一个在WinApi函数中得到的TSysTemTime类型的数转换为TDateTime类型。
DateTimeToTimeStamp 函数:TimeStampToDateTime 函数:定义:DateTimeToTimeStamp(DateTime: TDateTime):TTimeStamp;function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;作用:用于在TDataTime类型与TTimeStamp之间进行互相转换。
delphi6注册机制_概述及解释说明
delphi6注册机制概述及解释说明1. 引言1.1 概述本文将深入探讨Delphi 6的注册机制,该注册机制是一种用于软件激活和授权的重要工具。
通过对注册机制的研究与分析,我们可以了解其作用、实现方式以及相关的问题与挑战。
从而提高软件安全性和防止破解行为。
1.2 文章结构本文主要分为五个部分:引言、Delphi 6注册机制、解释说明、问题与挑战以及结论。
首先,我们将简要介绍本文的目的和文章结构,然后详细阐述Delphi 6注册机制的相关内容,并解释存储位置和关键信息在注册表中的说明。
接下来,我们将讨论可能存在的问题和挑战,包括法律违规性、破解原因分析以及提高软件安全性的方法。
最后,通过总结重要观点和发现,展望Delphi 6注册机制的未来发展并提出建议。
1.3 目的本文旨在全面了解Delphi 6的注册机制,并剖析其优劣势以及应对可能问题与挑战的方法。
通过深入研究这一主题,我们可以认识到软件激活和授权在保障软件版权和用户权益方面的重要性,并探索如何加强软件安全,防止破解行为的发生。
同时,本文也希望为开发者和相关利益方提供对Delphi 6注册机制的深入理解和有针对性的建议。
通过读者对此篇文章内容的了解,他们将获得更多关于Delphi 6注册机制、其潜在问题以及解决方案等方面的知识,并能够应用于实际开发中,提高软件的安全性和可靠性。
2. delphi6注册机制:2.1 注册机制简介:Delphi6是一款广泛使用的集成开发环境(IDE),它允许开发人员创建使用Delphi编程语言的应用程序。
为了确保软件的合法使用,Delphi6引入了注册机制。
注册机制是一种软件保护措施,通过验证用户的合法性来限制非授权用户对软件的使用。
2.2 注册机制的作用:注册机制主要用于确保Delphi6只被授权用户使用,并限制未经授权的用户从安装到运行时期内的功能和特性。
它可以防止盗版软件在没有得到授权的情况下被非法复制和分发。
AES加密算法(Delphi源码)
AES加密算法(Delphi源码) AES加密算法源码unit ElAES;interfaceusesClasses, SysUtils;typeEAESError = class(Exception);PInteger = ^Integer;TAESBuffer = array [0..15] of byte;TAESKey128 = array [0..15] of byte;TAESKey192 = array [0..23] of byte;TAESKey256 = array [0..31] of byte; TAESExpandedKey128 = array [0..43] of longword; TAESExpandedKey192 = array [0..53] of longword; TAESExpandedKey256 = array [0..63] of longword; PAESBuffer =^TAESBuffer;PAESKey128 =^TAESKey128;PAESKey192 =^TAESKey192;PAESKey256 =^TAESKey256;PAESExpandedKey128 =^TAESExpandedKey128; PAESExpandedKey192 =^TAESExpandedKey192; PAESExpandedKey256 =^TAESExpandedKey256;// Key expansion routines for encryptionprocedure ExpandAESKeyForEncryption(const Key: TAESKey128;var ExpandedKey: TAESExpandedKey128); overload; procedure ExpandAESKeyForEncryption(const Key: TAESKey192;var ExpandedKey: TAESExpandedKey192); overload; procedure ExpandAESKeyForEncryption(const Key: TAESKey256;var ExpandedKey: TAESExpandedKey256); overload;// Block encryption routinesprocedure EncryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey128;var OutBuf: TAESBuffer); overload;procedure EncryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey192;var OutBuf: TAESBuffer); overload;procedure EncryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey256;var OutBuf: TAESBuffer); overload;// Stream encryption routines (ECB mode)procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;const Key: TAESKey128; Dest: TStream); overload;procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;const ExpandedKey: TAESExpandedKey128; Dest: TStream); overload;procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;const Key: TAESKey192; Dest: TStream); overload;procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;const ExpandedKey: TAESExpandedKey192; Dest: TStream); overload;procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;const Key: TAESKey256; Dest: TStream); overload;procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;const ExpandedKey: TAESExpandedKey256; Dest: TStream); overload;// Stream encryption routines (CBC mode)procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;const Key: TAESKey128; const InitVector: TAESBuffer; Dest: TStream); overload; procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;const ExpandedKey: TAESExpandedKey128; const InitVector: TAESBuffer;Dest: TStream); overload;procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;const Key: TAESKey192; const InitVector: TAESBuffer; Dest: TStream); overload; procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;const ExpandedKey: TAESExpandedKey192; const InitVector: TAESBuffer;Dest: TStream); overload;procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;const Key: TAESKey256; const InitVector: TAESBuffer; Dest: TStream); overload; procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;const ExpandedKey: TAESExpandedKey256; const InitVector: TAESBuffer;Dest: TStream); overload;// Key transformation routines for decryptionprocedure ExpandAESKeyForDecryption(var ExpandedKey: TAESExpandedKey128); overload; procedure ExpandAESKeyForDecryption(const Key: TAESKey128;var ExpandedKey: TAESExpandedKey128); overload;procedure ExpandAESKeyForDecryption(var ExpandedKey: TAESExpandedKey192); overload; procedure ExpandAESKeyForDecryption(const Key: TAESKey192;var ExpandedKey: TAESExpandedKey192); overload;procedure ExpandAESKeyForDecryption(var ExpandedKey: TAESExpandedKey256); overload; procedure ExpandAESKeyForDecryption(const Key: TAESKey256;var ExpandedKey: TAESExpandedKey256); overload;// Block decryption routinesprocedure DecryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey128;var OutBuf: TAESBuffer); overload;procedure DecryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey192;var OutBuf: TAESBuffer); overload;procedure DecryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey256;var OutBuf: TAESBuffer); overload;// Stream decryption routines (ECB mode)procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;const Key: TAESKey128; Dest: TStream); overload;procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;const ExpandedKey: TAESExpandedKey128; Dest: TStream); overload;procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;const Key: TAESKey192; Dest: TStream); overload;procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;const ExpandedKey: TAESExpandedKey192; Dest: TStream); overload;procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;const Key: TAESKey256; Dest: TStream); overload;procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;const ExpandedKey: TAESExpandedKey256; Dest: TStream); overload;// Stream decryption routines (CBC mode)procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;const Key: TAESKey128; const InitVector: TAESBuffer; Dest: TStream); overload; procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;const ExpandedKey: TAESExpandedKey128; const InitVector: TAESBuffer;Dest: TStream); overload;procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;const Key: TAESKey192; const InitVector: TAESBuffer; Dest: TStream); overload; procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;const ExpandedKey: TAESExpandedKey192; const InitVector: TAESBuffer;Dest: TStream); overload;procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;const Key: TAESKey256; const InitVector: TAESBuffer; Dest: TStream); overload; procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;const ExpandedKey: TAESExpandedKey256; const InitVector: TAESBuffer;Dest: TStream); overload;resourcestringSInvalidInBufSize = 'Invalid buffer size for decryption';SReadError = 'Stream read error';SWriteError = 'Stream write error';implementationtypePLongWord = ^LongWord;function Min(A, B: integer): integer;beginif A < B thenResult := AelseResult := B;end;constRcon: array [1..30] of longword = ($00000001, $00000002, $00000004, $00000008, $00000010, $00000020,$00000040, $00000080, $0000001B, $00000036, $0000006C, $000000D8,$000000AB, $0000004D, $0000009A, $0000002F, $0000005E, $000000BC,$00000063, $000000C6, $00000097, $00000035, $0000006A, $000000D4,$000000B3, $0000007D, $000000FA, $000000EF, $000000C5, $00000091 );ForwardTable: array [0..255] of longword = ($A56363C6, $847C7CF8, $997777EE, $8D7B7BF6, $0DF2F2FF, $BD6B6BD6, $B16F6FDE, $54C5C591,$50303060, $03010102, $A96767CE, $7D2B2B56, $19FEFEE7, $62D7D7B5, $E6ABAB4D, $9A7676EC,$45CACA8F, $9D82821F, $40C9C989, $877D7DFA, $15FAFAEF, $EB5959B2, $C947478E, $0BF0F0FB,$ECADAD41, $67D4D4B3, $FDA2A25F, $EAAFAF45, $BF9C9C23, $F7A4A453, $967272E4, $5BC0C09B,$C2B7B775, $1CFDFDE1, $AE93933D, $6A26264C, $5A36366C, $413F3F7E, $02F7F7F5, $4FCCCC83,$5C343468, $F4A5A551, $34E5E5D1, $08F1F1F9, $937171E2, $73D8D8AB, $53313162, $3F15152A,$0C040408, $52C7C795, $65232346, $5EC3C39D, $28181830, $A1969637, $0F05050A, $B59A9A2F,$0907070E, $36121224, $9B80801B, $3DE2E2DF, $26EBEBCD, $6927274E, $CDB2B27F, $9F7575EA,$1B090912, $9E83831D, $742C2C58, $2E1A1A34, $2D1B1B36, $B26E6EDC, $EE5A5AB4, $FBA0A05B,$F65252A4, $4D3B3B76, $61D6D6B7, $CEB3B37D, $7B292952, $3EE3E3DD, $712F2F5E, $97848413,$F55353A6, $68D1D1B9, $00000000, $2CEDEDC1, $60202040, $1FFCFCE3, $C8B1B179, $ED5B5BB6,$BE6A6AD4, $46CBCB8D, $D9BEBE67, $4B393972, $DE4A4A94, $D44C4C98, $E85858B0, $4ACFCF85,$6BD0D0BB, $2AEFEFC5, $E5AAAA4F, $16FBFBED, $C5434386, $D74D4D9A, $55333366, $94858511,$CF45458A, $10F9F9E9, $06020204, $817F7FFE, $F05050A0, $443C3C78, $BA9F9F25, $E3A8A84B,$F35151A2, $FEA3A35D, $C0404080, $8A8F8F05, $AD92923F, $BC9D9D21, $48383870, $04F5F5F1,$DFBCBC63, $C1B6B677, $75DADAAF, $63212142, $30101020, $1AFFFFE5, $0EF3F3FD, $6DD2D2BF,$4CCDCD81, $140C0C18, $35131326, $2FECECC3, $E15F5FBE, $A2979735, $CC444488, $3917172E,$57C4C493, $F2A7A755, $827E7EFC, $473D3D7A, $AC6464C8, $E75D5DBA, $2B191932, $957373E6,$A06060C0, $98818119, $D14F4F9E, $7FDCDCA3, $66222244, $7E2A2A54, $AB90903B, $8388880B,$CA46468C, $29EEEEC7, $D3B8B86B, $3C141428, $79DEDEA7, $E25E5EBC, $1D0B0B16, $76DBDBAD,$3BE0E0DB, $56323264, $4E3A3A74, $1E0A0A14, $DB494992, $0A06060C, $6C242448, $E45C5CB8,$5DC2C29F, $6ED3D3BD, $EFACAC43, $A66262C4, $A8919139, $A4959531, $37E4E4D3, $8B7979F2,$32E7E7D5, $43C8C88B, $5937376E, $B76D6DDA, $8C8D8D01, $64D5D5B1, $D24E4E9C, $E0A9A949,$B46C6CD8, $FA5656AC, $07F4F4F3, $25EAEACF, $AF6565CA, $8E7A7AF4, $E9AEAE47, $18080810,$D5BABA6F, $887878F0, $6F25254A, $722E2E5C, $241C1C38, $F1A6A657, $C7B4B473, $51C6C697,$23E8E8CB, $7CDDDDA1, $9C7474E8, $211F1F3E, $DD4B4B96, $DCBDBD61, $868B8B0D, $858A8A0F,$907070E0, $423E3E7C, $C4B5B571, $AA6666CC, $D8484890, $05030306, $01F6F6F7, $120E0E1C,$A36161C2, $5F35356A, $F95757AE, $D0B9B969, $91868617, $58C1C199, $271D1D3A, $B99E9E27,$38E1E1D9, $13F8F8EB, $B398982B, $33111122, $BB6969D2, $70D9D9A9, $898E8E07, $A7949433,$B69B9B2D, $221E1E3C, $92878715, $20E9E9C9, $49CECE87, $FF5555AA, $78282850, $7ADFDFA5,$8F8C8C03, $F8A1A159, $80898909, $170D0D1A, $DABFBF65, $31E6E6D7, $C6424284, $B86868D0,$C3414182, $B0999929, $772D2D5A, $110F0F1E, $CBB0B07B, $FC5454A8, $D6BBBB6D, $3A16162C);LastForwardTable: array [0..255] of longword = ($00000063, $0000007C, $00000077, $0000007B, $000000F2, $0000006B, $0000006F, $000000C5,$00000030, $00000001, $00000067, $0000002B, $000000FE, $000000D7, $000000AB, $00000076,$000000CA, $00000082, $000000C9, $0000007D, $000000FA, $00000059, $00000047, $000000F0,$000000AD, $000000D4, $000000A2, $000000AF, $0000009C, $000000A4, $00000072, $000000C0,$000000B7, $000000FD, $00000093, $00000026, $00000036, $0000003F, $000000F7, $000000CC,$00000034, $000000A5, $000000E5, $000000F1, $00000071, $000000D8, $00000031, $00000015,$00000004, $000000C7, $00000023, $000000C3, $00000018, $00000096, $00000005, $0000009A,$00000007, $00000012, $00000080, $000000E2, $000000EB, $00000027, $000000B2, $00000075,$00000009, $00000083, $0000002C, $0000001A, $0000001B, $0000006E, $0000005A, $000000A0,$00000052, $0000003B, $000000D6, $000000B3, $00000029, $000000E3, $0000002F, $00000084,$00000053, $000000D1, $00000000, $000000ED, $00000020, $000000FC, $000000B1, $0000005B,$0000006A, $000000CB, $000000BE, $00000039, $0000004A, $0000004C, $00000058, $000000CF,$000000D0, $000000EF, $000000AA, $000000FB, $00000043, $0000004D, $00000033,$00000085,$00000045, $000000F9, $00000002, $0000007F, $00000050, $0000003C, $0000009F, $000000A8,$00000051, $000000A3, $00000040, $0000008F, $00000092, $0000009D, $00000038, $000000F5,$000000BC, $000000B6, $000000DA, $00000021, $00000010, $000000FF, $000000F3, $000000D2,$000000CD, $0000000C, $00000013, $000000EC, $0000005F, $00000097, $00000044, $00000017,$000000C4, $000000A7, $0000007E, $0000003D, $00000064, $0000005D, $00000019, $00000073,$00000060, $00000081, $0000004F, $000000DC, $00000022, $0000002A, $00000090, $00000088,$00000046, $000000EE, $000000B8, $00000014, $000000DE, $0000005E, $0000000B, $000000DB,$000000E0, $00000032, $0000003A, $0000000A, $00000049, $00000006, $00000024, $0000005C,$000000C2, $000000D3, $000000AC, $00000062, $00000091, $00000095, $000000E4, $00000079,$000000E7, $000000C8, $00000037, $0000006D, $0000008D, $000000D5, $0000004E, $000000A9,$0000006C, $00000056, $000000F4, $000000EA, $00000065, $0000007A, $000000AE, $00000008,$000000BA, $00000078, $00000025, $0000002E, $0000001C, $000000A6, $000000B4, $000000C6,$000000E8, $000000DD, $00000074, $0000001F, $0000004B, $000000BD, $0000008B, $0000008A,$00000070, $0000003E, $000000B5, $00000066, $00000048, $00000003, $000000F6, $0000000E,$00000061, $00000035, $00000057, $000000B9, $00000086, $000000C1, $0000001D, $0000009E,$000000E1, $000000F8, $00000098, $00000011, $00000069, $000000D9, $0000008E, $00000094,$0000009B, $0000001E, $00000087, $000000E9, $000000CE, $00000055, $00000028, $000000DF,$0000008C, $000000A1, $00000089, $0000000D, $000000BF, $000000E6, $00000042, $00000068,$00000041, $00000099, $0000002D, $0000000F, $000000B0, $00000054, $000000BB, $00000016);InverseTable: array [0..255] of longword = ($50A7F451, $5365417E, $C3A4171A, $965E273A, $CB6BAB3B, $F1459D1F, $AB58FAAC, $9303E34B,$55FA3020, $F66D76AD, $9176CC88, $254C02F5, $FCD7E54F, $D7CB2AC5, $80443526, $8FA362B5,$495AB1DE, $671BBA25, $980EEA45, $E1C0FE5D, $02752FC3, $12F04C81, $A397468D, $C6F9D36B,$E75F8F03, $959C9215, $EB7A6DBF, $DA595295, $2D83BED4, $D3217458, $2969E049, $44C8C98E,$6A89C275, $78798EF4, $6B3E5899, $DD71B927, $B64FE1BE, $17AD88F0, $66AC20C9, $B43ACE7D,$184ADF63, $82311AE5, $60335197, $457F5362, $E07764B1, $84AE6BBB, $1CA081FE, $942B08F9,$58684870, $19FD458F, $876CDE94, $B7F87B52, $23D373AB, $E2024B72, $578F1FE3, $2AAB5566,$0728EBB2, $03C2B52F, $9A7BC586, $A50837D3, $F2872830, $B2A5BF23, $BA6A0302, $5C8216ED,$2B1CCF8A, $92B479A7, $F0F207F3, $A1E2694E, $CDF4DA65, $D5BE0506, $1F6234D1, $8AFEA6C4,$9D532E34, $A055F3A2, $32E18A05, $75EBF6A4, $39EC830B, $AAEF6040, $069F715E, $51106EBD,$F98A213E, $3D06DD96, $AE053EDD, $46BDE64D, $B58D5491, $055DC471, $6FD40604, $FF155060,$24FB9819, $97E9BDD6, $CC434089, $779ED967, $BD42E8B0, $888B8907, $385B19E7, $DBEEC879,$470A7CA1, $E90F427C, $C91E84F8, $00000000, $83868009, $48ED2B32, $AC70111E, $4E725A6C,$FBFF0EFD, $5638850F, $1ED5AE3D, $27392D36, $64D90F0A, $21A65C68, $D1545B9B, $3A2E3624,$B1670A0C, $0FE75793, $D296EEB4, $9E919B1B, $4FC5C080, $A220DC61, $694B775A, $161A121C,$0ABA93E2, $E52AA0C0, $43E0223C, $1D171B12, $0B0D090E, $ADC78BF2, $B9A8B62D, $C8A91E14,$8519F157, $4C0775AF, $BBDD99EE, $FD607FA3, $9F2601F7, $BCF5725C, $C53B6644, $347EFB5B,$7629438B, $DCC623CB, $68FCEDB6, $63F1E4B8, $CADC31D7, $10856342, $40229713, $2011C684,$7D244A85, $F83DBBD2, $1132F9AE, $6DA129C7, $4B2F9E1D, $F330B2DC, $EC52860D, $D0E3C177,$6C16B32B, $99B970A9, $FA489411, $2264E947, $C48CFCA8, $1A3FF0A0, $D82C7D56, $EF903322,$C74E4987, $C1D138D9, $FEA2CA8C, $360BD498, $CF81F5A6, $28DE7AA5, $268EB7DA, $A4BFAD3F,$E49D3A2C, $0D927850, $9BCC5F6A, $62467E54, $C2138DF6, $E8B8D890, $5EF7392E, $F5AFC382,$BE805D9F, $7C93D069, $A92DD56F, $B31225CF, $3B99ACC8, $A77D1810, $6E639CE8, $7BBB3BDB,$097826CD, $F418596E, $01B79AEC, $A89A4F83, $656E95E6, $7EE6FFAA, $08CFBC21, $E6E815EF,$D99BE7BA, $CE366F4A, $D4099FEA, $D67CB029, $AFB2A431, $31233F2A, $3094A5C6, $C066A235,$37BC4E74, $A6CA82FC, $B0D090E0, $15D8A733, $4A9804F1, $F7DAEC41, $0E50CD7F, $2FF69117,$8DD64D76, $4DB0EF43, $544DAACC, $DF0496E4, $E3B5D19E, $1B886A4C, $B81F2CC1, $7F516546,$04EA5E9D, $5D358C01, $737487FA, $2E410BFB, $5A1D67B3, $52D2DB92, $335610E9, $1347D66D,$8C61D79A, $7A0CA137, $8E14F859, $893C13EB, $EE27A9CE, $35C961B7, $EDE51CE1, $3CB1477A,$59DFD29C, $3F73F255, $79CE1418, $BF37C773, $EACDF753, $5BAAFD5F, $146F3DDF, $86DB4478,$81F3AFCA, $3EC468B9, $2C342438, $5F40A3C2, $72C31D16, $0C25E2BC, $8B493C28, $41950DFF,$7101A839, $DEB30C08, $9CE4B4D8, $90C15664, $6184CB7B, $70B632D5, $745C6C48, $4257B8D0);LastInverseTable: array [0..255] of longword = ($00000052, $00000009, $0000006A, $000000D5, $00000030, $00000036, $000000A5, $00000038,$000000BF, $00000040, $000000A3, $0000009E, $00000081, $000000F3, $000000D7, $000000FB,$0000007C, $000000E3, $00000039, $00000082, $0000009B, $0000002F, $000000FF, $00000087,$00000034, $0000008E, $00000043, $00000044, $000000C4, $000000DE, $000000E9, $000000CB,$00000054, $0000007B, $00000094, $00000032, $000000A6, $000000C2, $00000023, $0000003D,$000000EE, $0000004C, $00000095, $0000000B, $00000042, $000000FA, $000000C3, $0000004E,$00000008, $0000002E, $000000A1, $00000066, $00000028, $000000D9, $00000024, $000000B2,$00000076, $0000005B, $000000A2, $00000049, $0000006D, $0000008B, $000000D1, $00000025,$00000072, $000000F8, $000000F6, $00000064, $00000086, $00000068, $00000098, $00000016,$000000D4, $000000A4, $0000005C, $000000CC, $0000005D, $00000065, $000000B6, $00000092,$0000006C, $00000070, $00000048, $00000050, $000000FD, $000000ED, $000000B9, $000000DA,$0000005E, $00000015, $00000046, $00000057, $000000A7, $0000008D, $0000009D,$00000084,$00000090, $000000D8, $000000AB, $00000000, $0000008C, $000000BC, $000000D3, $0000000A,$000000F7, $000000E4, $00000058, $00000005, $000000B8, $000000B3, $00000045, $00000006,$000000D0, $0000002C, $0000001E, $0000008F, $000000CA, $0000003F, $0000000F, $00000002,$000000C1, $000000AF, $000000BD, $00000003, $00000001, $00000013, $0000008A, $0000006B,$0000003A, $00000091, $00000011, $00000041, $0000004F, $00000067, $000000DC, $000000EA,$00000097, $000000F2, $000000CF, $000000CE, $000000F0, $000000B4, $000000E6, $00000073,$00000096, $000000AC, $00000074, $00000022, $000000E7, $000000AD, $00000035, $00000085,$000000E2, $000000F9, $00000037, $000000E8, $0000001C, $00000075, $000000DF, $0000006E,$00000047, $000000F1, $0000001A, $00000071, $0000001D, $00000029, $000000C5, $00000089,$0000006F, $000000B7, $00000062, $0000000E, $000000AA, $00000018, $000000BE, $0000001B,$000000FC, $00000056, $0000003E, $0000004B, $000000C6, $000000D2, $00000079, $00000020,$0000009A, $000000DB, $000000C0, $000000FE, $00000078, $000000CD, $0000005A, $000000F4,$0000001F, $000000DD, $000000A8, $00000033, $00000088, $00000007, $000000C7, $00000031,$000000B1, $00000012, $00000010, $00000059, $00000027, $00000080, $000000EC, $0000005F,$00000060, $00000051, $0000007F, $000000A9, $00000019, $000000B5, $0000004A, $0000000D,$0000002D, $000000E5, $0000007A, $0000009F, $00000093, $000000C9, $0000009C, $000000EF,$000000A0, $000000E0, $0000003B, $0000004D, $000000AE, $0000002A, $000000F5, $000000B0,$000000C8, $000000EB, $000000BB, $0000003C, $00000083, $00000053, $00000099, $00000061,$00000017, $0000002B, $00000004, $0000007E, $000000BA, $00000077, $000000D6, $00000026,$000000E1, $00000069, $00000014, $00000063, $00000055, $00000021, $0000000C, $0000007D);procedure ExpandAESKeyForEncryption(const Key: TAESKey128; var ExpandedKey:TAESExpandedKey128);varI, J: integer;T: longword;W0, W1, W2, W3: longword;beginExpandedKey[0] := PLongWord(@Key[0])^;ExpandedKey[1] := PLongWord(@Key[4])^;ExpandedKey[2] := PLongWord(@Key[8])^;ExpandedKey[3] := PLongWord(@Key[12])^;I := 0; J := 1;repeatT := (ExpandedKey[I + 3] shl 24) or (ExpandedKey[I + 3] shr 8);W0 := LastForwardTable[Byte(T)]; W1 := LastForwardTable[Byte(T shr 8)];W2 := LastForwardTable[Byte(T shr 16)]; W3 :=LastForwardTable[Byte(T shr 24)];ExpandedKey[I + 4] := ExpandedKey[I] xor(W0 xor ((W1 shl 8) or (W1 shr 24)) xor((W2 shl 16) or (W2 shr 16)) xor ((W3 shl 24) or (W3 shr 8))) xor Rcon[J];Inc(J);ExpandedKey[I + 5] := ExpandedKey[I + 1] xor ExpandedKey[I + 4];ExpandedKey[I + 6] := ExpandedKey[I + 2] xor ExpandedKey[I + 5];ExpandedKey[I + 7] := ExpandedKey[I + 3] xor ExpandedKey[I + 6];Inc(I, 4);until I >= 40;end;procedure ExpandAESKeyForEncryption(const Key: TAESKey192; var ExpandedKey: TAESExpandedKey192); overload;varI, J: integer;T: longword;W0, W1, W2, W3: longword;beginExpandedKey[0] := PLongWord(@Key[0])^;ExpandedKey[1] := PLongWord(@Key[4])^;ExpandedKey[2] := PLongWord(@Key[8])^;ExpandedKey[3] := PLongWord(@Key[12])^;ExpandedKey[4] := PLongWord(@Key[16])^;ExpandedKey[5] := PLongWord(@Key[20])^;I := 0; J := 1;repeatT := (ExpandedKey[I + 5] shl 24) or (ExpandedKey[I + 5] shr 8);W0 := LastForwardTable[Byte(T)]; W1 := LastForwardTable[Byte(T shr 8)];W2 := LastForwardTable[Byte(T shr 16)]; W3 :=LastForwardTable[Byte(T shr 24)];ExpandedKey[I + 6] := ExpandedKey[I] xor(W0 xor ((W1 shl 8) or (W1 shr 24)) xor((W2 shl 16) or (W2 shr 16)) xor ((W3 shl 24) or (W3 shr 8))) xor Rcon[J];Inc(J);ExpandedKey[I + 7] := ExpandedKey[I + 1] xor ExpandedKey[I + 6];ExpandedKey[I + 8] := ExpandedKey[I + 2] xor ExpandedKey[I + 7];ExpandedKey[I + 9] := ExpandedKey[I + 3] xor ExpandedKey[I + 8];ExpandedKey[I + 10] := ExpandedKey[I + 4] xor ExpandedKey[I + 9];ExpandedKey[I + 11] := ExpandedKey[I + 5] xor ExpandedKey[I + 10];Inc(I, 6);until I >= 46;end;procedure ExpandAESKeyForEncryption(const Key: TAESKey256; var ExpandedKey: TAESExpandedKey256); overload;varI, J: integer;T: longword;W0, W1, W2, W3: longword;beginExpandedKey[0] := PLongWord(@Key[0])^;ExpandedKey[1] := PLongWord(@Key[4])^;ExpandedKey[2] := PLongWord(@Key[8])^;ExpandedKey[3] := PLongWord(@Key[12])^;ExpandedKey[4] := PLongWord(@Key[16])^;ExpandedKey[5] := PLongWord(@Key[20])^;ExpandedKey[6] := PLongWord(@Key[24])^;ExpandedKey[7] := PLongWord(@Key[28])^;I := 0; J := 1;repeatT := (ExpandedKey[I + 7] shl 24) or (ExpandedKey[I + 7] shr 8);W0 := LastForwardTable[Byte(T)]; W1 := LastForwardTable[Byte(T shr 8)];W2 := LastForwardTable[Byte(T shr 16)]; W3 :=LastForwardTable[Byte(T shr 24)];ExpandedKey[I + 8] := ExpandedKey[I] xor(W0 xor ((W1 shl 8) or (W1 shr 24)) xor((W2 shl 16) or (W2 shr 16)) xor ((W3 shl 24) or (W3 shr 8))) xor Rcon[J];Inc(J);ExpandedKey[I + 9] := ExpandedKey[I + 1] xor ExpandedKey[I + 8];ExpandedKey[I + 10] := ExpandedKey[I + 2] xor ExpandedKey[I + 9];ExpandedKey[I + 11] := ExpandedKey[I + 3] xor ExpandedKey[I + 10];W0 := LastForwardTable[Byte(ExpandedKey[I + 11])];W1 := LastForwardTable[Byte(ExpandedKey[I + 11] shr 8)];W2 := LastForwardTable[Byte(ExpandedKey[I + 11] shr 16)];W3 := LastForwardTable[Byte(ExpandedKey[I + 11] shr 24)];ExpandedKey[I + 12] := ExpandedKey[I + 4] xor(W0 xor ((W1 shl 8) or (W1 shr 24)) xor((W2 shl 16) or (W2 shr 16)) xor ((W3 shl 24) or (W3 shr 8)));ExpandedKey[I + 13] := ExpandedKey[I + 5] xor ExpandedKey[I + 12];ExpandedKey[I + 14] := ExpandedKey[I + 6] xor ExpandedKey[I + 13];ExpandedKey[I + 15] := ExpandedKey[I + 7] xor ExpandedKey[I + 14];Inc(I, 8);until I >= 52;end;procedure EncryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey128;var OutBuf: TAESBuffer);varT0, T1: array [0..3] of longword;W0, W1, W2, W3: longword;begin// initializingT0[0] := PLongWord(@InBuf[0])^ xor Key[0];T0[1] := PLongWord(@InBuf[4])^ xor Key[1];T0[2] := PLongWord(@InBuf[8])^ xor Key[2];T0[3] := PLongWord(@InBuf[12])^ xor Key[3];// performing transformation 9 times// round 1W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[4];W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[5];W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[6];W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[7];// round 2W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[8];W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[9];W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[10];W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[11];// round 3W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[12];W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[13];W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[14];W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[15];// round 4W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[16];W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[17];W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[18];W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[19];// round 5W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[20];W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))xor ((W3 shl 24) or (W3 shr 8))) xor Key[21];W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];。
DELPHIMD5加密算法
DELPHIMD5加密算法{具体使用方法如下,另外还附有源代码://*1、MD5String、MD5File、MD5Print、MD5Match这四个函数是供调用的。
其他是用来辅助这几个函数的子函数。
2、MD5String为加密字符串。
3、MD5File为加密这个文件。
4、MD5Print是将加密后的密文转换成字符串。
5、MD5Match是用来比较密文是否一致。
加密字符串aaa MD5String('aaa')将加密后的aaa显示出来 MD5Print(MD5String('aaa'))比较两次密文是否一致:MD5Match(MD5String('第一次明文'),MD5String('第二次输入的明文'))*//MD5加密算法(DELPHI)}unit md5;// -----------------------------------------------------------------------------------------------INTERFACE// -----------------------------------------------------------------------------------------------usesWindows;typeMD5Count = array[0..1] of DWORD;MD5State = array[0..3] of DWORD;MD5Block = array[0..15] of DWORD;MD5CBits = array[0..7] of byte;MD5Digest = array[0..15] of byte;MD5Buffer = array[0..63] of byte;MD5Context = recordState: MD5State;Count: MD5Count;Buffer: MD5Buffer;end;procedure MD5Init(var Context: MD5Context);procedure MD5Update(var Context: MD5Context; Input: pChar; Length: longword);procedure MD5Final(var Context: MD5Context; var Digest: MD5Digest);function MD5String(M: string): MD5Digest;function MD5File(N: string): MD5Digest;function MD5Print(D: MD5Digest): string;function MD5Match(D1, D2: MD5Digest): boolean;// -----------------------------------------------------------------------------------------------IMPLEMENTATION// -----------------------------------------------------------------------------------------------varPADDING: MD5Buffer = ($80, $00, $00, $00, $00, $00, $00, $00,$00, $00, $00, $00, $00, $00, $00, $00,$00, $00, $00, $00, $00, $00, $00, $00,$00, $00, $00, $00, $00, $00, $00, $00,$00, $00, $00, $00, $00, $00, $00, $00,$00, $00, $00, $00, $00, $00, $00, $00,$00, $00, $00, $00, $00, $00, $00, $00,$00, $00, $00, $00, $00, $00, $00, $00);function F(x, y, z: DWORD): DWORD;beginResult := (x and y) or ((not x) and z);end;function G(x, y, z: DWORD): DWORD;beginResult := (x and z) or (y and (not z));end;function H(x, y, z: DWORD): DWORD;beginResult := x xor y xor z;end;function I(x, y, z: DWORD): DWORD;beginResult := y xor (x or (not z));end;procedure rot(var x: DWORD; n: BYTE);beginx := (x shl n) or (x shr (32 - n));end;procedure FF(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);begininc(a, F(b, c, d) + x + ac);rot(a, s);inc(a, b);end;procedure GG(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac:DWORD);begininc(a, G(b, c, d) + x + ac);rot(a, s);inc(a, b);end;procedure HH(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);begininc(a, H(b, c, d) + x + ac);rot(a, s);inc(a, b);end;procedure II(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);begininc(a, I(b, c, d) + x + ac);rot(a, s);inc(a, b);end;// -----------------------------------------------------------------------------------------------// Encode Count bytes at Source into (Count / 4) DWORDs at Targetprocedure Encode(Source, Target: pointer; Count: longword);varS: PByte;T: PDWORD;I: longword;S := Source;T := Target;for I := 1 to Count div 4 do beginT^ := S^;inc(S);T^ := T^ or (S^ shl 8);inc(S);T^ := T^ or (S^ shl 16);inc(S);T^ := T^ or (S^ shl 24);inc(S);inc(T);end;end;// Decode Count DWORDs at Source into (Count * 4) Bytes at Targetprocedure Decode(Source, Target: pointer; Count: longword);varS: PDWORD;T: PByte;I: longword;beginS := Source;T := Target;for I := 1 to Count do beginT^ := S^ and $ff;inc(T);T^ := (S^ shr 8) and $ff;T^ := (S^ shr 16) and $ff;inc(T);T^ := (S^ shr 24) and $ff;inc(T);inc(S);end;end;// Transform State according to first 64 bytes at Buffer procedure Transform(Buffer: pointer; var State: MD5State); vara, b, c, d: DWORD;Block: MD5Block;beginEncode(Buffer, @Block, 64);a := State[0];b := State[1];c := State[2];d := State[3];FF (a, b, c, d, Block[ 0], 7, $d76aa478);FF (d, a, b, c, Block[ 1], 12, $e8c7b756);FF (c, d, a, b, Block[ 2], 17, $242070db);FF (b, c, d, a, Block[ 3], 22, $c1bdceee);FF (a, b, c, d, Block[ 4], 7, $f57c0faf);FF (d, a, b, c, Block[ 5], 12, $4787c62a);FF (c, d, a, b, Block[ 6], 17, $a8304613);FF (b, c, d, a, Block[ 7], 22, $fd469501);FF (a, b, c, d, Block[ 8], 7, $698098d8);FF (d, a, b, c, Block[ 9], 12, $8b44f7af);FF (c, d, a, b, Block[10], 17, $ffff5bb1);FF (b, c, d, a, Block[11], 22, $895cd7be); FF (a, b, c, d, Block[12], 7, $6b901122); FF (d, a, b, c, Block[13], 12, $fd987193); FF (c, d, a, b, Block[14], 17, $a679438e); FF (b, c, d, a, Block[15], 22, $49b40821); GG (a, b, c, d, Block[ 1], 5, $f61e2562); GG (d, a, b, c, Block[ 6], 9, $c040b340); GG (c, d, a, b, Block[11], 14, $265e5a51); GG (b, c, d, a, Block[ 0], 20, $e9b6c7aa); GG (a, b, c, d, Block[ 5], 5, $d62f105d); GG (d, a, b, c, Block[10], 9, $2441453); GG (c, d, a, b, Block[15], 14, $d8a1e681); GG (b, c, d, a, Block[ 4], 20, $e7d3fbc8); GG (a, b, c, d, Block[ 9], 5, $21e1cde6); GG (d, a, b, c, Block[14], 9, $c33707d6); GG (c, d, a, b, Block[ 3], 14, $f4d50d87); GG (b, c, d, a, Block[ 8], 20, $455a14ed); GG (a, b, c, d, Block[13], 5, $a9e3e905); GG (d, a, b, c, Block[ 2], 9, $fcefa3f8); GG (c, d, a, b, Block[ 7], 14, $676f02d9); GG (b, c, d, a, Block[12], 20, $8d2a4c8a); HH (a, b, c, d, Block[ 5], 4, $fffa3942); HH (d, a, b, c, Block[ 8], 11, $8771f681); HH (c, d, a, b, Block[11], 16, $6d9d6122); HH (b, c, d, a, Block[14], 23, $fde5380c); HH (a, b, c, d, Block[ 1], 4, $a4beea44); HH (d, a, b, c, Block[ 4], 11, $4bdecfa9); HH (c, d, a, b, Block[ 7], 16, $f6bb4b60); HH (b, c, d, a, Block[10], 23, $bebfbc70); HH (a, b, c, d, Block[13], 4, $289b7ec6);HH (d, a, b, c, Block[ 0], 11, $eaa127fa);HH (c, d, a, b, Block[ 3], 16, $d4ef3085);HH (b, c, d, a, Block[ 6], 23, $4881d05);HH (a, b, c, d, Block[ 9], 4, $d9d4d039);HH (d, a, b, c, Block[12], 11, $e6db99e5);HH (c, d, a, b, Block[15], 16, $1fa27cf8);HH (b, c, d, a, Block[ 2], 23, $c4ac5665);II (a, b, c, d, Block[ 0], 6, $f4292244);II (d, a, b, c, Block[ 7], 10, $432aff97);II (c, d, a, b, Block[14], 15, $ab9423a7);II (b, c, d, a, Block[ 5], 21, $fc93a039);II (a, b, c, d, Block[12], 6, $655b59c3);II (d, a, b, c, Block[ 3], 10, $8f0ccc92);II (c, d, a, b, Block[10], 15, $ffeff47d);II (b, c, d, a, Block[ 1], 21, $85845dd1);II (a, b, c, d, Block[ 8], 6, $6fa87e4f);II (d, a, b, c, Block[15], 10, $fe2ce6e0);II (c, d, a, b, Block[ 6], 15, $a3014314);II (b, c, d, a, Block[13], 21, $4e0811a1);II (a, b, c, d, Block[ 4], 6, $f7537e82);II (d, a, b, c, Block[11], 10, $bd3af235);II (c, d, a, b, Block[ 2], 15, $2ad7d2bb);II (b, c, d, a, Block[ 9], 21, $eb86d391);inc(State[0], a);inc(State[1], b);inc(State[2], c);inc(State[3], d);end;// -----------------------------------------------------------------------------------------------// Initialize given Contextprocedure MD5Init(var Context: MD5Context);beginwith Context do beginState[0] := $67452301;State[1] := $efcdab89;State[2] := $98badcfe;State[3] := $10325476;Count[0] := 0;Count[1] := 0;ZeroMemory(@Buffer, SizeOf(MD5Buffer));end;end;// Update given Context to include Length bytes of Inputprocedure MD5Update(var Context: MD5Context; Input: pChar; Length: longword);varIndex: longword;PartLen: longword;I: longword;beginwith Context do beginIndex := (Count[0] shr 3) and $3f;inc(Count[0], Length shl 3);if Count[0] < (Length shl 3) then inc(Count[1]);inc(Count[1], Length shr 29);end;PartLen := 64 - Index;if Length >= PartLen then beginCopyMemory(@Context.Buffer[Index], Input, PartLen);Transform(@Context.Buffer, Context.State);I := PartLen;while I + 63 < Length do beginTransform(@Input[I], Context.State);inc(I, 64);end;Index := 0;end else I := 0;CopyMemory(@Context.Buffer[Index], @Input[I], Length - I);end;// Finalize given Context, create Digest and zeroize Context procedure MD5Final(var Context: MD5Context; var Digest: MD5Digest);varBits: MD5CBits;Index: longword;PadLen: longword;beginDecode(@Context.Count, @Bits, 2);Index := (Context.Count[0] shr 3) and $3f;if Index < 56 then PadLen := 56 - Index else PadLen := 120 - Index;MD5Update(Context, @PADDING, PadLen);MD5Update(Context, @Bits, 8);Decode(@Context.State, @Digest, 4);ZeroMemory(@Context, SizeOf(MD5Context));end;// -----------------------------------------------------------------------------------------------// Create digest of given Messagefunction MD5String(M: string): MD5Digest;varContext: MD5Context;beginMD5Init(Context);MD5Update(Context, pChar(M), length(M));MD5Final(Context, Result);end;// Create digest of file with given Namefunction MD5File(N: string): MD5Digest;varFileHandle: THandle;MapHandle: THandle;ViewPointer: pointer;Context: MD5Context;beginMD5Init(Context);FileHandle := CreateFile(pChar(N), GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE,nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_SEQUENTIAL_SCAN, 0);if FileHandle <> INVALID_HANDLE_value then tryMapHandle := CreateFileMapping(FileHandle, nil, PAGE_READONLY, 0, 0, nil);if MapHandle <> 0 then tryViewPointer := MapViewOfFile(MapHandle, FILE_MAP_READ, 0, 0, 0);if ViewPointer <> nil then tryMD5Update(Context, ViewPointer, GetFileSize(FileHandle, nil));UnmapViewOfFile(ViewPointer);end;finallyCloseHandle(MapHandle);end;finallyCloseHandle(FileHandle);end;MD5Final(Context, Result);end;// Create hex representation of given Digestfunction MD5Print(D: MD5Digest): string;varI: byte;constDigits: array[0..15] of char =('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');beginResult := '';for I := 0 to 15 do Result := Result + Digits[(D[I] shr 4) and $0f] + Digits[D[I] and $0f];end;// -----------------------------------------------------------------------------------------------// Compare two Digestsfunction MD5Match(D1, D2: MD5Digest): boolean;varI: byte;beginResult := TRUE;while Result and (I < 16) do begin Result := D1[I] = D2[I];inc(I);end;end;end.。
基于Delphi的加密算法应用模拟系统
基于Delphi的加密算法应用模拟系统作者:王旭辉王涛康晓凤来源:《软件导刊》2012年第02期摘要:为了提高学习者单位时间内的学习效率和学习质量,我们利用Delphi技术开发了一个加密算法应用模拟系统,将加密技术中常用的几个加密算法如:置换、凯撒、乘法、维吉尼亚、PLAYFAIR、DES算法、RSA算法、MD5算法进行模拟实现,使得用户更加直观的了解这些加密算法的原理和实际的应用。
关键词:Delphi;加密;解密中图分类号:TP309.2 文献标识码:A 文章编号:1672-7800(2012)002-0117-基金项目:徐州工程学院2011年度大学生创新创业基金项目作者简介:王旭辉(1990-),男,山东青岛人,徐州工程学院本科生;研究方向为信息安全;王涛(1989-),男,江苏连云港人,徐州工程学院本科生,研究方向为信息安全;康晓凤(1978-),女,江苏徐州人,徐州工程学院讲师,研究方向为信息安全。
0 引言随着互联网的迅速发展,网络技术已深入到社会的各个领域,互联网的安全问题已成为社会关注的焦点,计算机信息的保密问题显得越来越重要,密码技术是对计算机信息进行保护的最实用和最可靠的方法。
但是在长期的教学中发现,密码算法这部分内容学生学习起来感到非常的困难和抽象。
为了提高学生的学习兴趣,使所学内容更直观、更容易接受,提高学习者单位时间内的学习效率和学习质量,我们就把这种很难看到的实现过程,通过计算机模拟实现,然后应用到我们的实际教学中,让学生可以清楚地看到加密算法的具体的实现过程,有利于学生快速理解与掌握这些内容,有效的提高了课堂的教学效果和教学质量。
1 系统整体设计方案我们首先根据教学大纲,把需要实现的密码算法进行筛选,通过我们的筛选共选定了8个算法进行实现,为了增加系统的清晰性,这8个算法我们又分成了两类,即古典和现代加密算法,然后再根据每个算法不同的加、解密过程,为每个算法建立模型,确定实现方案,最后利用 Delphi软件开发实现。
2024版Delphi程序设计[1]
数据库性能。
21
05
Delphi网络编程
Hale Waihona Puke 2024/1/2922
网络通信原理简介
客户端/服务器模型
网络通信通常采用客户端/服务器模型,其中 客户端发送请求,服务器响应请求并返回数据。
2024/1/29
套接字编程
网络通信基于套接字(socket)进行,套接字是不同 计算机之间进行通信的端点。
传输协议
常见的传输协议包括TCP和UDP。TCP提供可 靠的、面向连接的通信服务,而UDP提供无 连接的、不可靠的通信服务。
23
TCP/IP协议在Delphi中实现
2024/1/29
使用WinSock控件
Delphi中可以使用WinSock控件实现TCP/IP协议,通过设置控件 属性并调用相关方法即可建立客户端或服务器应用程序。
熟悉窗体的事件处理机制,如加载、关闭、大小改变 等事件。
2024/1/29
13
常用控件介绍
基本控件
学习Delphi中常用的基本控件,如按钮、标签、 文本框等。
高级控件
了解高级控件的使用,如列表框、树形视图、 表格等。
2024/1/29
控件属性与事件
掌握控件的常用属性和事件,如控件的名称、大小、颜色、单击事件等。
编译器异常
编译时检测到的错误,如语法错误或类型不匹配。通过编译器提 示信息进行修复。
自定义异常
用户自定义的异常类型,用于特定业务逻辑的错误处理。通过创 建自定义异常类实现。
33
自定义异常处理机制
创建自定义异常类
继承自Exception类或其子类,添加自定义 属性和方法。
抛出自定义异常
在适当的位置使用raise语句抛出异常,并传 递异常实例。
计算机毕业设计38DELPHI基于USB KEY的文件加密工具—-客户端的实现
分类号:TP315 U D C:D10621-408-(2007)5745-0 密级:公开编号:2002214042成都信息工程学院学位论文基于USB KEY的文件加密工具—-客户端的实现论文作者姓名:康桃义申请学位专业:计算机科学与技术申请学位类别:工学学士指导教师姓名(职称):高宏宇(讲师)论文提交日期:2007年 6 月 4 日基于USB KEY的文件加密工具---客户端的实现摘要随着计算机不断的发展,文件的安全性受大越来越大的重视,为了对自己需要保密的文件进行加密,防止别人窃取和不被别人识别,提高文件的安全强度,文件加密已成为一个重要的话题。
本设计为了解决用户记忆烦琐的密码问题,以软、硬件相结合的方式,实现了文件加密和解密的功能。
具有操作简单、稳定性高、兼容性好、速度快等特点。
该系统使用Rockey2加密锁,用delphi进行开发。
本文主要介绍了该设计的基本功能及实现方法。
在设计与实现中对KEY内存的划分,初始化、文件加密和文件解密进行了详细的分析和说明;在应用与编码中介绍了各个模块的应用与实现;最后介绍了本设计的操作界面及改进方式。
关键词:USB;加密锁;加密;解密The Files Eencryption Tool Based on USB-KEY----- Client SideAbstractAlong with the development of the computer, the security demand of the files is increasing. For the sake of encrypting the files of the users to prevent the act of stealing and improving the security of the documents, the security encryption of the documents have become an important issue.This design based on the combination of software and hardware to provide an easy and reliable approach to encrypt files. Password memorization is not necessary. The benefits of this design are easy to use and high stability. This project is coded by Delphi and base on Rockey2( a type of USB key). This paper describes the basic functions and methods to build a files encryption tools based on USB key. Details of implementation are also involved in this paper.Key words:USB;encryption lock;encrypt;decrypt目录论文总页数:25页1 引言 (1)1.1 课题背景 (1)1.2 国内外研究现状 (1)1.3 本设计研究的意义 (1)1.4 本设计研究的方法 (1)2需求分析 (1)2.1 用户问题分析 (1)2.2 本设计应满足的需求 (2)2.3 本设计的保护技术 (2)3设计与实现 (2)3.1 程序语言:delphi (2)3.2 USB KEY (3)3.2.1 USB KEY选型 (3)3.2.2 Rockey2 加密锁的优点 (3)3.2.3 Rockey2 加密锁要点说明 (3)3.3 Rockey2 内存分配 (4)3.4 总体设计模块 (4)3.5客户端逻辑流程 (5)3.6客户端设计逻辑流程 (6)3.6.1 初始化和写用户名的设计流程图 (6)3.6.2 加密设计流程图 (7)3.6.3 解密设计流程图 (8)4应用与编码 (9)4.1硬件的安装 (9)4.2控件的使用 (9)4.3进度框 (9)4.4初始化的应用与编码 (9)4.5写用户名和密码的应用与编码 (11)4.6文件加密应用与编码 (13)4.7文件解密应用与编码 (16)4.8查看被加密文件后的信息 (17)5操作界面 (19)结论 (20)参考文献 (21)附录 (22)致谢 (24)声明 (25)1 引言1.1 课题背景随着社会高科技,商品经济化突飞猛进的发展,计算机的应用已经普及到经济和社会生活的各个领域。
delphi十六进制转字符
delphi十六进制转字符Delphi是一种编程语言,它具有强大的十六进制转字符的功能。
本文将介绍如何使用Delphi实现十六进制转字符,并探讨其应用场景。
我们需要了解十六进制和字符之间的关系。
十六进制是一种表示数字的进位制,使用0-9和A-F这16个字符来表示0-15的数值。
而字符则是计算机中用来表示文字和符号的基本单位。
在计算机中,字符使用ASCII码或Unicode编码表示。
在Delphi中,可以通过使用内置的函数将十六进制转换为字符。
具体的函数是Chr(),它的参数是一个整数值,代表十六进制的值。
例如,Chr($41)将返回字符'A',因为$41是十六进制表示的65,而65对应ASCII码中的字符'A'。
通过使用这个函数,我们可以轻松地将十六进制转换为字符。
例如,如果我们有一个十六进制数值$48,我们可以使用Chr($48)将其转换为字符'H'。
那么十六进制转字符有什么实际应用呢?一个典型的应用场景是在网络通信中,当我们需要传输二进制数据时,可以将其转换为十六进制表示,以便在不同的系统之间进行交互。
而在接收方,我们则可以将十六进制转换为字符,以还原原始的数据。
另一个应用场景是在数据存储和处理中,有时候我们需要以十六进制的形式来表示数据,比如在调试时查看内存中的数据。
通过将十六进制转换为字符,我们可以更加直观地理解数据的含义和结构。
除了以上的应用场景,十六进制转字符在密码学中也有重要的作用。
在加密算法中,经常需要将明文转换为二进制数据,并进行一系列的计算和操作。
而在展示和分析加密结果时,我们通常会将结果转换为十六进制表示,以便更好地理解加密的过程和结果。
总结一下,Delphi提供了方便快捷的十六进制转字符的功能,可以应用于网络通信、数据存储和处理以及密码学等领域。
通过将十六进制转换为字符,我们可以更好地理解数据的含义和结构,方便进行数据交互和分析。
DELPHI加密字串(异或运算加密)
DELPHI加密字串(异或运算加密)这个本来我我在DELPHI盒子看到的,后来我对其作了一点修改,这里上全部代码,可以直接用首先有两个自定的转换函数:1.function myStrT oHex(s:string):string; //字串转16进制2.var3.TmpStr:string;4.i:integer;5.begin6.TmpStr:='';7.for i:=1 to Length(s)do8.TmpStr:=TmpStr+IntToHex(ord(s[i]),2);9.Result:=TmpStr;10.end;11.12.function myHexT oStr(S:string):string; //16进制转字串13.var14.HexS,TmpStr:string;15.i:Integer;16.a:Byte;17.begin18.HexS:=s;19.if Length(HexS) mod 2=1 then20.HexS:=HexS+'0';21.TmpStr:='';22.for i:=1 to(Length(HexS)div 2)do23.begin24.a:=StrToInt('$'+HexS[2*i-1]+HexS[2*i]);25.TmpStr:=TmpStr+Chr(a);26.end;27.Result:=TmpStr;28.end;然后就是加密、解密函数了:1.{两个函数的参数相同,s为要加密、解密的字串;sKey为密匙}2.function EncryptStr(const s:string;sKey:string):string; //加密3.var4.i,j:Integer;5.HexS,HexsKey,MidS,TmpStr:string;6.a,b,c:byte;7.begin8.HexS:=myStrToHex(s);9.HexsKey:=myStrT oHex(sKey);10.MidS:=HexS;11.for i:=1 to(Length(HexsKey)div 2)do12.begin13.if i<>1 then MidS:=TmpStr;14.TmpStr:=''; //下面要用到TmpStr,所以要清空15.for j:=1 to (Length(MidS)div 2)do16.begin17.a:=StrToInt('$'+midS[2*j-1]+midS[2*j]);18.b:=StrToInt('$'+HexsKey[2*i-1]+HexsKey[2*i]);19.c:=a xor b;20.tmpstr:=TmpStr+myStrT oHex(Chr(c));21.end;22.end;23.Result:=TmpStr;24.end;25.26.function DecryptStr(const s:string;sKey:string):string; / /解密27.var28.i,j:Integer;29.HexS,HexsKey,MidS,TmpStr:string;30.a,b,c:Byte;31.begin32.HexS:=s;33.if Length(HexS)mod 2=1 then //检查是否为字符串34.begin35.ShowMessage('密文错误!');36.Exit;37.end;38.HexsKey:=myStrT oHex(sKey);39.TmpStr:=HexS;40.MidS:=HexS;41.for i:=(length(HexsKey) div 2) downto 1 do42.begin43.if i<>(length(HexsKey) div 2)then44.MidS:=TmpStr;45.TmpStr:=''; //下面要用到TmpStr,所以要清空46.for j:=1 to(length(MidS) div 2)do47.begin48.a:=StrToInt('$'+MidS[2*j-1]+MidS[2*j]);49.b:=StrToInt('$'+HexsKey[2*i-1]+HexsKey[2*i]);50.c:=a xor b;51.TmpStr := TmpStr+myStrT oHex(Chr(c));52.end;53.end;54.Result:=myHexToStr(TmpStr);55.end;现在已经可以使用了,调用EncryptStr和DecryptStr分别加密、解密例:1.Edit1.Text:=EncryptStr('Hello','delphi');2.3.////////////////////////////////////////4.5.Edit1.Text:=DecryptStr(Edit1.Text,'delphi');。
课题-Delphi-DES加密
Delphi DES加密之前自己修改过一个,又找到一个,觉得这个要比我修改的好,之前修改的好像有点问题:-(unit NewDES;interfaceusesSysUtils,Classes;typeTByte32 = array[1..32] of Byte;TSData = array[0..63] of Byte;TBlock = array[0..7] of Byte;function EnCryptStr(aStr: AnsiString; aKey: AnsiString ): AnsiString;function DeCryptStr(aStr: AnsiString; aKey: AnsiString ): AnsiString;function EnCrypt(in_buf:Tblock; aKey: AnsiString = 'garfield'): Tblock;function DeCrypt(in_buf:Tblock; aKey: AnsiString = 'garfield'): Tblock;procedure EnCryptFile(infile,outfile: AnsiString; aKey: AnsiString );procedure DECryptFile(infile,outfile: AnsiString; aKey: AnsiString );implementationconstSA1: TSData =(1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1); SA2: TSData =(1, 0, 1, 1, 0, 1, 0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, 8, 23, 12, 25, 21, 14, 6, 28, 10, 18, 9, 1, 22, 15, 4,43, 54, 33, 39, 49, 29, 32, 42, 53, 47, 35, 50, 46, 51, 41, 30, 36, 55, 48, 44, 52, 38, 31, 34), (18, 21, 15, 28, 5, 9, 7, 4, 19, 10, 25, 14, 27, 23, 16, 8, 2, 12, 20, 11, 3, 24, 17, 6,45, 56, 35, 41, 51, 31, 34, 44, 55, 49, 37, 52, 48, 53, 43, 32, 38, 29, 50, 46, 54, 40, 33, 36), (20, 23, 17, 2, 7, 11, 9, 6, 21, 12, 27, 16, 1, 25, 18, 10, 4, 14, 22, 13, 5, 26, 19, 8,47, 30, 37, 43, 53, 33, 36, 46, 29, 51, 39, 54, 50, 55, 45, 34, 40, 31, 52, 48, 56, 42, 35, 38), (22, 25, 19, 4, 9, 13, 11, 8, 23, 14, 1, 18, 3, 27, 20, 12, 6, 16, 24, 15, 7, 28, 21, 10,49, 32, 39, 45, 55, 35, 38, 48, 31, 53, 41, 56, 52, 29, 47, 36, 42, 33, 54, 50, 30, 44, 37, 40), (24, 27, 21, 6, 11, 15, 13, 10, 25, 16, 3, 20, 5, 1, 22, 14, 8, 18, 26, 17, 9, 2, 23, 12,51, 34, 41, 47, 29, 37, 40, 50, 33, 55, 43, 30, 54, 31, 49, 38, 44, 35, 56, 52, 32, 46, 39, 42), (26, 1, 23, 8, 13, 17, 15, 12, 27, 18, 5, 22, 7, 3, 24, 16, 10, 20, 28, 19, 11, 4, 25, 14,53, 36, 43, 49, 31, 39, 42, 52, 35, 29, 45, 32, 56, 33, 51, 40, 46, 37, 30, 54, 34, 48, 41, 44),56, 39, 46, 52, 34, 42, 45, 55, 38, 32, 48, 35, 31, 36, 54, 43, 49, 40, 33, 29, 37, 51, 44, 47), (3, 6, 28, 13, 18, 22, 20, 17, 4, 23, 10, 27, 12, 8, 1, 21, 15, 25, 5, 24, 16, 9, 2, 19,30, 41, 48, 54, 36, 44, 47, 29, 40, 34, 50, 37, 33, 38, 56, 45, 51, 42, 35, 31, 39, 53, 46, 49), (5, 8, 2, 15, 20, 24, 22, 19, 6, 25, 12, 1, 14, 10, 3, 23, 17, 27, 7, 26, 18, 11, 4, 21,32, 43, 50, 56, 38, 46, 49, 31, 42, 36, 52, 39, 35, 40, 30, 47, 53, 44, 37, 33, 41, 55, 48, 51), (7, 10, 4, 17, 22, 26, 24, 21, 8, 27, 14, 3, 16, 12, 5, 25, 19, 1, 9, 28, 20, 13, 6, 23,34, 45, 52, 30, 40, 48, 51, 33, 44, 38, 54, 41, 37, 42, 32, 49, 55, 46, 39, 35, 43, 29, 50, 53), (9, 12, 6, 19, 24, 28, 26, 23, 10, 1, 16, 5, 18, 14, 7, 27, 21, 3, 11, 2, 22, 15, 8, 25,36, 47, 54, 32, 42, 50, 53, 35, 46, 40, 56, 43, 39, 44, 34, 51, 29, 48, 41, 37, 45, 31, 52, 55), (11, 14, 8, 21, 26, 2, 28, 25, 12, 3, 18, 7, 20, 16, 9, 1, 23, 5, 13, 4, 24, 17, 10, 27,38, 49, 56, 34, 44, 52, 55, 37, 48, 42, 30, 45, 41, 46, 36, 53, 31, 50, 43, 39, 47, 33, 54, 29), (13, 16, 10, 23, 28, 4, 2, 27, 14, 5, 20, 9, 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1,40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47, 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 56, 31), (14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32)); varG: array[1..16, 1..48] of Byte;L, R, F: TByte32;C: array[1..56] of Byte;//对转换后的密码进行置换procedure DES_Init(Key: TBlock; FCode: Boolean);varn, h: Byte;beginC[1] := Ord(Key[7] and 128 > 0); C[29] := Ord(Key[7] and 2 > 0);C[2] := Ord(Key[6] and 128 > 0); C[30] := Ord(Key[6] and 2 > 0);C[3] := Ord(Key[5] and 128 > 0); C[31] := Ord(Key[5] and 2 > 0);C[4] := Ord(Key[4] and 128 > 0); C[32] := Ord(Key[4] and 2 > 0);C[5] := Ord(Key[3] and 128 > 0); C[33] := Ord(Key[3] and 2 > 0);C[6] := Ord(Key[2] and 128 > 0); C[34] := Ord(Key[2] and 2 > 0);C[7] := Ord(Key[1] and 128 > 0); C[35] := Ord(Key[1] and 2 > 0);C[8] := Ord(Key[0] and 128 > 0); C[36] := Ord(Key[0] and 2 > 0);C[9] := Ord(Key[7] and 64 > 0); C[37] := Ord(Key[7] and 4 > 0);C[10] := Ord(Key[6] and 64 > 0); C[38] := Ord(Key[6] and 4 > 0);C[11] := Ord(Key[5] and 64 > 0); C[39] := Ord(Key[5] and 4 > 0);C[12] := Ord(Key[4] and 64 > 0); C[40] := Ord(Key[4] and 4 > 0);C[13] := Ord(Key[3] and 64 > 0); C[41] := Ord(Key[3] and 4 > 0);C[14] := Ord(Key[2] and 64 > 0); C[42] := Ord(Key[2] and 4 > 0);C[15] := Ord(Key[1] and 64 > 0); C[43] := Ord(Key[1] and 4 > 0);C[16] := Ord(Key[0] and 64 > 0); C[44] := Ord(Key[0] and 4 > 0);C[17] := Ord(Key[7] and 32 > 0); C[45] := Ord(Key[7] and 8 > 0);C[18] := Ord(Key[6] and 32 > 0); C[46] := Ord(Key[6] and 8 > 0);C[19] := Ord(Key[5] and 32 > 0); C[47] := Ord(Key[5] and 8 > 0);C[20] := Ord(Key[4] and 32 > 0); C[48] := Ord(Key[4] and 8 > 0);C[21] := Ord(Key[3] and 32 > 0); C[49] := Ord(Key[3] and 8 > 0);C[22] := Ord(Key[2] and 32 > 0); C[50] := Ord(Key[2] and 8 > 0);C[23] := Ord(Key[1] and 32 > 0); C[51] := Ord(Key[1] and 8 > 0);C[24] := Ord(Key[0] and 32 > 0); C[52] := Ord(Key[0] and 8 > 0);C[25] := Ord(Key[7] and 16 > 0); C[53] := Ord(Key[3] and 16 > 0);C[26] := Ord(Key[6] and 16 > 0); C[54] := Ord(Key[2] and 16 > 0);C[27] := Ord(Key[5] and 16 > 0); C[55] := Ord(Key[1] and 16 > 0);C[28] := Ord(Key[4] and 16 > 0); C[56] := Ord(Key[0] and 16 > 0);if FCode thenbeginfor n := 1 to 16 dobeginfor h := 1 to 48 dobeginG[n, h] := C[Sc[n, h]];end;end;endelsebeginbeginG[17 - n, h] := C[Sc[n, h]];end;end;end;end;//对输入的8字节数据加密/解密procedure DES_Code(Input: TBlock; var Output: TBlock);varn: Byte;z: Word;beginL[1] := Ord(Input[7] and 64 > 0); R[1] := Ord(Input[7] and 128 > 0); L[2] := Ord(Input[6] and 64 > 0); R[2] := Ord(Input[6] and 128 > 0); L[3] := Ord(Input[5] and 64 > 0); R[3] := Ord(Input[5] and 128 > 0); L[4] := Ord(Input[4] and 64 > 0); R[4] := Ord(Input[4] and 128 > 0); L[5] := Ord(Input[3] and 64 > 0); R[5] := Ord(Input[3] and 128 > 0); L[6] := Ord(Input[2] and 64 > 0); R[6] := Ord(Input[2] and 128 > 0); L[7] := Ord(Input[1] and 64 > 0); R[7] := Ord(Input[1] and 128 > 0); L[8] := Ord(Input[0] and 64 > 0); R[8] := Ord(Input[0] and 128 > 0); L[9] := Ord(Input[7] and 16 > 0); R[9] := Ord(Input[7] and 32 > 0); L[10] := Ord(Input[6] and 16 > 0); R[10] := Ord(Input[6] and 32 > 0); L[11] := Ord(Input[5] and 16 > 0); R[11] := Ord(Input[5] and 32 > 0); L[12] := Ord(Input[4] and 16 > 0); R[12] := Ord(Input[4] and 32 > 0); L[13] := Ord(Input[3] and 16 > 0); R[13] := Ord(Input[3] and 32 > 0); L[14] := Ord(Input[2] and 16 > 0); R[14] := Ord(Input[2] and 32 > 0); L[15] := Ord(Input[1] and 16 > 0); R[15] := Ord(Input[1] and 32 > 0); L[16] := Ord(Input[0] and 16 > 0); R[16] := Ord(Input[0] and 32 > 0); L[17] := Ord(Input[7] and 4 > 0); R[17] := Ord(Input[7] and 8 > 0); L[18] := Ord(Input[6] and 4 > 0); R[18] := Ord(Input[6] and 8 > 0); L[19] := Ord(Input[5] and 4 > 0); R[19] := Ord(Input[5] and 8 > 0); L[20] := Ord(Input[4] and 4 > 0); R[20] := Ord(Input[4] and 8 > 0); L[21] := Ord(Input[3] and 4 > 0); R[21] := Ord(Input[3] and 8 > 0); L[22] := Ord(Input[2] and 4 > 0); R[22] := Ord(Input[2] and 8 > 0); L[23] := Ord(Input[1] and 4 > 0); R[23] := Ord(Input[1] and 8 > 0); L[24] := Ord(Input[0] and 4 > 0); R[24] := Ord(Input[0] and 8 > 0); L[25] := Input[7] and 1; R[25] := Ord(Input[7] and 2 > 0);L[26] := Input[6] and 1; R[26] := Ord(Input[6] and 2 > 0);L[27] := Input[5] and 1; R[27] := Ord(Input[5] and 2 > 0);L[28] := Input[4] and 1; R[28] := Ord(Input[4] and 2 > 0);L[29] := Input[3] and 1; R[29] := Ord(Input[3] and 2 > 0);L[30] := Input[2] and 1; R[30] := Ord(Input[2] and 2 > 0);L[31] := Input[1] and 1; R[31] := Ord(Input[1] and 2 > 0);L[32] := Input[0] and 1; R[32] := Ord(Input[0] and 2 > 0);for n := 1 to 16 dobeginz := ((R[32] xor G[n, 1]) shl 5) or ((R[5] xor G[n, 6]) shl 4)or ((R[ 1] xor G[n, 2]) shl 3) or ((R[2] xor G[n, 3]) shl 2)or ((R[ 3] xor G[n, 4]) shl 1) or ( R[4] xor G[n, 5]);F[ 9] := L[ 9] xor SA1[z];F[17] := L[17] xor SB1[z];F[23] := L[23] xor SC1[z];F[31] := L[31] xor SD1[z];z := ((R[4] xor G[n, 7]) shl 5) or ((R[9] xor G[n, 12]) shl 4)or ((R[5] xor G[n, 8]) shl 3) or ((R[6] xor G[n, 9]) shl 2)or ((R[7] xor G[n, 10]) shl 1) or ( R[8] xor G[n, 11]);F[13] := L[13] xor SA2[z];F[28] := L[28] xor SB2[z];F[ 2] := L[ 2] xor SC2[z];F[18] := L[18] xor SD2[z];z := ((R[ 8] xor G[n, 13]) shl 5) or ((R[13] xor G[n, 18]) shl 4)or ((R[ 9] xor G[n, 14]) shl 3) or ((R[10] xor G[n, 15]) shl 2)or ((R[11] xor G[n, 16]) shl 1) or ( R[12] xor G[n, 17]);F[24] := L[24] xor SA3[z];z := ((R[12] xor G[n, 19]) shl 5) or ((R[17] xor G[n, 24]) shl 4)or ((R[13] xor G[n, 20]) shl 3) or ((R[14] xor G[n, 21]) shl 2)or ((R[15] xor G[n, 22]) shl 1) or ( R[16] xor G[n, 23]);F[26] := L[26] xor SA4[z];F[20] := L[20] xor SB4[z];F[10] := L[10] xor SC4[z];F[ 1] := L[ 1] xor SD4[z];z := ((R[16] xor G[n, 25]) shl 5) or ((R[21] xor G[n, 30]) shl 4)or ((R[17] xor G[n, 26]) shl 3) or ((R[18] xor G[n, 27]) shl 2)or ((R[19] xor G[n, 28]) shl 1) or ( R[20] xor G[n, 29]);F[ 8] := L[ 8] xor SA5[z];F[14] := L[14] xor SB5[z];F[25] := L[25] xor SC5[z];F[ 3] := L[ 3] xor SD5[z];z := ((R[20] xor G[n, 31]) shl 5) or ((R[25] xor G[n, 36]) shl 4)or ((R[21] xor G[n, 32]) shl 3) or ((R[22] xor G[n, 33]) shl 2)or ((R[23] xor G[n, 34]) shl 1) or ( R[24] xor G[n, 35]);F[ 4] := L[ 4] xor SA6[z];F[29] := L[29] xor SB6[z];F[11] := L[11] xor SC6[z];F[19] := L[19] xor SD6[z];z := ((R[24] xor G[n, 37]) shl 5) or ((R[29] xor G[n, 42]) shl 4)or ((R[25] xor G[n, 38]) shl 3) or ((R[26] xor G[n, 39]) shl 2)or ((R[27] xor G[n, 40]) shl 1) or ( R[28] xor G[n, 41]);F[32] := L[32] xor SA7[z];F[12] := L[12] xor SB7[z];F[22] := L[22] xor SC7[z];F[ 7] := L[ 7] xor SD7[z];z := ((R[28] xor G[n, 43]) shl 5) or ((R[ 1] xor G[n, 48]) shl 4)or ((R[29] xor G[n, 44]) shl 3) or ((R[30] xor G[n, 45]) shl 2)or ((R[31] xor G[n, 46]) shl 1) or ( R[32] xor G[n, 47]);F[ 5] := L[ 5] xor SA8[z];F[27] := L[27] xor SB8[z];F[15] := L[15] xor SC8[z];F[21] := L[21] xor SD8[z];L := R;R := F;end;Output[0] := (L[8] shl 7) or (R[8] shl 6) or (L[16] shl 5) or (R[16] shl 4) or (L[24] shl 3) or (R[24] shl 2) or (L[32] shl 1) or R[32];Output[1] := (L[7] shl 7) or (R[7] shl 6) or (L[15] shl 5) or (R[15] shl 4) or (L[23] shl 3) or (R[23] shl 2) or (L[31] shl 1) or R[31];Output[2] := (L[6] shl 7) or (R[6] shl 6) or (L[14] shl 5) or (R[14] shl 4) or (L[22] shl 3) or (R[22] shl 2) or (L[30] shl 1) or R[30];Output[3] := (L[5] shl 7) or (R[5] shl 6) or (L[13] shl 5) or (R[13] shl 4) or (L[21] shl 3) or (R[21] shl 2) or (L[29] shl 1) or R[29];Output[4] := (L[4] shl 7) or (R[4] shl 6) or (L[12] shl 5) or (R[12] shl 4) or (L[20] shl 3) or (R[20] shl 2) or (L[28] shl 1) or R[28];Output[5] := (L[3] shl 7) or (R[3] shl 6) or (L[11] shl 5) or (R[11] shl 4) or (L[19] shl 3) or (R[19] shl 2) or (L[27] shl 1) or R[27];Output[6] := (L[2] shl 7) or (R[2] shl 6) or (L[10] shl 5) or (R[10] shl 4) or (L[18] shl 3) or (R[18] shl 2) or (L[26] shl 1) or R[26];Output[7] := (L[1] shl 7) or (R[1] shl 6) or (L[9] shl 5) or (R[9] shl 4) or (L[17] shl 3) or (R[17] shl 2) or (L[25] shl 1) or R[25];end;//把密码转换成8字节的数据function StrToKey(aKey: AnsiString): TBlock;varKey : TBlock;I : Integer;beginFillChar(Key, SizeOf(TBlock), 0);for I := 1 to Length(aKey) dobeginend;//加密8字节的数据function EnCrypt(in_Buf: Tblock; aKey: AnsiString): TBlock;varWriteBuf: TBlock;Key : TBlock;begintryfillchar(writeBuf,8,0);Key := StrToKey(aKey);Des_Init(Key, True);Des_Code(in_buf, WriteBuf);result:=writebuf;exceptfillchar(writeBuf,8,0);result:=writebuf;end;end;//解密8字节的数据function DeCrypt(in_buf: Tblock; aKey: AnsiString):Tblock;varWriteBuf : TBlock;Key : TBlock;begintryKey := StrToKey(aKey);Des_Init(Key, False);FillChar(WriteBuf, 8, 0);Des_Code(in_Buf, WriteBuf);result :=WriteBuf;exceptFillChar(WriteBuf, 8, 0);result :=WriteBuf;end;end;//加密字符串function EnCryptStr(aStr: AnsiString; aKey: AnsiString): AnsiString; varReadBuf : TBlock;WriteBuf: TBlock;Key : TBlock;Count : Integer;Offset : Integer;I : Integer;S : AnsiString;beginresult := '';Key := StrToKey(aKey);Des_Init(Key, True);Offset := 1;Count := Length(aStr);repeatS := Copy(aStr, Offset, 8);FillChar(ReadBuf, 8, 0);Move(S[1], ReadBuf, Length(S));Des_Code(ReadBuf, WriteBuf);for I := 0 to 7 dobeginresult := result + IntToHex(WriteBuf[I], 2);end;Offset := Offset + 8;until Offset > ((Count+7) div 8) * 8;end;//解密字符串WriteBuf : TBlock;Key : TBlock;Offset : Integer;Count : Integer;I : Integer;S : AnsiString;begintryKey := StrToKey(aKey);Des_Init(Key, False);S := '';I := 1;repeatS := S + AnsiChar(Chr(StrToInt('$'+Copy(aStr, I, 2))));Inc(I, 2);until I > Length(aStr);//Result:=s;//Exit;Offset := 1;Count := Length(S);while Offset < ((Count+7) div 8 * 8) dobeginFillChar(ReadBuf, 8, 0);Move(S[Offset], ReadBuf, 8);Des_Code(ReadBuf, WriteBuf);for I := 0 to 7 dobeginresult := result + AnsiChar(Chr(WriteBuf[I]));end;Offset := Offset + 8;end;result := StrPas(PAnsiChar(result));exceptresult := '';end;end;//加密文件procedure EnCryptFile(infile,outfile: AnsiString; aKey: AnsiString );varReadBuf : TBlock;WriteBuf: TBlock;LEN,len1,len2,I:INTEGER;ms1,ms2:Tmemorystream;beginif (infile='') or (outfile='') or (akey='') then exit;tryms1:=Tmemorystream.Create;ms2:=Tmemorystream.Create;ms1.LoadFromFile(infile);//得到原始文件长度并按8的整数倍对齐len:=ms1.Size;len1 := ( len + 7 ) SHR 3; // 按8Bytes(64bits) 对齐ms1.Size := len1 SHL 3;len2:=ms1.Size;ms1.Position:=0;len1:=len2 div 8;for i:=0 to len1-1 dobeginms1.Read(Readbuf,8);writebuf:=EnCrypt(readbuf,aKey);ms2.Write(writebuf,8);end;//保存原始文件长度ms2.Seek( 0, soFromEnd );ms2.Write( len, SizeOf( len) ); // 将原始大小记录在数据末:///ms2.Free;exceptms1.Free;ms2.Free;end;end;//解密文件procedure DeCryptFile(infile,outfile: AnsiString; aKey: AnsiString ); varReadBuf,WriteBuf : TBlock;LEN,len1,len2,I:INTEGER;ms1,ms2:Tmemorystream;beginif (infile='') or (outfile='') or (akey='') then exit;try//加密ms1:=Tmemorystream.Create;ms2:=Tmemorystream.Create;ms1.LoadFromFile(infile);//得到原始文件长度lenlen1 := SizeOf( len );ms1.Seek( -len1, soFromEnd ); // 取得原始大小ms1.Read( len, len1 );len1 := ms1.Size - len1;ms1.Size := len1;len1 := ( len1 + 7 ) SHR 3; // 按8Bytes(64bits) 对齐If ( ms1.Size <> ( len1 SHL 3 ) ) ThenRaise Exception.Create( 'Invalid data size!' );len1:=ms1.Size;len1:=len1 div 8;ms1.Position:=0;ms2.Position:=0;fillchar(readbuf,8,0);for i:=0 to len1-1 dobeginms1.Read(readbuf,8);writebuf:=DeCrypt(readbuf,aKey);ms2.Write(writebuf,8);end;ms2.SetSize(len);ms2.SaveToFile(outfile);ms1.Free;ms2.Free;exceptms1.Free;ms2.Free;end;end;end.。
delphi 十六进制异或运算
delphi 十六进制异或运算Delphi 十六进制异或运算引言:在计算机编程中,异或运算是一种常用的逻辑运算符。
它可以用于加密、校验和计算、数据处理等多个领域。
本文将介绍Delphi中的十六进制异或运算,并提供一些实例来帮助读者更好地理解和应用这一运算。
一、概述十六进制异或运算是指对两个十六进制数进行位异或操作。
异或运算的规则是:对应位相同为0,不同为1。
在Delphi中,我们可以使用XOR函数来执行这一运算。
二、Delphi中的十六进制异或运算在Delphi中,我们可以使用XOR函数来执行十六进制异或运算。
该函数接受两个参数,分别是待运算的十六进制数。
下面是一个示例代码:```delphifunction HexXOR(hex1, hex2: string): string;varint1, int2, result: Integer;beginint1 := StrToInt('$' + hex1);int2 := StrToInt('$' + hex2);result := int1 xor int2;Result := IntToHex(result, 2);end;```在上面的代码中,我们定义了一个HexXOR函数,该函数接受两个十六进制数作为输入,并返回它们的异或结果。
首先,我们使用StrToInt函数将十六进制字符串转换为整数,然后使用xor运算符执行异或运算,最后使用IntToHex函数将结果转换回十六进制字符串。
这样,我们就可以方便地在Delphi中进行十六进制异或运算了。
三、实例应用十六进制异或运算在实际应用中有着广泛的用途。
下面是一些常见的应用场景:1. 数据加密十六进制异或运算可以用于数据加密。
通过对明文和密钥进行异或运算,可以得到密文。
只有拥有相同密钥的人才能正确解密。
这种加密算法简单高效,被广泛应用于网络传输、文件加密等领域。
2. 校验和计算十六进制异或运算可以用于校验和的计算。
用Delphi编写文件加密、解密软件
用Delphi编写文件加密、解密软件我们接触过很多文件加密软件,对初学者来说,那简直太神奇了:一瞬间,熟悉的文件变得面目全非;而谈笑中,它又完璧归赵,毫发无损。
如果能自己写一个这样的程序,那感觉一定很"酷"。
若只是简单地对文件内容作一些加、减、异或等操作,则安全性太低,达不到加密的效果;专业的加密算法虽然安全性好,但过于复杂,又难于为编程爱好者所理解。
下面,我们一起来完成一个准专业的文件加密、解密程序,通过学习,希望初学者能对文件加密的算法、思路有一个清晰的认识。
程序的界面如图1。
各构件需设置的属性如下表:对文件加密的思路是:1、判断源文件fname是否存在。
2、比较两次输入的密码是否一致,否则要求用户重新输入。
3、根据密码的长度和密码字符的ASCII码,通过特定的算法产生两个密码种子数seed1和seed2(字节型)。
4、判断文件是否已被加密过,如已加密,给出提示;如未加密,则利用种子数seed1和seed2再经特定的算法对文件内容逐字节加密变换,产生文件"$$$.tmp"5、产生"$$$.tmp"时,在文件头部写入一个标志(如字符串LOCKED)和种子数seed1和seed2,供解密时使用。
也就是说,加密后,文件会变长8个字节。
6、把原文件删除,将"$$$.tmp"改名,加密完成。
对文件解密的思路是:1、判断源文件fname是否存在。
2、根据密码,用相同的算法求得种子数。
3、打开欲解密文件,判断文件头六个字节是否是"LOCKED":如否,则提示文件未曾加密;如是,再读出第七、八字节,与seed1和seed2比较,相同则说明密码正确,开始解密。
4、用加密相反的算法对文件逐字节还原,产生文件"###.tmp"。
5、把原文件删除,将"###.tmp"改名,解密完成。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Delphi程序的时限和加密
日期:2005年5月31日作者:BUCK FORLAND 人气:2307 查看:[大字体中字体小字体] 本例中TRegistry是关键类,Delphi 4.0不能自行加入,需在uses部分手工加入“registry”,通过其方法“ReadString”和“WriteString”来读出和写入字符,亦可通过其方法“ReadDate”和“WriteDate”来读出和写入日期。
程序第一次运行就写入其运行时间,应用期限为30天,超过30天就不再运行。
全局变量NoRegistry、SpareDays来分别判断是否注册和剩余期限,自定义函数Encrypt为用户名到密码的变换函数。
一、程序启动时,通过搜索注册表,判断是否第一次运行和是否注册,来确定程序是否运行。
procedure TForm1.FormCreate(Sender: TObject);
var
Reg:Tregistry;
KeyName,TempCode,TempName,TempStr:string;
Same:Integer;
FirstDate,NowDate:Tdatetime;
NumberOfDays:real;
begin
NoRegistry:=true;
NowDate:=date; //取得运行时系统日期
try
//创建注册表,有该键则读取,无则创建
Reg:=Tregistry.Create ;
Reg.RootKey :=hkey_local_machine;
KeyName:='Software\jsjb\Example';
if Reg.OpenKey(KeyName,true) then
begin
TempName:=Reg.ReadString('UsrName');
TempCode:=Reg.ReadString('Passwd');
//读取用户名,注册号
try
FirstDate:=Reg.ReadDate('Date');
//非第一次则读入第一次运行时间
except
Reg.WriteDate('Date',NowDate);
// 若为第一次运行,则写入系统日期
FirstDate:=NowDate;
end;
end ;
reg.CloseKey ;
finally
reg.Free ;
end;
TempStr:=Encrypt(TempName);
//通过自定义函数Encrypt()来获取密码
Same:=CompareText(TempStr,TempCode);
//比较密码
if TempName<>'' then
if Same=0 then
NoRegistry:=false;
//验证密码,通过NoRegistry为false
if NoRegistry then
begin //若未注册...
NumberOfDays:=Nowdate-FirstDate;
SpareDays:=round(31-NumberOfDays);
Label1.Caption :=FloatToStr(SpareDays);
if((NumberOfDays>31) or (NumberOfDays<-1)) then
begin
showmessage('程序未注册超过试用期或更改系统时间,将终止运行!'); application.Terminate;//超过30天,则禁止运行
end;
end;
二、注册过程,其响应入口可放于"About"内。
procedure TAbout.Button1Click(Sender: TObject); var
InptName,InptCode,RealCode:String;
Same:Integer;
Reg:Tregistry;
Keyname:String;
begin
if NoRegistry then //未注册时做
begin
RealCode:='';
InptName:= InputBox('注册', '输入你的名字', '');
if InptName<>'' then
begin
InptCode:= InputBox('注册', '输入注册号', ''); RealCode:=Encrypt(InptName);
Same:=CompareText(RealCode,InptCode);
if (Same<>0) then
showmessage('注册号码不对,注册未成功!')
else
begin
//密码匹配时做:把用户名、密码写入注册表
Try
Reg:=Tregistry.Create ;
Reg.RootKey :=hkey_local_machine; KeyName:='Software\jsjb\Example';
if Reg.OpenKey(KeyName,true) then
Reg.WriteString('Passwd',InptCode);
Reg.WriteString('UsrName',InptName);
end;
reg.CloseKey ;
finally
Reg.Free ;
end;
NoRegistry:=false;
//可修改注册后的界面
end;
end;
end;
end;
三、密码的变换函数。
此变换函数可由读者自由发挥,在此,仅示一例而已。
Function TForm1.Encrypt(TempStr:string):string;
Var
Str1:String;
i,j:Integer;
Begin
Str1:='';
For i:=1 to Length(TempStr) do
begin
j:=(i i i i mod (i+30))+(i i mod (i+20))+i 3+1;
Str1:=Str1+chr(ord(TempStr)+j);
j:=(i i i i mod (i+30))+(i i mod (i+20))+i 3+1;
Str1:=Str1+chr(ord(TempStr)+j);
End;
Result:=Str1; end;。