标题: 【管他正版盗版的】Woo咚加密算法程序 Pascal版 [打印本页]
作者: roywillow 时间: 2010-4-7 22:30 标题: 【管他正版盗版的】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下通过
[attach]27024[/attach]
[attach]26995[/attach]
代码附上
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]]
作者: 最美我中文 时间: 2010-4-7 23:01
胡扯。加密Woodu上来就来个+8+6
你看看应该是+7+5还是+8+6。
上色&完整完美染色版请访问这个传送门:
http://poketb.com/woodu/2010/04/04/789-published-the-answer/
我表示这才是正版。复制内容到剪贴板
代码:
program project1;
var
isss,xsk,tmpnum,i,x,tmpint,errorcoden,tmpnum22:integer;
tmpstr2,tmpstr:char;
inputtext:array of char;
mystr,outputstring,linshistr,tmpstring,mytempstr1,mytempstr2,mytmpstr33,inputmystring:string;
begin
mystr:='';
xsk:=0;
tmpstr:=chr(0);
tmpnum:=0;
i:=0;
x:=0;
isss:=1;
readln(inputmystring);
setlength(inputtext,length(inputmystring));
for i:=1 to length(inputmystring) do inputtext[i]:=inputmystring[i];
i:=0;
outputstring:='';
for i:=1 to High(inputtext)+1 do begin
tmpstr:=inputtext[i];
tmpnum:=ord(tmpstr);
str(tmpnum,mytempstr1);
for x:=1 to LENGTH(mytempstr1) do
begin
xsk:=random(3) + 1;
mystr:=chr(64+xsk);
str(tmpnum,tmpstring);
tmpstr2:=tmpstring[x];
if (ord(tmpstr2)>=48) and (ord(tmpstr2)<=57) then
begin //tmpint VAL(字符串,数字,错误代码)
val(tmpstr2,tmpint,errorcoden);
tmpnum22:=tmpint-isss;
str(tmpnum22,mytmpstr33);
if tmpint>isss
then
outputstring:=outputstring + mystr + '+' + mytmpstr33
else
if tmpint<isss
then
outputstring:=outputstring+mystr+mytmpstr33
else
if tmpint=isss
then
outputstring:=outputstring+mystr;
end;
isss:=isss+1;
if isss>=11 then isss:=1;
end;
if i<> LENGTH(inputtext) then outputstring:=outputstring+',';
end;
writeln(outputstring);
readln;
end.
此程序在Lazarus for noi 0.9.28.2 beta @ Windows7下调试通过。
[ 本帖最后由 最美我中文 于 2010-4-7 23:23 编辑 ]
作者: roywillow 时间: 2010-4-8 16:25
我没说我是完全按照你的算法来的啊……
为了解密方便我是按照0到9的顺序编号
而你是按照1到10
这不就正好了么……
我在上面说明了啊……
我用插入排序排序字符串然后你就说那不是插入排序?
我把一段明文加密两次然后那个就不是你的加密算法?
[ 本帖最后由 roywillow 于 2010-4-8 16:44 编辑 ]
作者: 最美我中文 时间: 2010-4-9 11:57
路过with smilence
作者: roywillow 时间: 2010-4-9 13:21
我承认想看懂您的代码我需要更多的注释……
作者: 最美我中文 时间: 2010-4-9 15:55
可以不用split,多个if而已。
作者: roywillow 时间: 2010-4-9 18:46
总之殊途同归,做不是很大量的运算的时候效率应该不会差很多
况且效率怎么计算……
欢迎光临 口袋社区-Poke The BBS (https://ww.poketb.com/) |
Powered by Discuz! 6.1.0F |