Delphi字符串隐藏一法

通过使用char数组来实现字符串隐藏;
具体请看示例代码:
代码:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  t:array[1..14] of char;     //用数组来实现隐藏
begin
  t[1]:=Char(103);
  t[2]:=Char(111);
  t[3]:=Char(111);
  t[4]:=Char(100);
  t[5]:=Char(32);
  t[6]:=Char(106);
  t[7]:=Char(111);
  t[8]:=Char(98);
  t[9]:=Char(44);
  t[10]:=Char(32);
  t[11]:=Char(109);
  t[12]:=Char(97);
  t[13]:=Char(110);
  t[14]:=Char(33);
  Showmessage(t);               //英文的“good job, man!”
end;


procedure TForm1.Button2Click(Sender: TObject);
var
  t:array[1..20] of char;          //用数组来实现隐藏
begin
  t[1]:=Char(185);
  t[2]:=Char(167);
  t[3]:=Char(207);
  t[4]:=Char(178);
  t[5]:=Char(196);
  t[6]:=Char(227);
  t[7]:=Char(163);
  t[8]:=Char(172);
  t[9]:=Char(215);
  t[10]:=Char(162);
  t[11]:=Char(178);
  t[12]:=Char(225);
  t[13]:=Char(179);
  t[14]:=Char(201);
  t[15]:=Char(185);
  t[16]:=Char(166);
  t[17]:=Char(193);
  t[18]:=Char(203);
  t[19]:=Char(163);
  t[20]:=Char(161);
  Showmessage(t);                     //中文的“恭喜你,注册成功了!”
end;


end.
有人会觉得这样写代码很累,没关系,这里有批量生成上面结果的代码,我正用之...
且上面代码均为其生成之...
edit1.text输入你的提示字符串,edit2.text输入为你预定义的变量名,默认为't'...
点击即可生成像上面的代码,保存在ByTeCrypt.txt,直接copy使用之...
代码:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    GroupBox1: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
    wFile:TextFile;
    wFileName,s,t:String;
    i:Integer;

begin
    s:=Edit1.Text;
    t:=Edit2.Text;
    if length(s)=0 then
        begin
           showmessage('Please input your string');
           exit;
        end;
    if length(t)=0 then
        begin
           showmessage('请输入变量名');
           exit;
        end;
    t:=Edit2.Text;
    wFileName:= 'ByTeCrypt.txt';
    AssignFile(wFile, wFileName);
    Rewrite(wFile);

    Writeln(wFile,'var');
    Writeln(wFile,'  '+t+':array[1..'+IntToStr(Length(s))+'] of char;');                  //生成定义t:array[1..?] of char
    Writeln(wFile,'begin');
    for i:=1 to Length(s) do
       begin
          Writeln(wFile, '  '+t+'['+IntToStr(i)+']:=Char('+IntToStr(Ord(s[i]))+');');     //生成语句t[?]:=Char(?);
       end;
    Writeln(wFile,'  Showmessage('+t+');');
    Writeln(wFile,'end;');
    CloseFile(wFile);
    showmessage('执行完毕,请查看同目录下ByTeCrypt.txt文件!');

end;

end.
posted @ 2009-03-09 23:40  iAdo  阅读(413)  评论(0编辑  收藏  举报