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

📄 实验3dlg.cpp

📁 是一个md5的VC程序
💻 CPP
字号:
// 实验3Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "实验3.h"
#include "实验3Dlg.h"
#include "md5.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()

/////////////////////////////////////////////////////////////////////////////
// CMy3Dlg dialog

CMy3Dlg::CMy3Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMy3Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMy3Dlg)
	m_filename = _T("");
	m_md5key = _T("");
	m_len = 0;
	m_d = _T("");
	m_e = _T("");
	m_n = _T("");
	m_savename = _T("");
	m_out = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMy3Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMy3Dlg)
	DDX_Control(pDX, IDC_D, m_read2);
	DDX_Control(pDX, IDC_E, m_read1);
	DDX_Control(pDX, IDC_N, m_read);
	DDX_Text(pDX, IDC_EDIT1, m_filename);
	DDX_Text(pDX, IDC_EDIT2, m_md5key);
	DDX_CBIndex(pDX, IDC_COMBO, m_len);
	DDX_Text(pDX, IDC_D, m_d);
	DDX_Text(pDX, IDC_E, m_e);
	DDX_Text(pDX, IDC_N, m_n);
	DDX_Text(pDX, IDC_EDIT3, m_savename);
	DDX_Text(pDX, IDC_EDIT10, m_out);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMy3Dlg, CDialog)
	//{{AFX_MSG_MAP(CMy3Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnFastRead)
	ON_BN_CLICKED(IDC_BUTTON2, OnButtonMd5)
	ON_BN_CLICKED(IDC_B1, OnBGetRnd)
	ON_BN_CLICKED(IDC_B4, OnB4)
	ON_BN_CLICKED(IDC_B2, OnBPut)
	ON_BN_CLICKED(IDC_B3, OnBCheck)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy3Dlg message handlers

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

void CMy3Dlg::OnFastRead() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CFileDialog dlg(1,NULL,NULL,OFN_HIDEREADONLY ,"All Files(*.*)|*.*||");

	if(IDOK!=dlg.DoModal())return;
	m_filename=dlg.GetPathName();	
	UpdateData(FALSE);
}

void CMy3Dlg::OnButtonMd5() 
{
	

// TODO: Add your control notification handler code here
	UpdateData(true);
	if(m_filename!="")
	{
		CString csPath;
		CString csFile;

		csPath=m_filename;
		m_md5key=MD5File(csPath.GetBuffer(0)); 
     
		GetDlgItem(IDC_B1)->EnableWindow(true);
		GetDlgItem(IDC_B2)->EnableWindow(true);
		GetDlgItem(IDC_COMBO)->EnableWindow(true);
		UpdateData(false);
	}
	else
	{
		MessageBox("请选择需要MD5处理的文件。","提示:",MB_OK);
	}


}

void CMy3Dlg::OnBGetRnd() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_N)->EnableWindow(false);
	GetDlgItem(IDC_E)->EnableWindow(false);
	GetDlgItem(IDC_D)->EnableWindow(false);
	ready=1;
	UpdateData(TRUE);
	int len=2;
	for(int i=0;i<m_len+1;i++){len*=2;}
	P.Mov(0);
	Q.Mov(0);
	N.Mov(0);
	E.Mov(0);
	P.GetPrime(len);
	Q.GetPrime(len);
	N.Mov(P.Mul(Q));
	N.Put(m_n);
	P.m_ulValue[0]--;
	Q.m_ulValue[0]--;
	P.Mov(P.Mul(Q));
	D.Mov(0x10001);
	m_d="10001";
	E.Mov(D.Euc(P));
	E.Put(m_e);
    CTime t1=CTime::GetCurrentTime();
//   CTimeSpan t=t1-t0;
//	m_tdisplay.Format("%d",t.GetTotalSeconds());
//	m_tdisplay+=" 秒";
	Q.m_ulValue[0]=0;
	UpdateData(FALSE);// TODO: Add your control notification handler code here
	GetDlgItem(IDC_B4)->EnableWindow(true);
}

