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

📄 wwwdlg.cpp

📁 基于RSA加密和解密 用mfc做得
💻 CPP
字号:
// wwwDlg.cpp : implementation file
//

#include "stdafx.h"
#include "www.h"
#include "wwwDlg.h"
#include "stdlib.h"
#include "string.h"
#include "math.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()

/////////////////////////////////////////////////////////////////////////////
// CWwwDlg dialog

CWwwDlg::CWwwDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWwwDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWwwDlg)
	m_e = 0;
	m_mingwen = _T("");
	m_n = 0;
	m_p = 0;
	m_q = 0;
	m_z = 0;
	m_d = 0;
	m_miwen = _T("");
	m_jiemi = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CWwwDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWwwDlg)
	DDX_Text(pDX, IDC_gongyue, m_e);
	DDX_Text(pDX, IDC_mingwen, m_mingwen);
	DDX_Text(pDX, IDC_mn, m_n);
	DDX_Text(pDX, IDC_mp, m_p);
	DDX_Text(pDX, IDC_mq, m_q);
	DDX_Text(pDX, IDC_mz, m_z);
	DDX_Text(pDX, IDC_siyue, m_d);
	DDX_Text(pDX, IDC_miwen, m_miwen);
	DDX_Text(pDX, IDC_jiemi, m_jiemi);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CWwwDlg, CDialog)
	//{{AFX_MSG_MAP(CWwwDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnJIAMI)
	ON_BN_CLICKED(IDC_BUTTON2, OnJIEMI)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWwwDlg message handlers

BOOL CWwwDlg::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 CWwwDlg::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 CWwwDlg::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 CWwwDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
long  gys(long p,long q)
{
	if(p%q!=0)
		gys(q,p%q);
	else
		return q;
}
bool Issushu(long p)
{
	if(p==1)
		return false;
	if(p==2)
		return true;
	for(long i=2;i<p/2;i++)
		if(p%i==0)
			return false;
	return true;
}
long get_gongyao(long a, long b)
{
	long s0=1,s1=0,s2;long q,t,b0;
	b0=b;
	while(b)
	{
		q=a/b;
		s2=s0-q*s1;
		if(s2>=0) 
			s2=s2%b0;
		else
			s2=b0-(-s2)%b0;
		s0=s1;s1=s2;
		t=b;b=a%b;a=t;
	}
	if(a==1) 
		return s0;
	else return 0;
}
long  get_siyao(long p)
{
	long yueshu=1;
	long i=sqrt(p);
	while(true)
	{
		if(gys(p,i)==yueshu)
	      return i;
		i++;
	}
}
void Init(long &p,long &q)
{
	p=rand()%100+100;
	q=rand()%100+100;
	while(Issushu(p)==false||Issushu(q)==false)
	{
		p=rand()%100+100;
		q=rand()%100+100;
	}
}
void StrtoInt(char *s,long n[],int Length)
{
	for(int i=0;i<Length;i++)
		n[i]=(int)(s[i]);
}
void InttoStr(char *s,long n[],int Length)
{
	for(int i=0;i<Length;i++)
		s[i]=(char)(n[i]);
}
long miwenshuzi(long m,long e,long n)
{
	long a=1;
	while(e!=0)
	{
		if(e%2)  a=(a*m)%n;
		m=(m*m)%n;
		e=e>>=1;
	}
	return a;
}
void CWwwDlg::OnJIAMI() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	if(m_mingwen.GetLength()==0)
	{
		AfxMessageBox("输入的明文不能为空");
		return;
	}
	m_miwen.Empty();
	int i;
	for(i=0;i<m_mingwen.GetLength();i++)
		info.sInfo[i]=m_mingwen.GetAt(i);
	info.sInfo[i]='\0';
	info.Length=m_mingwen.GetLength();
	StrtoInt(info.sInfo,info.nInfo,info.Length);
	Init(m_p,m_q);
	m_n=m_p*m_q;
	m_z=(m_p-1)*(m_q-1);
	m_d=get_siyao(m_z);
	m_e=get_gongyao(m_d,m_z);
	for(i=0;i<info.Length;i++)
		info.nKeyInfo[i]=miwenshuzi(info.nInfo[i],m_e,m_n);
	InttoStr(info.sKeyInfo,info.nKeyInfo,info.Length);
	for(i=0;i<info.Length;i++)
		m_miwen+=info.sKeyInfo[i];
	UpdateData(false);
}

void CWwwDlg::OnJIEMI() 
{
	// TODO: Add your control notification handler code here
	m_jiemi.Empty();
	int i;
	for(i=0;i<info.Length;i++)
		info.nInfo[i]=miwenshuzi(info.nKeyInfo[i],m_d,m_n);
	InttoStr(info.sInfo,info.nInfo,info.Length);
	for(i=0;i<info.Length;i++)
		m_jiemi+=info.sInfo[i];
	UpdateData(false);;
}

⌨️ 快捷键说明

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