// bxnmfcDlg.cpp : implementation file
//
#include "stdafx.h"
#include "bxnmfc.h"
#include "bxnmfcDlg.h"
#include "aes.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBxnmfcDlg dialog
CBxnmfcDlg::CBxnmfcDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBxnmfcDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBxnmfcDlg)
strme = _T("");
strming = _T("");
m_key = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CBxnmfcDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBxnmfcDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_prog);
DDX_Text(pDX, IDC_EDIT_ME, m_me);
DDX_Text(pDX, IDC_EIDT_MING, m_ming);
DDX_Text(pDX, IDC_EDIT_KEY, m_key);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBxnmfcDlg, CDialog)
//{{AFX_MSG_MAP(CBxnmfcDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_DE, OnDe)
ON_BN_CLICKED(IDC_EN, OnEn)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_ASSIC, OnAssic)
ON_BN_CLICKED(IDC_HEX, OnHex)
ON_BN_CLICKED(IDC_4, On4)
ON_BN_CLICKED(IDC_6, On6)
ON_BN_CLICKED(IDC_8, On8)
ON_BN_CLICKED(IDC_long, Onlong)
ON_BN_CLICKED(IDC_cut, Oncut)
ON_BN_CLICKED(IDC_ECB, OnEcb)
ON_BN_CLICKED(IDC_CBC, OnCbc)
ON_BN_CLICKED(IDC_CFB, OnCfb)
ON_BN_CLICKED(IDC_OFB, OnOfb)
ON_BN_CLICKED(IDC_CTR, OnCtr)
ON_BN_CLICKED(IDC_clear, Onclear)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_STRING, OnString)
ON_BN_CLICKED(IDC_FILE, OnFile)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_STATIC_BXN, OnStaticBxn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBxnmfcDlg message handlers
BOOL CBxnmfcDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_prog.SetPos(0);
CheckRadioButton(IDC_EN,IDC_DE,IDC_EN);
CheckRadioButton(IDC_ASSIC,IDC_HEX,IDC_ASSIC);
CheckRadioButton(IDC_4,IDC_8,IDC_4);
CheckRadioButton(IDC_long,IDC_cut,IDC_cut);
CheckRadioButton(IDC_ECB,IDC_CTR,IDC_ECB);
CheckRadioButton(IDC_STRING,IDC_FILE,IDC_STRING);
int i=0,j=0;
for(i=0;i<4;i++)
for(j=0;j<8;j++){
key[i][j]=0;
}
for(i=0;i<4;i++)
for(j=0;j<4;j++){
me[i][j]=0;
ming[i][j]=0;
}
for(i=0;i<50;i++)
for(j=0;j<4;j++){
buf[i][j]=0;
}
flag=0;
flag_hexorassic=0;
keysize=4;
cutorlong=0;
mode=1;
minglen=0;
melen=0;
flag_strorfile=0;
CEdit *pedit=(CEdit *)GetDlgItem(IDC_EDIT_ME);
pedit->SetReadOnly();
CButton *pbutton;
pbutton=(CButton *)GetDlgItem(IDC_ECB);
pbutton->EnableWindow(false);
pbutton=(CButton *)GetDlgItem(IDC_CBC);
pbutton->EnableWindow(false);
pbutton=(CButton *)GetDlgItem(IDC_CFB);
pbutton->EnableWindow(false);
pbutton=(CButton *)GetDlgItem(IDC_OFB);
pbutton->EnableWindow(false);
pbutton=(CButton *)GetDlgItem(IDC_CTR);
pbutton->EnableWindow(false);
pbutton=(CButton *)GetDlgItem(IDC_BUTTON3);
pbutton->EnableWindow(false);
pbutton=(CButton *)GetDlgItem(IDC_BUTTON4);
pbutton->EnableWindow(false);
return TRUE; // return TRUE unless you set the focus to a control
}
void CBxnmfcDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CBxnmfcDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CBxnmfcDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CBxnmfcDlg::OnDe()
{
// TODO: Add your control notification handler code here
flag=1;
CEdit *pedit=(CEdit *)GetDlgItem(IDC_EDIT2);
pedit->SetReadOnly();
//pdeit
pedit=(CEdit *)GetDlgItem(IDC_EDIT_ME);
pedit->SetReadOnly(FALSE);
CButton *pbutton;
if(flag_strorfile==1){
pbutton=(CButton *)GetDlgItem(IDC_BUTTON4);
pbutton->EnableWindow(true);
pbutton=(CButton *)GetDlgItem(IDC_BUTTON3);
pbutton->EnableWindow(false);
}
//strming="";
//melen=0;
//UpdateData(false);
}
void CBxnmfcDlg::OnEn()
{
// TODO: Add your control notification handler code here
//CStatic *pstatic=(CStatic *)GetDlgItem(IDC_plain_cipher_text);
//pstatic->SetWindowText("plaintext");
flag=0;
CEdit *pedit=(CEdit *)GetDlgItem(IDC_EDIT_ME);
pedit->SetReadOnly();
pedit=(CEdit *)GetDlgItem(IDC_EIDT_MING);
pedit->SetReadOnly(false);
CButton *pbutton;
if(flag_strorfile==1){
pbutton=(CButton *)GetDlgItem(IDC_BUTTON3);
pbutton->EnableWindow(true);
pbutton=(CButton *)GetDlgItem(IDC_BUTTON4);
pbutton->EnableWindow(false);
}
//strme="";
//minglen=0;
//UpdateData(false);
}
void CBxnmfcDlg::OnButton1()
{
clear();
UpdateData(true);
strming=m_ming;strme=m_me;
enfilepath=m_ming;defilepath=m_me;
strming.TrimLeft();strme.TrimLeft();
strming.TrimRight();strme.TrimRight();
m_key.TrimLeft();m_key.TrimRight();
if(m_key.GetLength()==0){MessageBox("input keys!!");return;}
readkey();
AES.initial(keysize,key);
if(flag_strorfile==0){
if(cutorlong==0){
if(flag==0){
if(strming.GetLength()==0){MessageBox("input plain texts!!");return;}
string2char44(strming,ming);
AES.jiami(ming,me);
strme=char442string(me);