⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysboxdlg.cpp

📁 s盒的加密解密算法
💻 CPP
字号:
// MySBoxDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MySBox.h"
#include "MySBoxDlg.h"
#include "iostream.h"
#include "fstream.h"
#include "stdlib.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()

/////////////////////////////////////////////////////////////////////////////
// CMySBoxDlg dialog

CMySBoxDlg::CMySBoxDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMySBoxDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMySBoxDlg)
	m_fenum = _T("");
	m_midnum = _T("");
	m_six01 = _T("");
	m_midnum10 = _T("");
	m_fenum10 = _T("");
	m_insteadnum = _T("");
	m_output = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

void CMySBoxDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMySBoxDlg)
	DDX_Text(pDX, IDC_FENUM, m_fenum);
	DDX_Text(pDX, IDC_MIDNUM, m_midnum);
	DDX_Text(pDX, IDC_SIX01, m_six01);
	DDX_Text(pDX, IDC_MIDNUM10, m_midnum10);
	DDX_Text(pDX, IDC_FENUM10, m_fenum10);
	DDX_Text(pDX, IDC_INSTEAD, m_insteadnum);
	DDX_Text(pDX, IDC_OUTPUT, m_output);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMySBoxDlg, CDialog)
	//{{AFX_MSG_MAP(CMySBoxDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDABOUT, OnAbout)
	ON_BN_CLICKED(IDEXIT, OnExit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMySBoxDlg message handlers

BOOL CMySBoxDlg::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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMySBoxDlg::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 CMySBoxDlg::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 CMySBoxDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMySBoxDlg::OnOK() 
{
	// TODO: Add extra validation here
	    UpdateData(true);
		 for(int ii=0;ii<m_six01.GetLength();ii++)
		 {
			 if(m_six01.GetAt(ii)!='0'&&m_six01.GetAt(ii)!='1')
			 {
				 MessageBox("请输入0、1数字!");
				 return;
				 break;
			 }
		 }
	if(m_six01.GetLength()!=6)
		{
		MessageBox("请输入六位二进制0、1数!");
		return;
		}
	else
		{
			int m_length,fenum,midnum;
			int m_six[6];
			char m_six0[2],m_six1[2],m_six2[2],m_six3[2],m_six4[2],m_six5[2];
			//把每个0或者1赋给各自的数组变量
			m_six0[0]=m_six01.GetAt(0);	
			m_six1[0]=m_six01.GetAt(1);	
			m_six2[0]=m_six01.GetAt(2);	
			m_six3[0]=m_six01.GetAt(3);	
			m_six4[0]=m_six01.GetAt(4);	
			m_six5[0]=m_six01.GetAt(5);	
			///将每个数组里的字符转换成INT类型的变量
			m_six[0]=atoi(m_six0);
			m_six[1]=atoi(m_six1);
			m_six[2]=atoi(m_six2);
			m_six[3]=atoi(m_six3);
			m_six[4]=atoi(m_six4);
			m_six[5]=atoi(m_six5);
			//
			m_fenum=m_six0[0];
			m_fenum+=m_six5[0];
			m_midnum=m_six1[0];
			m_midnum+=m_six2[0];
			m_midnum+=m_six3[0];
			m_midnum+=m_six4[0];
			//计算行和列
			fenum = m_six[0]*2+m_six[5];
	    	midnum = int(m_six[1])*8+int(m_six[2])*4+int(m_six[3])*2+int(m_six[4]);
			char aaa[4];
			char bbb[4];
			_itoa(fenum,aaa,10);
			m_fenum10 =aaa;
			_itoa(midnum,bbb,10);
			m_midnum10 =bbb;
			//从文件中读数字
			char mtext[34];
			ifstream sfile("xp.txt");
			for(int i=0; i<fenum+1; i++)
			{
				sfile.getline(mtext,34);
			}
			//取得要代替的数字
			m_insteadnum=mtext[(2*midnum)];
			m_insteadnum=m_insteadnum+mtext[(2*midnum+1)];
			int tend;
			tend = atoi(m_insteadnum);
			char ccc[4];
			_itoa(tend,ccc,2);
			m_output = ccc;
			if(m_output.GetLength()!=4)
			{
				for(;m_output.GetLength()<4;)
				{
					m_output = "0"+m_output;
				}
			}
			UpdateData(false);
			MessageBox("要用二进制数替代的S中的数字是:"+m_insteadnum);
		}
}

void CMySBoxDlg::OnAbout() 
{
	// TODO: Add your control notification handler code here
	CAboutDlg about;
	about.DoModal();
}

void CMySBoxDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	MessageBox("Thank you sir see you next time!");
	CDialog::OnCancel();
}

void CMySBoxDlg::OnExit() 
{
	MessageBox("Thank you sir see you next time!");
	CDialog::OnCancel();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -