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

📄 showemoddlg.cpp

📁 1024位的大整数进行相乘(N方)取模
💻 CPP
字号:
// ShowEModDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "ShowEMod.h"
#include "ShowEModDlg.h"
#include ".\showemoddlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CShowEModDlg 对话框



CShowEModDlg::CShowEModDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CShowEModDlg::IDD, pParent)
	, n_btype(FALSE)
	, m_strA(_T(""))
	, m_strB(_T(""))
	, m_strN(_T(""))
	, m_strC(_T(""))
	, m_strOutput(_T(""))
	, m_strMsg(_T("B"))
	, m_nshow(1)
	, m_strTime(_T(""))
	, m_bifshow(FALSE)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CShowEModDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Radio(pDX, IDC_RADIO1, n_btype);
	DDX_Text(pDX, IDC_EDIT1, m_strA);
	DDX_Text(pDX, IDC_EDIT2, m_strB);
	DDX_Text(pDX, IDC_EDIT3, m_strN);
	DDX_Text(pDX, IDC_EDIT5, m_strC);
	DDX_Text(pDX, IDC_EDIT4, m_strOutput);
	DDX_Text(pDX, IDC_MSG, m_strMsg);
	DDX_Radio(pDX, IDC_RADIO3, m_nshow);
	DDX_Text(pDX, IDC_TIME, m_strTime);
	DDX_Radio(pDX, IDC_RADIO7, m_bifshow);
}

BEGIN_MESSAGE_MAP(CShowEModDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_RADIO2, OnBnClickedRadio2)
	ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
	ON_BN_CLICKED(IDC_RADIO1, OnBnClickedRadio1)
	ON_BN_CLICKED(IDC_RADIO3, OnBnClickedRadio3)
	ON_BN_CLICKED(IDC_RADIO4, OnBnClickedRadio4)
	ON_BN_CLICKED(IDC_RADIO5, OnBnClickedRadio5)
	ON_BN_CLICKED(IDC_RADIO6, OnBnClickedRadio6)
	ON_EN_CHANGE(IDC_EDIT1, OnEnChangeEdit1)
	ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3)
END_MESSAGE_MAP()


// CShowEModDlg 消息处理程序

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

	// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码
	sem.m_strOutput = &this->m_strOutput;
	smm.m_strOutput = &this->m_strOutput;
	
	return TRUE;  // 除非设置了控件的焦点,否则返回 TRUE
}

// 如果向对话框添加最小化按钮,则需要下面的代码
//  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
//  这将由框架自动完成。

void CShowEModDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作矩形中居中
		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;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标显示。
HCURSOR CShowEModDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

void CShowEModDlg::OnBnClickedRadio2()
{
	this->UpdateData(true);
	this->m_strMsg="E";
	this->UpdateData( false );
}

void CShowEModDlg::OnBnClickedButton1()
{
	
	long beginTime,endTime;
	this->UpdateData( true );
	this->m_strOutput=_T("");
	this->storeArray( this->m_nshow );
	if( n_btype ){
	// this is the case A^E Mod N	
		beginTime = GetTickCount();
		if( this->m_bifshow )  
			sem.emod(a,b,n,c);
		else
			sem.showemod( a,b,n,c );
		endTime=GetTickCount();
	}else{
	// this is the case A*B Mod N
		smm.reverse(a);
		smm.reverse(b);
		smm.reverse(n);
		beginTime = GetTickCount();
		if( this->m_bifshow )  
			smm.cmod( a,b,n,c);
		else
			smm.showcmod( a,b,n,c);
		endTime=GetTickCount();
	}
	smm.reverse(a);
	smm.reverse(b);
	smm.reverse(n);
	int final_clength=smm.length(c);
	if( final_clength>0 ){
		c[final_clength]=0;
		smm.reverse(c);
	}else{
		c[0]='0';
		c[1]=0;
	}

	this->getArray( this->m_nshow );
	
	this->m_strTime.Format("用时 %ld ms",endTime-beginTime);
	this->UpdateData( false );

}

void CShowEModDlg::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
}

void CShowEModDlg::OnBnClickedRadio1()
{
	this->UpdateData(true);
	this->m_strMsg="B";
	this->UpdateData( false );
}

void CShowEModDlg::OnBnClickedRadio3()
{
	this->commonAction();
}

void CShowEModDlg::OnBnClickedRadio4()
{
	this->commonAction();
}

void CShowEModDlg::OnBnClickedRadio5()
{
	this->commonAction();
}

void CShowEModDlg::OnBnClickedRadio6()
{
	this->commonAction();
}

void CShowEModDlg::OnEnChangeEdit1()
{
	// TODO:  如果该控件是 RICHEDIT 控件,则它将不会
	// 发送该通知,除非重写 CDialog::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
}

void CShowEModDlg::storeArray(int pre_nshow)
{
	switch( pre_nshow ){
		case 0:  util.HtoB( this->m_strA,this->a );
				util.HtoB( this->m_strB,this->b ); 
				util.HtoB( this->m_strN,this->n ); 
				util.HtoB( this->m_strC,this->c ); 
				break;
		case 1:  util.DtoB( this->m_strA,this->a ); 
				 util.DtoB( this->m_strB,this->b );
				 util.DtoB( this->m_strN,this->n );
				 util.DtoB( this->m_strC,this->c );break;
		case 2:	 util.OtoB( this->m_strA,this->a );
				 util.OtoB( this->m_strB,this->b );
				 util.OtoB( this->m_strN,this->n );
				 util.OtoB( this->m_strC,this->c );break;
		case 3:  strcpy( this->a, this->m_strA ); 
				 strcpy( this->b, this->m_strB );
				 strcpy( this->n, this->m_strN );
				  strcpy( this->c, this->m_strC );break;
	}
}

void CShowEModDlg::getArray(int nshow)
{
	char temp[MAXLENGTH];
	switch(  nshow ){
		case 0:  util.BtoH( this->a, temp ); this->m_strA=temp; 
				util.BtoH( this->b, temp ); this->m_strB=temp;
				util.BtoH( this->n, temp ); this->m_strN=temp;
				util.BtoH( this->c, temp ); this->m_strC=temp;break;
		case 1:  util.BtoD( this->a, temp ); this->m_strA=temp;
				util.BtoD( this->b, temp ); this->m_strB=temp;
				util.BtoD( this->n, temp ); this->m_strN=temp;
				util.BtoD( this->c, temp ); this->m_strC=temp;break;
		case 2:	 util.BtoO( this->a ,temp ); this->m_strA=temp; 
				util.BtoO( this->b ,temp ); this->m_strB=temp; 
				util.BtoO( this->n ,temp ); this->m_strN=temp; 
				util.BtoO( this->c ,temp ); this->m_strC=temp; break;
		case 3:  this->m_strA =this->a; 
				this->m_strB =this->b; 
				this->m_strN =this->n; 
				this->m_strC =this->c; break;

	}

}

void CShowEModDlg::commonAction(void)
{
	int pre_nshow = this->m_nshow;
	this->UpdateData(true);
	
	this->storeArray( pre_nshow );
	
	this->getArray( this->m_nshow );
	
	
	this->UpdateData( false );
}

void CShowEModDlg::OnBnClickedButton3()
{
	this->m_strA="";
	this->m_strB="";
	this->m_strN="";
	this->m_strC="";
	this->m_strTime="";
	this->m_strOutput="";
	this->UpdateData( false );
}

⌨️ 快捷键说明

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