【管他正版盗版的】Woo咚加密算法程序 Pascal版
本Pascal版使用Delphi2009编译,因此对Unicode支持是很不错的,能够支持非英文字符的加密。
原算法参见 http://poketb.com/woodu/2010/04/04/789-published-the-answer/comment-page-1/
程序是在使用Unicode的前提下写的,若使用不支持Unicode的编译器重新编译可能导致对非英文字符的识别产生错误,所以慎重。
还有,我都不知道该怎么说了
目前没发现不兼容VB版的地方
坐等W挑刺
Delphi 2009+Windows 7 Ultimate下通过
代码附上
unit UnitMain;
interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, StrUtils, Math, ComCtrls;
type
TfrmMain = class(TForm)
btnConvert: TButton;
btnSolve: TButton;
txtOriginal: TRichEdit;
txtOutput: TRichEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
txtFrom: TEdit;
txtTo: TEdit;
Label4: TLabel;
procedure btnConvertClick(Sender: TObject);
function GetCipherText(ClearText: string): string;
function GetClearText(CipherText: string): string;
procedure btnSolveClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
LoopFrom, LoopTo: integer;//自定义字母循环计数的始终
implementation
{$R *.dfm}
procedure TfrmMain.btnConvertClick(Sender: TObject);
begin
LoopFrom:=StrToInt(txtFrom.Text);LoopTo:=StrToInt(txtTo.Text);
txtOutput.Text:=GetCipherText(txtOriginal.Text);
end;
procedure TfrmMain.btnSolveClick(Sender: TObject);
begin
LoopFrom:=StrToInt(txtFrom.Text);LoopTo:=StrToInt(txtTo.Text);
txtOriginal.Text:=GetClearText(txtOutput.Text);
end;
function TfrmMain.GetCipherText(ClearText: string): string;
var
CharBuffer: WideChar;
ASCIIBuffer, SingleNum, LetterLoop: integer;
i, j, ClearTextLength, ASCIILength: integer;
ResultBuffer: string;
begin
LetterLoop:=LoopFrom;
ClearTextLength:=Length(ClearText);
for i := 1 to ClearTextLength do
begin
CharBuffer:=ClearText[i];//读取出来一个字符
ASCIIBuffer:=Ord(CharBuffer);//获得ASCII码
ASCIILength:=Length(IntToStr(ASCIIBuffer))-1;//获得ASCII码位数-1
for j := ASCIILength downto 0 do
begin
SingleNum:=ASCIIBuffer div Trunc(IntPower(10,j));//取出最高位数字
Randomize;//初始化随机数生成器
if LetterLoop<SingleNum then//构造数字的算式
ResultBuffer:=ResultBuffer+Char(Random(4)+65)+'+'+IntToStr(SingleNum-LetterLoop)
else if LetterLoop>SingleNum then
ResultBuffer:=ResultBuffer+Char(Random(4)+65)+'-'+IntToStr(LetterLoop-SingleNum)
else ResultBuffer:=ResultBuffer+Char(Random(4)+65);
Inc(LetterLoop);//自增
if LetterLoop>LoopTo then LetterLoop:=LoopFrom;//自增过界则循环回去
ASCIIBuffer:=ASCIIBuffer mod Trunc(IntPower(10,j));//去掉最高位
end;
if i<>ClearTextLength then
ResultBuffer:=ResultBuffer+',';//不是最后一个数字则添加逗号
end;
GetCipherText:=ResultBuffer;
end;
function TfrmMain.GetClearText(CipherText: string): string;
var
i, NumLoop, NumBuffer, CipherLength, ASCIIBuffer, Skip, SingleNum: integer;
ResultBuffer: string;
begin
NumLoop:=LoopFrom;
ASCIIBuffer:=0;
SingleNum:=0;
CipherText:=CipherText+',';//在最后强制添加逗号,方便判断结束
CipherLength:=Length(CipherText);
for i := 1 to CipherLength do
begin
case CipherText[i] of
'A'..'D':
begin
NumBuffer:=NumLoop; Inc(NumLoop);
if ((CipherText[i+1]>='A') and (CipherText[i+1]<='D')) or (CipherText[i+1]=',') then
ASCIIBuffer:=ASCIIBuffer*10+NumBuffer;//如果某个字母后面也为字母或者逗号,那么这个字母代表的数字就是ASCII码的其中一位
end;
'+': Skip:=1;
'-': Skip:=2;//记录运算符
'0'..'9':
begin
SingleNum:=SingleNum*10+StrToInt(CipherText[i]);//处理多位数字的情况
if not((CipherText[i+1]>='0') and (CipherText[i+1]<='9')) then//如果一个数字后面不再是数字,那么这个数字已经读取完毕,可以开始计算
begin
if Skip=1 then NumBuffer:=NumBuffer+SingleNum
else if Skip=2 then NumBuffer:=NumBuffer-SingleNum;
ASCIIBuffer:=ASCIIBuffer*10+NumBuffer;
SingleNum:=0;
end;
end;
',':
begin
ResultBuffer:=ResultBuffer+Char(ASCIIBuffer);//读到逗号,则一个字符已经读取完毕,保存至输出
ASCIIBuffer:=0;
end;
end;
if NumLoop>LoopTo then NumLoop:=LoopFrom;//自增过界则循环回去
end;
GetClearText:=ResultBuffer;
end;
end.
然后是窗体
object frmMain: TfrmMain
Left = 0
Top = 0
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle
Caption = 'Woo'#21658#21152#23494' Algorithm-Woodu Program-Roy'
ClientHeight = 296
ClientWidth = 400
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poOwnerFormCenter
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 8
Top = 8
Width = 76
Height = 13
Caption = #26126#25991#36755#20837'/'#36755#20986
end
object Label2: TLabel
Left = 8
Top = 160
Width = 76
Height = 13
Caption = #23494#25991#36755#20837'/'#36755#20986
end
object Label3: TLabel
Left = 160
Top = 136
Width = 84
Height = 13
Caption = #23383#27597#35745#25968#24490#29615#65306
end
object Label4: TLabel
Left = 192
Top = 152
Width = 12
Height = 13
Caption = #33267
end
object btnConvert: TButton
Left = 48
Top = 136
Width = 89
Height = 25
Caption = #23601#26159#36825#26679#21941
TabOrder = 3
OnClick = btnConvertClick
end
object btnSolve: TButton
Left = 264
Top = 136
Width = 89
Height = 25
Caption = #26159#36825#26679#30340#21941
TabOrder = 5
OnClick = btnSolveClick
end
object txtOriginal: TRichEdit
Left = 8
Top = 24
Width = 385
Height = 105
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
HideScrollBars = False
ParentFont = False
ScrollBars = ssVertical
TabOrder = 0
end
object txtOutput: TRichEdit
Left = 7
Top = 176
Width = 385
Height = 113
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
HideScrollBars = False
ParentFont = False
ScrollBars = ssVertical
TabOrder = 4
end
object txtFrom: TEdit
Left = 160
Top = 152
Width = 25
Height = 21
TabOrder = 1
Text = '1'
end
object txtTo: TEdit
Left = 216
Top = 152
Width = 25
Height = 21
TabOrder = 2
Text = '10'
end
end
[[i] 本帖最后由 roywillow 于 2010-4-9 08:53 编辑 [/i]]
附件: 您所在的用户组无法下载或查看附件