MFC的一个程序,求帮忙。
刚刚接触C++,一直调试有错误,可能语法逻辑有问题,但是找不出来,求帮忙解答,感谢。
visual studio 2010默认建的MFC aplication,*.h 和 *.cpp 文件附下
=======================================================
// geffeDlg.h : header file
#pragma once
// CgeffeDlg dialog
class CgeffeDlg : public CDialogEx
{
// Construction
public:
CgeffeDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
enum { IDD = IDD_GEFFE_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
CString m_IN;
CString m_OUT;
afx_msg void OnBnClickedButton();
afx_msg void OnEnChangeEditIn();
afx_msg void OnEnChangeEditOut();
};
//int main(int argc, char* argv[]);
unsigned char buf[1000],buf1[1000],buf2[1000],b[10000],c[1000];
void cypt(unsigned char b[]);
void Geffe(unsigned char buf[],unsigned char buf1[],unsigned char buf2[],unsigned char b[]);
void output_binary(unsigned char c);
void lfsr_output_byte(int n,unsigned char c,unsigned char init_state,unsigned char output_bytes[],int byte_length);
unsigned char fn_feedback( unsigned char n,unsigned char c,unsigned char curr_state);
=====================================================================================
// geffeDlg.cpp : implementation file
//
#include "stdafx.h"
#include <iostream>
#include "geffe.h"
#include "geffeDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
using namespace std;
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CgeffeDlg dialog
CgeffeDlg::CgeffeDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CgeffeDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_IN = _T("");
m_OUT = _T("");
}
void CgeffeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_IN, m_IN);
DDX_Text(pDX, IDC_EDIT_OUT, m_OUT);
}
BEGIN_MESSAGE_MAP(CgeffeDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON, &CgeffeDlg::OnBnClickedButton)
ON_EN_CHANGE(IDC_EDIT_IN, &CgeffeDlg::OnEnChangeEditIn)
ON_EN_CHANGE(IDC_EDIT_OUT, &CgeffeDlg::OnEnChangeEditOut)
END_MESSAGE_MAP()
// CgeffeDlg message handlers
BOOL CgeffeDlg::OnInitDialog()
{
CDialogEx::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)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
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
return TRUE; // return TRUE unless you set the focus to a control
}
void CgeffeDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::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 CgeffeDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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
{
CDialogEx::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CgeffeDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CgeffeDlg::OnBnClickedButton()
{
UpdateData(true);
lfsr_output_byte(5,(unsigned char)144,(unsigned char)152, buf, 100);
lfsr_output_byte(5,(unsigned char)44,(unsigned char)152, buf1, 100);
lfsr_output_byte(5,(unsigned char)24,(unsigned char)152, buf2, 100);
Geffe(buf,buf1,buf2,b);
cypt(b);
//system("pause");
return;
UpdateData(false);
}
//return next state 反馈
unsigned char fn_feedback( unsigned char n,unsigned char c,unsigned char curr_state)
{
unsigned char t = c & curr_state;
unsigned char s = t & (unsigned char)128;//get first bit
for(int i =1; i< n; i++)
{
s = s ^ ( (t << i) & (unsigned char)128 );
}
return (unsigned char)((curr_state << 1) | (s >> (n-1))); //return next state
}
//产生LFSR序列
void lfsr_output_byte(int n,unsigned char c,unsigned char init_state,unsigned char output_bytes[],int byte_length)
{
unsigned char next_state = init_state;
for(int i = 0; i < byte_length; i++)
{
unsigned char temp = (unsigned char)0;
for(int j=0; j< 8; j++)
{
temp = temp | ( (next_state & (unsigned char)128) >> j );
next_state = fn_feedback(n, c, next_state);
}
output_bytes[i] = temp;
}
}
//geffe生成器
void Geffe(unsigned char buf[],unsigned char buf1[],unsigned char buf2[],unsigned char b[])
{
for(int i=0; i< 10; i++)
{
b[i]=buf[i]*buf1[i]+buf2[i]*buf1[i]+buf2[i];
output_binary( (unsigned char)b[i]);
}
}
//加密解密函数
void cypt(unsigned char b[])
{
unsigned char m_IN[1000],m_OUT[1000];
int j;
for(j=0;m_IN[j]!='\0';j++)
{
m_OUT[j]=m_IN[j]^b[j];
cout<<m_OUT[j];
}
// for(int k=0;k<j;k++)
// {
// m_IN[k]=m_OUT[k]^b[k];
// }
}