一个只有17K的Delphi字符串加密程序源码

Delphi中MD5算法的实现、优化与常见问题解决方案 哈希算法是计算机科学中用于数据完整性校验和生成唯一标识的基础技术,其核心原理是将任意长度的输入通过特定计算映射为固定长度的输出。MD5作为一种经典的哈希函数,因其计算速度快、实现简单,在数据校验、缓存键生成等非安全敏感场景中仍有广泛应用。在Delphi开发中,实现MD5算法常面临编码问题、性能优化和跨平台兼容性等挑战。本文通过一个经过生产环境验证的纯Pascal实现,详细解析了MD5算法的流式处理机制,并针对字符串编码、大文件处理和线程安全等常见问题提供了实用解决方案,帮助开发者高效集成这一轻量级校验功能。 阅读详情

program Window;

{
   This is an example of making an application
   without using the Forms unit. Forms.pas is the
   Delphi unit that makes your programs so damn
   huge! Forms.pas has all the code for translating
   the forms you create with Delphi w/components
   into windows. If you ask me, anything that adds
   200k(@%#$!) to your app has got to be some damn
   inefficient code.

   GoRDy <gfody@jps.net>
   www.jps.net/gfody
}


uses Windows, Messages;

{$R *.RES}

var
wClass:   TWndClass;  // class struct for main window
hFont,                // handle of font
hInst,                // handle of program (hinstance)
Handle,               // handle of main window
hEncrypt,             // handle of encrypt button
hDecrypt,             // handle of decrypt button
hEdit,                // handle of main edit
hLabel,               // handle of password label
hPW:      HWND;       // handle of password edit
Msg:      TMSG;       // message struct
dEncrypt,
dDecrypt: Pointer;    // default button procedures

(*------------------------------------------------*)

// This lines everything up
procedure Resize;
var
RCT:TRect;
begin
  GetWindowRect(Handle,RCT);
  MoveWindow(hPW,230,5,RCT.Right-RCT.Left-245,24,True);
  MoveWindow(hEdit,5,34,RCT.Right-RCT.Left-20,RCT.Bottom-RCT.Top-66,True);
end;

(*------------------------------------------------*)

// This is to cleanup and stop the program
procedure ShutDown;
begin
  DeleteObject(hFont);
  UnRegisterClass('Sample Class',hInst);
  ExitProcess(hInst); //end program
end;

(*------------------------------------------------*)

// Decrypts the text in hEdit with the text in hPW
procedure Decrypt;
var
x,i,                // count variables
sText,sPW: Integer; // size of Text, PW
Text,PW:   PChar;   // buffer for Text, PW
begin
  sText:=GetWindowTextLength(hEdit)+1;
  sPW:=GetWindowTextLength(hPW)+1;
  GetMem(Text,sText);
  GetMem(PW,sPW);
  GetWindowText(hEdit,Text,sText);
  GetWindowText(hPW,PW,sPW);
  x:=0; // initialize count
  for i:=0 to sText-2 do
  begin
    Text[i]:=Chr(Ord(Text[i])-Ord(PW[x]));
    Inc(x);
    if x=(sPW-1)then x:=0;
  end;
  SetWindowText(hEdit,Text);
  FreeMem(Text);
  FreeMem(PW);
end;

(*------------------------------------------------*)

// Encrypts the text in hEdit with the text in hPW
procedure Encrypt;
var
x,i,                // count variables
sText,sPW: Integer; // size of Text, PW
Text,PW:   PChar;   // buffer for Text, PW
begin
  sText:=GetWindowTextLength(hEdit)+1;
  sPW:=GetWindowTextLength(hPW)+1;
  GetMem(Text,sText);
  GetMem(PW,sPW);
  GetWindowText(hEdit,Text,sText);
  GetWindowText(hPW,PW,sPW);
  x:=0; // initialize count
  for i:=0 to sText-2 do
  begin
    Text[i]:=Chr(Ord(Text[i])+Ord(PW[x]));
    Inc(x);
    if x=(sPW-1)then x:=0;
  end;
  SetWindowText(hEdit,Text);
  FreeMem(Text);
  FreeMem(PW);
end;

(*------------------------------------------------*)

// This function processes every message sent to the Encrypt Button
function EncryptProc(hWnd,Msg,wParam,lParam:Longint):Longint; stdcall;
var
i: Integer;
begin
  // Always pass the message to the Default procedure
  Result:=CallWindowProc(dEncrypt,hWnd,Msg,wParam,lParam);

  case Msg of
  // If the user presses TAB we're gunna switch the
  // focus over to the Decrypt button.
  WM_KEYDOWN: if wParam=9 then SetFocus(hDecrypt);
  end;

end;

(*------------------------------------------------*)

// This function processes every message sent to the Decrypt Button
function DecryptProc(hWnd,Msg,wParam,lParam:Longint):Longint; stdcall;
begin
  // Always pass the message to the Default procedure
  Result:=CallWindowProc(dEncrypt,hWnd,Msg,wParam,lParam);

  case Msg of
  // if the user presses TAB we're gunna switch
  // the focus back to the Encrypt button.
  WM_KEYDOWN: if wParam=9 then SetFocus(hEncrypt);
  end;

end;

(*------------------------------------------------*)

// This function processes every message sent to our Main window
function WindowProc(hWnd,Msg,wParam,lParam:Longint):Longint; stdcall;
begin
  // Always pass the message to the Default procedure
  Result:=DefWindowProc(hWnd,Msg,wParam,lParam);

  case Msg of
  WM_SIZE:    Resize;
  // When buttons are clicked the message is passed to
  // the parent window, so we handle it here.
  WM_COMMAND: if      lParam=hEncrypt then Encrypt
              else if lParam=hDecrypt then Decrypt;
  WM_DESTROY: ShutDown;
  end;

end;

(*------------------------------------------------*)

// This is the main program function (WinMain)
begin

  hInst:=GetModuleHandle(nil); // get the application instance
                               // hInstance returns zilch

  with wClass do
  begin
    Style:=         CS_PARENTDC;
    hIcon:=         LoadIcon(hInst,'MAINICON');
    lpfnWndProc:=   @WindowProc;
    hInstance:=     hInst;
    hbrBackground:= COLOR_BTNFACE+1;
    lpszClassName:= 'Sample Class';
    hCursor:=       LoadCursor(0,IDC_ARROW);
  end;

  // Once our class is registered we
  // can start making windows with it
  RegisterClass(wClass);

  // Create our main window
  Handle:=CreateWindow(
    'Sample Class',          // Registered Class Name
    'Encrypter - By: GoRDy', // Title of Window
    WS_OVERLAPPEDWINDOW or   // Basic Window Style
    WS_VISIBLE,              // Make it Visible
    10,                      // Left
    10,                      // Top
    400,                     // Width
    300,                     // Height
    0,                       // Parent Window Handle
    0,                       // Handle of Menu
    hInst,                   // Application Instance
    nil);                    // Structure for Creation Data

  // Create the Encrypt button
  hEncrypt:=CreateWindow(
    'Button',
    'Encrypt',
    WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,
    5,5,65,24,Handle,0,hInst,nil);

  // Create the Decrypt button
  hDecrypt:=CreateWindow(
    'Button',
    'Decrypt',
    WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,
    75,5,65,24,Handle,0,hInst,nil);

  // Create the main Edit
  hEdit:=CreateWindowEx(
    WS_EX_CLIENTEDGE, // this EX style is for the beveled edge
    'Edit',
    '',
    WS_VISIBLE or WS_CHILD or ES_LEFT or ES_MULTILINE or ES_WANTRETURN or ES_AUTOVSCROLL or WS_VSCROLL,
    5,34,380,234,Handle,0,hInst,nil);

  // Create the password Edit
  hPW:=CreateWindowEx(
    WS_EX_CLIENTEDGE,
    'Edit',
    '',
    WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL or ES_PASSWORD,
    230,5,155,24,Handle,0,hInst,nil);

  hLabel:=CreateWindow(
    'Static',
    'Password:',
    WS_VISIBLE or WS_CHILD or SS_LEFT,
    160,10,70,20,Handle,0,hInst,nil);

  // Create a custom font for our window otherwise
  // everything would use the system font (blech!)
  hFont:=CreateFont(
    -12,                           // Height
    0,                             // Width
    0,                             // Angle of Rotation
    0,                             // Orientation
    0,                             // Weight
    0,                             // Italic
    0,                             // Underline
    0,                             // Strike Out
    DEFAULT_CHARSET,               // Char Set
    OUT_DEFAULT_PRECIS,            // Precision
    CLIP_DEFAULT_PRECIS,           // Clipping
    DEFAULT_QUALITY,               // Render Quality
    DEFAULT_PITCH or FF_DONTCARE,  // Pitch & Family
    'MS Sans Serif');              // Font Name

  // Set the fonts for all our controls
  SendMessage(hEncrypt,WM_SETFONT,hFont,0);
  SendMessage(hDecrypt,WM_SETFONT,hFont,0);
  SendMessage(hEdit,WM_SETFONT,hFont,0);
  SendMessage(hPW,WM_SETFONT,hFont,0);
  SendMessage(hLabel,WM_SETFONT,hFont,0);

  // Subclass Encrypt Button (assign it a custom WindowProc)
  dEncrypt:=Pointer(GetWindowLong(hEncrypt,GWL_WNDPROC));
  SetWindowLong(hEncrypt,GWL_WNDPROC,Longint(@EncryptProc));

  // Subclass Decrypt Button
  dDecrypt:=Pointer(GetWindowLong(hDecrypt,GWL_WNDPROC));
  SetWindowLong(hDecrypt,GWL_WNDPROC,Longint(@DecryptProc));

  // The reason I don't subclass the Edit controls here
  // is because they don't do anything custom. If I wanted
  // them to Beep or something whenever you typed a "G" then
  // I would subclass them.

  // Focus on first control (otherwise people with no mouse are screwed)
  SetFocus(hEncrypt);

  // Now we loop GetMessage to process each Message in
  // our main window's message list. Every time the main
  // window recieves a message its added to the list, so
  // this loop here will eventually process it.

  while(GetMessage(Msg,Handle,0,0))do
  begin
    TranslateMessage(Msg);             // Translate any keyboard Msg's
    DispatchMessage(Msg);              // Send it to our WindowProc
  end;                                 // for processing.

end.

Delphi中Base64编码与解码的实现与应用 在Delphi中,编码单元的API通常非常丰富,使得开发者能够以多种方式处理Base64编码。以下是两个主要API函数的功能描述及其使用示例。线程同步是指在多线程环境中,协调不同线程对共享资源的访问,保证数据的一致性和完整性。Delphi提供了多种线程同步机制,如:- 互斥锁(- 事件(TEvent- 信号量(TSemaphore- 临界区(使用这些同步机制可以有效地控制线程的执行顺序和访问共享资源的时机。 阅读详情

相关推荐

SecureBridge v11.0.1:Delphi 13.1安全通信合规升级指南

TLS/SSL加密是现代网络通信的基础安全能力,其核心在于协议协商、证书验证与密钥交换原理。在Delphi生态中,原生组件长期缺乏对TLS 1.2/1.3及OCSP Stapling等合规特性的内建支持,导致大量遗留系统面临PCI DSS、GDPR审计风险。SecureBridge v11.0.1通过纯Pascal实现的TLS协议栈,提供零DLL依赖、跨平台一致的安全隧道抽象,显著提升HTTPS、SFTP、SMTP等协议的端到端加密可靠性与可审计性。它无缝集成于FireMonkey与VCL项目,尤其适用于医

weixin_30719711的博客 636

DELPHI 自己写的经常用到的加解密函数

以下程序可直接用,拷贝就可以了,希望可以起到抛砖引玉的作用。 function StrDecrypt(s: string; key: word): string; var   i:byte; const   fc1=2;   fc2=3; begin   //result[0]:=s[0];   setlength(result,length(s));   for i:=1

全欣 的专栏 2270

DCPcrypt加密解密库演示及源码分析_Delphi环境

在当今数字化时代,数据安全成为每个开发者都必须面对的课题。DCPcrypt库,一个功能强大的加密解密工具库,为Delphi开发者提供了简便而高效的解决方案。它是专为Delphi和C++ Builder环境设计的开源库,支持各种常见的加密算法,包括但不限于AES、Blowfish、DES和MD5等。本章我们将简要了解DCPcrypt的起源、它在数据安全领域所扮演的角色以及它如何简化和加速开发者的加密解密任务。begin// 将密钥随机化处理try。

weixin_28736145的博客 686

【经验】Delphi字符串加密解密函数

const XorKey: array[0..7] of Byte = ($B2, $09, $BB, $55, $93, $6D, $44, $47); //字符串加密用 function Enc(Str: string): string; //字符加密函數 這是用的一個異或加密 var i, j: Integer; begin Result :=...

慢动作 1286

Delphi7与Java间AES加密技术兼容实现

高级加密标准(AES)是目前广泛使用的对称密钥加密算法之一。AES算法最初是由两位比利时密码学家Joan Daemen和Vincent Rijmen在1998年提出,名为Rijndael。Rijndael加密算法在2000年被选中作为美国联邦政府用于保护电子数据的加密标准,随后在2001年被采纳为美国国家标准与技术研究院(NIST)的高级加密标准(AES)。这项标准迅速被全球广泛接受,并在多个行业中得到了应用。

weixin_32389853的博客 1161

Delphi中DES文本加密模块的实现与应用

信息安全是当今数字世界中的核心议题之一,而加密技术是保护数据免受未经授权访问的基石。在本章节中,我们将介绍DES(Data Encryption Standard)对称加密算法,它是一种广泛采用的技术,尽管在现代加密中不再是最安全的选择,但了解其原理和历史对于理解现代加密技术至关重要。加密是将明文信息转换为密文的过程,这样即使数据被拦截,未经授权的个人也无法读取其内容。解密则是相反的过程,它将密文还原为原始的明文,以便合法用户阅读。

weixin_32102617的博客 942

Delphi 字符串加密和解密函数

泰山老父的Delphi 字符串加密和解密函数 function Encrypt(const InString:string; Salt:string): string; var i : Byte; StartKey, MultKey, AddKey: Word; begin Result := ''; if (Salt = '') then begin Result := InString; end else begin StartKey := Length(S.

Delphi开发局QQ群:32422310 2202

delphi 字符串带密钥简单加密解密

delphi 字符串带密钥简单加密解密,一个完整的演示测试,加密结果串根据密钥变化而变化,加密与解密演示小程序一目了然

Delphi 带KEY字符串加密解密(支持中文)

unit Unit2; interface uses Winapi.Windows, System.SysUtils , AnsiStrings; Function JiaMi(Src:String; Key:String):String; Function JieMi (Src:String; Key:String):String; implementation Function JiaMi(Src:String; Key:String):String; var KeyLen :

yygyyygy1233的博客 2122

delphi 字符串加密 解密小程序

通过delphi 实现对字符串进行加密和解密操作

DELPHI各种字符串加密解密方法

Delphi 各种字符串的加密解密方法,含括2007版本和2012版本的加密解密方法

Mythos模型:AI原生安全与动态推理架构的技术解析

大语言模型正从‘模式识别’迈向‘意图理解’,其核心演进体现在推理架构的范式升级——动态推理编排、意图图谱建模与可信执行闭环成为新一代AI安全能力的基础。Mythos并非参数堆叠产物,而是将符号执行、子代理协同、博弈论仲裁等系统级能力深度嵌入推理流,实现对漏洞利用链的端到端建模与PoC自动生成。这种AI原生安全能力,已推动SAST/IAST工具向‘可验证修复建议生成器’演进,并倒逼企业构建具备小时级响应能力的分布式漏洞操作系统。本文深入剖析Mythos背后的动态推理架构与意图驱动安全范式,揭示其如何重塑Dev

记录技术点点之路 240

WSL2 + Open3D点云可视化踩坑全记录:从GLFW报错到VcXsrv配置,一篇讲清所有‘坑’

本文详细解析了在WSL2环境中使用Open3D进行点云可视化时遇到的常见问题,特别是GLFW报错和VcXsrv配置问题。通过系统性的解决方案和高级配置技巧,帮助开发者彻底解决图形显示、驱动加载和库版本冲突等难题,实现高效的点云可视化。

weixin_30627341的博客 101

基于Delphi实现的AES加解密算法

基于Delphi实现AES加密解密算法。利用密钥KEY对指定内容进行加密并返回Base64或者HEX字符串。keybit分:128 Bit、192 Bit、256 Bit。mode分:ECB、CBC、CFB、OFB。padding分:Zero和PKCS7。返回数据可以为base64或者HEX。

xurunxian的博客 1152

ArcGIS Pro中如何批量替换数据源

不知您是否遇到过下面情况:ArcGIS Pro的Map/Scene中所引用的数据源被移动或重命名了,导致Map/Scene中找不到之前的数据,出现红色叹号;已有一个Map模板文件,图层的样式符号都是设置好的,想批量设置成另外一个数据源,复用该模板文件中的样式符号。 如果您在ArcGIS Pro的使用过程中遇到了上面情况,那么可以参考本篇文章,本文以图层存储在同一GDB中为例介绍。 情况一:Map中已有图层的数据源被移动了 原始Map长这样: 当数据源位置改变之后,显示找不到数据源的红色叹号: 这时如果右

xinying180的博客 7948

Unreal浅做一个MetaBall

Raymaching其实就是实时场景的一种渲染方法。主要原理网上有很多详细介绍。简单来说就是,以摄像机为原点,发射很多条射线,而每一条射线以步长为单位向前采样,同时以采样点和最近的物体像素的距离为半径进行一个球形检测。检测到摄像机和场景像素在当前射线方向的距离差小于某个值,就表示射线到达物体表面,然后画这个像素。

xzljj的博客 335

【函数】简单的加密解密函数

function EncString(Source, Key: string): string; // 对字符串加密(Source:源 Key:密匙) var KeyLen: integer; KeyPos: integer; Offset: integer; Dest: string; SrcPos: integer; SrcAsc: integer; Range: integer; begi...

慢动作 2243

ComfyUI-Impact-Subpack插件安装避坑指南:为什么你的UltralyticsDetectorProvider节点还是找不到?

本文深入解析了ComfyUI-Impact-Subpack插件的安装与排障问题,特别是针对UltralyticsDetectorProvider节点缺失的常见问题提供了详细的解决方案。从底层机制到高阶应用,涵盖了手动安装、模型配置、性能优化等关键步骤,帮助用户彻底解决插件依赖关系断裂问题。

Jerry的专栏 1152

一个使用秘钥加/解密字符串的delphi函数

字符串 秘钥 加密

一葉輕舟的笔记 2666

手眼标定(EyeToHand)推导

Base为基坐标系(B),工具末端坐标系(T),标定板为Mark坐标系(M),相机坐标系(C)对于每两个姿态都存在上式,组成一个AX=XB的矩阵方程,X为。此时转换成AX=0的问题,单纯用SVD求奇异解便可得到。相机坐标系到Base基坐标系下的转换关系。已知标定板与机械臂末端的相对位置固定不变,,即。带入(2)式求,至此求解出需要的手眼矩阵。在眼在手外的时候,其实是要求解。

stevenreally6的博客 1143

Windows下MMdetection3D保姆级安装指南(含CUDA和PyTorch版本避坑)

本文提供Windows平台下MMdetection3D的完整安装指南,重点解决CUDA与PyTorch版本匹配问题。从环境准备到关键组件安装,详细介绍了CUDA Toolkit选择策略、PyTorch精准安装步骤,以及MM系列组件的安装顺序和常见错误解决方案,帮助用户顺利完成3D目标检测环境的配置。

weixin_42628941的博客 491

DELPHI加密字串(异或运算加密)

首先有两个自定的转换函数: function myStrToHex(s:string):string; //字串转16进制 var TmpStr:string; i:integer; begin TmpStr:=''; for i:=1 to Length(s)do TmpStr:=TmpStr+IntToHex(ord(s

靠别人不如靠自已。 9903

FLACS-CFD 气云爆炸模拟全流程工况构建指南:从泄漏到爆炸

摘要: 本文详细介绍了使用FLACS-CFD模拟气云爆炸的全流程构建方法,重点解决泄漏模拟到爆炸模拟的气云文件传递问题。核心步骤包括: 项目规划:明确泄漏源(甲烷管道腐蚀泄漏)和爆炸场景,建立标准目录结构; 网格设计:泄漏与爆炸模拟需采用兼容的网格,爆炸域应为泄漏域的子区域且网格划分一致; 泄漏模拟配置:通过.inp文件定义几何、网格、风场、燃料及泄漏源参数,确保输出爆炸所需的气云文件(*.uni/*.fla); 关键设置:统一燃料名称、时间点匹配、路径正确性,避免版本兼容性问题。

huanghm88的专栏 764
上一篇: IE 链接打不开
下一篇: Pascal的指针
Open2ye
博客等级 码龄23年 6粉丝 50原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值