📄 powmod.cpp
字号:
// PowMod.cpp : implementation file
//
#include "stdafx.h"
#include "SoftProtect.h"
#include "PowMod.h"
#include "Superint.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPowMod dialog
CPowMod::CPowMod(CWnd* pParent /*=NULL*/)
: CDialog(CPowMod::IDD, pParent)
{
//{{AFX_DATA_INIT(CPowMod)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CPowMod::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPowMod)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPowMod, CDialog)
//{{AFX_MSG_MAP(CPowMod)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPowMod message handlers
void CPowMod::OnButton1()
{
int x = GetDlgItemInt(IDC_EDIT1);
int y = GetDlgItemInt(IDC_EDIT2);
int m = GetDlgItemInt(IDC_EDIT3);
CString strX,strY,strM;
strX.Format(_T("%x"),x);
strY.Format(_T("%x"),y);
strM.Format(_T("%x"),m);
CSuperint siX(strX);
CSuperint siY(strY);
CSuperint siM(strM);
//求结果
CSuperint siMod(1);
int iDBits = siY.GetUsedBits();
CSuperint siBitMod(siX);
int iDBitModIndex = 0;
for(int i=0; i<iDBits; i++)
{
if( siY.IsBitOn(i))
{
for(int j=iDBitModIndex; j<i; j++)
siBitMod = siBitMod*siBitMod%siM;
iDBitModIndex = i;
siMod = siMod*siBitMod%siM;
}
}
CString strResult;
int iResult;
siMod.GetHex(strResult.GetBufferSetLength(0x1000),0x1000);
strResult.ReleaseBuffer();
_stscanf(strResult,_T("%x"),&iResult);
SetDlgItemInt(IDC_EDIT4,iResult);
}
void CPowMod::OnButton2()
{
int x = GetDlgItemInt(IDC_EDIT5);
int y = GetDlgItemInt(IDC_EDIT6);
CString strX,strY;
strX.Format(_T("%x"),x);
strY.Format(_T("%x"),y);
CSuperint siX(strX);
CSuperint siY(strY);
CSuperint siResult = siX%siY;
CString strResult;
int iResult;
siResult.GetHex(strResult.GetBufferSetLength(0x1000),0x1000);
strResult.ReleaseBuffer();
_stscanf(strResult,_T("%x"),&iResult);
SetDlgItemInt(IDC_EDIT7,iResult);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -