[我就认准第二代了][我就闲的X疼了]Woo咚加密第二代C++ Builder版
无责任飘过扔Woo咚加密第二代C++ Builder版。运行效率感觉没Delphi的高,当然还是比VB的高很多……
UnitMain.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "UnitMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmMain *frmMain;
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
}
UnicodeString GetCipherText(UnicodeString ClearText, int LoopFrom, int LoopTo)
{
int i, j, ClearTextLength, ASCIILength, NumLoop;
UnicodeString ResultBuffer, ASCIIBuffer;
ClearTextLength = ClearText.Length();
ResultBuffer = "";
NumLoop = LoopFrom;
for (i = 1; i <= ClearTextLength; i++)
{
ASCIIBuffer = IntToStr(ClearText[i]);
ASCIILength = ASCIIBuffer.Length();
for (j = 1; j <= ASCIILength; j++, NumLoop++)
{
if (NumLoop > LoopTo) NumLoop = LoopFrom;
Randomize();
if (ASCIIBuffer[j] - '0' > NumLoop)
ResultBuffer = ResultBuffer + char(Random(4)+65) + '+' + IntToStr(ASCIIBuffer[j] -'0' - NumLoop);
else
if (ASCIIBuffer[j] - '0' < NumLoop)
ResultBuffer = ResultBuffer + char(Random(4)+65) + '-' + IntToStr(NumLoop - ASCIIBuffer[j] + '0');
else
ResultBuffer += char(Random(4)+65);
}
if (i != ClearTextLength) ResultBuffer += ',';
}
return (ResultBuffer);
}
UnicodeString GetClearText(UnicodeString CipherText, int LoopFrom, int LoopTo)
{
int i, NumLoop, CipherTextLength, Operator = 0, ASCIIBuffer = 0, SingleNum = 0;
UnicodeString ResultBuffer;
CipherText +=',';
NumLoop = LoopFrom;
CipherTextLength = CipherText.Length();
for (i = 1; i <= CipherTextLength; i++)
{
if (NumLoop > LoopTo) NumLoop = LoopFrom;
switch (CipherText[i])
{
case 'A': case 'B': case 'C': case 'D':
if ((CipherText[i+1] >= 'A' && CipherText[i+1] <= 'D') || (CipherText[i+1]==','))
{
ASCIIBuffer = ASCIIBuffer * 10 + NumLoop;
NumLoop++;
}
break;
case '+': Operator = 1; break;
case '-': Operator = 2; break;
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
SingleNum = SingleNum * 10 + (CipherText[i] - '0');
if (CipherText[i+1] < '0' || CipherText[i+1] > '9')
{
if (Operator == 1) ASCIIBuffer = ASCIIBuffer * 10 + NumLoop + SingleNum;
else if (Operator == 2) ASCIIBuffer = ASCIIBuffer * 10 + NumLoop - SingleNum;
NumLoop++;
SingleNum = 0;
}
break;
case ',':
ResultBuffer += wchar_t(ASCIIBuffer);
ASCIIBuffer = 0;
break;
default:
return (Format("未知字符 “%s” 于第 %d 个字符", ARRAYOFCONST((CipherText[i], i))));
}
}
return (ResultBuffer);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnToCipherClick(TObject *Sender)
{
txtCipher->Text = GetCipherText(txtClear->Text, StrToInt(txtLoopFrom->Text), StrToInt(txtLoopTo->Text));
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnToClearClick(TObject *Sender)
{
txtClear->Text = GetClearText(txtCipher->Text, StrToInt(txtLoopFrom->Text), StrToInt(txtLoopTo->Text));
}
//---------------------------------------------------------------------------
UnitMain.dfm
object frmMain: TfrmMain
Left = 0
Top = 0
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle
Caption = 'Woo'#21658#21152#23494' C++ Builder'#29256
ClientHeight = 312
ClientWidth = 400
Color = clBtnFace
ParentFont = True
OldCreateOrder = False
Position = poOwnerFormCenter
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 16
Top = 8
Width = 88
Height = 13
Caption = #26126#25991#36755#20837'/'#36755#20986#65306
end
object Label2: TLabel
Left = 8
Top = 168
Width = 88
Height = 13
Caption = #23494#25991#36755#20837'/'#36755#20986#65306
end
object Label3: TLabel
Left = 160
Top = 144
Width = 84
Height = 13
Caption = #23383#27597#35745#25968#24490#29615#65306
end
object Label4: TLabel
Left = 192
Top = 160
Width = 12
Height = 13
Caption = #33267
end
object txtClear: TRichEdit
Left = 8
Top = 24
Width = 385
Height = 113
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
ParentFont = False
ScrollBars = ssVertical
TabOrder = 0
end
object txtCipher: TRichEdit
Left = 7
Top = 184
Width = 385
Height = 121
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
ParentFont = False
ScrollBars = ssVertical
TabOrder = 1
WantReturns = False
end
object btnToCipher: TButton
Left = 32
Top = 144
Width = 81
Height = 25
Caption = #21152#30721
TabOrder = 2
OnClick = btnToCipherClick
end
object btnToClear: TButton
Left = 288
Top = 144
Width = 81
Height = 25
Caption = #21435#30721
TabOrder = 3
OnClick = btnToClearClick
end
object txtLoopFrom: TEdit
Left = 160
Top = 160
Width = 25
Height = 21
TabOrder = 4
Text = '1'
end
object txtLoopTo: TEdit
Left = 216
Top = 160
Width = 25
Height = 21
TabOrder = 5
Text = '10'
end
end
UnitMain.h
//---------------------------------------------------------------------------
#ifndef UnitMainH
#define UnitMainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class TfrmMain : public TForm
{
__published: // IDE-managed Components
TRichEdit *txtClear;
TRichEdit *txtCipher;
TButton *btnToCipher;
TButton *btnToClear;
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TEdit *txtLoopFrom;
TEdit *txtLoopTo;
TLabel *Label4;
void __fastcall btnToCipherClick(TObject *Sender);
void __fastcall btnToClearClick(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TfrmMain(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TfrmMain *frmMain;
//---------------------------------------------------------------------------
#endif
本程序在 C++ Builder 2009 + Windows 7 Ultimate下编译通过
[[i] 本帖最后由 roywillow 于 2010-5-16 21:40 编辑 [/i]]