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

📄 bigintdlg.cpp

📁 RSA加密中的大整数运算
💻 CPP
字号:
// BigIntDlg.cpp : implementation file
//

#include "stdafx.h"
#include "BigInt.h"
#include "BigIntDlg.h"
#include"main.cpp"
#include"CRT.cpp"
#ifdef _DEBUG

#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define HISTORY 20
CString history[HISTORY];
int mark=-1,look=-1;
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CBigIntDlg dialog

CBigIntDlg::CBigIntDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBigIntDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBigIntDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CBigIntDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBigIntDlg)
	DDX_Control(pDX, IDC_COMBO2, m_comboexp);
	DDX_Control(pDX, IDC_COMBO1, m_combovar);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CBigIntDlg, CDialog)
	//{{AFX_MSG_MAP(CBigIntDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
	ON_CBN_SELCHANGE(IDC_COMBO2, OnSelchangeCombo2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBigIntDlg message handlers

BOOL CBigIntDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

CheckRadioButton(IDC_RADIO8,IDC_RADIO13,IDC_RADIO8);



	m_combovar.AddString("VAR0");
	m_combovar.AddString("VAR1");
	m_combovar.AddString("VAR2");
	m_combovar.AddString("VAR3");
	m_combovar.AddString("VAR4");
	m_combovar.AddString("VAR5");
	m_combovar.AddString("VAR6");
	m_combovar.AddString("VAR7");
	m_combovar.AddString("VAR8");
	m_combovar.AddString("VAR9");
	m_combovar.AddString("VAR10");
	m_combovar.AddString("VAR11");
	m_combovar.AddString("VAR12");
	m_combovar.AddString("VAR13");
	m_combovar.AddString("VAR14");
	m_combovar.AddString("VAR15");
	m_combovar.AddString("VAR16");
	m_combovar.AddString("VAR17");
	m_combovar.AddString("VAR18");
	m_combovar.AddString("VAR19");



	m_comboexp.AddString("EXP0");
	m_comboexp.AddString("EXP1");
	m_comboexp.AddString("EXP2");
	m_comboexp.AddString("EXP3");
	m_comboexp.AddString("EXP4");
	m_comboexp.AddString("EXP5");
	m_comboexp.AddString("EXP6");
	m_comboexp.AddString("EXP7");
	m_comboexp.AddString("EXP8");
	m_comboexp.AddString("EXP9");
	m_comboexp.AddString("EXP10");
	m_comboexp.AddString("EXP11");
	m_comboexp.AddString("EXP12");
	m_comboexp.AddString("EXP13");
	m_comboexp.AddString("EXP14");
	m_comboexp.AddString("EXP15");
	m_comboexp.AddString("EXP16");
	m_comboexp.AddString("EXP17");
	m_comboexp.AddString("EXP18");
	m_comboexp.AddString("EXP19");

	for(int i=0;i<HISTORY;i++)
		history[i]="";

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

void CBigIntDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
		CString str="\0";
		look=mark;
SetDlgItemText(IDC_EDIT1,str);
SetDlgItemText(IDC_EDIT2,str);
	
}

void CBigIntDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	int nid=GetCheckedRadioButton(IDC_RADIO8,IDC_RADIO13);
	CString cs,cs1,cs2; 
    GetDlgItem( IDC_EDIT2 )->GetWindowText( cs ); 
	char p[10000];
	strcpy(p,LPCTSTR(cs));
	if(p[strlen(p)-1]!='=')
		cs=cs+"=";
	if(strlen(p)<2&&(nid-1015==1||nid-1015==2||nid-1015==3))
	{
		MessageBox("输入命令不符合要求!");
	}
	else if(nid-1015==6)
	{
	string result=crtmain(p);
    cs1.Format("%s",  result.c_str());
	cs2=cs+cs1;
	    history[(++mark)%HISTORY]=cs2;
	look=mark;
	SetDlgItemText(IDC_EDIT1,cs2);
	}
	else
	{
	string result=domain(nid-1015,p);

	if(nid-1015==1||nid-1015==2||nid-1015==3)
	{
    cs1.Format("%s",  result.c_str());
	cs2=cs+cs1;
	}

	else
	{
     cs2.Format("%s",  result.c_str());
	}
    history[(++mark)%HISTORY]=cs2;
	look=mark;
	SetDlgItemText(IDC_EDIT1,cs2);
	}
	

	
}

void CBigIntDlg::OnSelchangeCombo1() 
{
	// TODO: Add your control notification handler code here
	char temp[4];
	int nIndex=m_combovar.GetCurSel();
	_itoa(nIndex,temp,10);
    string  str="VAR";
	str+=temp;
	str+="=";
	str+=VAR[nIndex].outputDEC();
	CString cs;
    cs.Format("%s",  str.c_str());
	    history[(++mark)%HISTORY]=cs;
	look=mark;
    SetDlgItemText(IDC_EDIT1,cs);
}

void CBigIntDlg::OnSelchangeCombo2() 
{
	// TODO: Add your control notification handler code here
	char temp[4];
	int nIndex=m_comboexp.GetCurSel();
		_itoa(nIndex,temp,10);
	 string  str="EXP";
	str+=temp;
	str+="=";
	str+=EXP[nIndex].outputDEC();
	CString cs;
    cs.Format("%s",  str.c_str());
	    history[(++mark)%HISTORY]=cs;
	look=mark;
    SetDlgItemText(IDC_EDIT1,cs);
	
}

void CBigIntDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here

	SetDlgItemText(IDC_EDIT1,history[(look--)%HISTORY]);
	if(look<0)look=HISTORY+look;
	
}

void CBigIntDlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
			look++;
	SetDlgItemText(IDC_EDIT1,history[look%HISTORY]);
}

⌨️ 快捷键说明

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