void CMy3Dlg::OnB4() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_EDIT3)->EnableWindow(true);
	if(ready==0)
	{
		MessageBox("请先输入或生成N、D、E","提示:",MB_OK);
        UpdateData(FALSE);
		return;
	}
	UpdateData(TRUE);
	for(int i=0;i<m_md5key.GetLength();i++)
	{
		if((m_md5key[i]<'0')||
		   ((m_md5key[i]>'9')&&(m_md5key[i]<'A'))||
		   ((m_md5key[i]>'F')&&(m_md5key[i]<'a'))||
		   (m_md5key[i]>'f'))
		{
			MessageBox("待加密数据必须为0-9或A-F或a-f组成的整数","提示:",MB_OK);
			m_md5key="";
			UpdateData(FALSE);
			return;
		}
	}
	P.Get(m_md5key);
	if(P.Cmp(N)>=0)
	{
		MessageBox("待加密数据必须小于N","提示:",MB_OK);
		m_md5key="";
        UpdateData(FALSE);
		return;
	}
	Q.Mov(P.RsaTrans(E,N));
	Q.Put(m_out);
	m_savename=m_filename+".mra";
	CFile ff(m_filename,CFile::modeRead);
	long lFileLen=ff.GetLength();
	CFile fp(m_savename,CFile::modeCreate|CFile::modeWrite);
	ff.SeekToBegin();	
	fp.SeekToBegin();
	char buff[1];
	for(long j=0;j<lFileLen;j++)
	{
		ff.Read(buff,1);
		fp.Write(buff,1);
	}
	ff.Close();
	long len=m_out.GetLength();
	fp.Write(m_out,len);
	fp.Close();
	UpdateData(FALSE);
}

void CMy3Dlg::OnBPut() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_COMBO)->EnableWindow(false);
	GetDlgItem(IDC_B3)->EnableWindow(true);
	GetDlgItem(IDC_N)->EnableWindow(true);
	GetDlgItem(IDC_E)->EnableWindow(true);
	GetDlgItem(IDC_D)->EnableWindow(true);
    m_read1.SetReadOnly(false);
	m_read2.SetReadOnly(false);
	m_read.SetReadOnly(false);

}

void CMy3Dlg::OnBCheck() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	ready=0;
	if(m_n.GetLength()>256)
	{
		MessageBox("N不得大于256位","提示:",MB_OK);
		UpdateData(FALSE);
		GetDlgItem(IDC_B4)->EnableWindow(false);
		return;
	}
	if(m_e.GetLength()>256)
	{
		MessageBox("E不得大于256位","提示:",MB_OK);
		UpdateData(FALSE);
		GetDlgItem(IDC_B4)->EnableWindow(false);
		return;
	}
    if(m_d.GetLength()>10)
	{
		MessageBox("N不得大于10位","提示:",MB_OK);
		UpdateData(FALSE);
		GetDlgItem(IDC_B4)->EnableWindow(false);
		return;
	}
	for(int i=0;i<m_n.GetLength();i++)
	{
		if((m_n[i]<'0')||
		   ((m_n[i]>'9')&&(m_n[i]<'A'))||
		   ((m_n[i]>'F')&&(m_n[i]<'a'))||
		   (m_n[i]>'f'))
		{
			MessageBox("N必须为0-9或A-F或a-f组成的整数","提示:",MB_OK);
			UpdateData(FALSE);
		    GetDlgItem(IDC_B4)->EnableWindow(false);
			return;
		}
	}
	for(i=0;i<m_e.GetLength();i++)
	{
		if((m_e[i]<'0')||
		   ((m_e[i]>'9')&&(m_e[i]<'A'))||
		   ((m_e[i]>'F')&&(m_e[i]<'a'))||
		   (m_e[i]>'f'))
		{
			MessageBox("E必须为0-9或A-F或a-f组成的整数","提示:",MB_OK);
			UpdateData(FALSE);
		    GetDlgItem(IDC_B4)->EnableWindow(false);
			return;
		}
	}
	for(i=0;i<m_d.GetLength();i++)
	{
		if((m_d[i]<'0')||
		   ((m_d[i]>'9')&&(m_d[i]<'A'))||
		   ((m_d[i]>'F')&&(m_d[i]<'a'))||
		   (m_d[i]>'f'))
		{
	    	MessageBox("D必须为0-9或A-F或a-f组成的整数","提示:",MB_OK);
			UpdateData(FALSE);
		    GetDlgItem(IDC_B4)->EnableWindow(false);
			return;
		}
	}
	N.Get(m_n);
	D.Get(m_d);
	E.Get(m_e);
	if((N.Cmp(E)<=0)||(N.Cmp(D)<=0))
	{
		MessageBox("N必须大于D、E","提示:",MB_OK);
		UpdateData(FALSE);
		GetDlgItem(IDC_EDIT3)->EnableWindow(false);
		GetDlgItem(IDC_B4)->EnableWindow(false);
		return;
	}
	ready=1;
	Q.m_ulValue[0]=0;
	m_read1.SetReadOnly(true);
	m_read2.SetReadOnly(true);
	m_read.SetReadOnly(true);
	GetDlgItem(IDC_B3)->EnableWindow(false);
	GetDlgItem(IDC_COMBO)->EnableWindow(true);
	GetDlgItem(IDC_B3)->EnableWindow(false);
	GetDlgItem(IDC_N)->EnableWindow(false);
	GetDlgItem(IDC_E)->EnableWindow(false);
	GetDlgItem(IDC_D)->EnableWindow(false);
	GetDlgItem(IDC_B4)->EnableWindow(true);

}

⌨️ 快捷键说明

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