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

📄 dlgrsa.cpp

📁 详细的AESRSASHA1实现原理
💻 CPP
字号:
// DlgRSAEncrypt.cpp : implementation file
//

#include "stdafx.h"
#include "cryptology.h"
#include "DlgRSA.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgRSA dialog
CDlgRSA::CDlgRSA(CWnd* pParent /*=NULL*/)
: CDialog(CDlgRSA::IDD, pParent)
{
    //{{AFX_DATA_INIT(CDlgRSA)
    m_strMsg	= _T("");
    m_strDecrypt= _T("");
    m_strCrypt	= _T("");
	m_strKey    = _T("");
	//}}AFX_DATA_INIT
}

void CDlgRSA::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CDlgRSA)
    DDX_Text(pDX, IDC_EDIT_MESSAGE, m_strMsg);
    DDV_MaxChars(pDX, m_strMsg, 50000);
    DDX_Text(pDX, IDC_EDIT_DECRYPT, m_strDecrypt);
    DDV_MaxChars(pDX, m_strDecrypt, 50000);
    DDX_Text(pDX, IDC_EDIT_CRYPTOGRAPH, m_strCrypt);
    DDV_MaxChars(pDX, m_strCrypt, 50000);
	DDX_Text(pDX, IDC_EDIT_KEY, m_strKey);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgRSA, CDialog)
    //{{AFX_MSG_MAP(CDlgRSA)
    ON_BN_CLICKED(IDC_BUTTON_DECRYPT, OnButtonDecrypt)
    ON_BN_CLICKED(IDC_BUTTON_ENCRYPT, OnButtonEncrypt)
    ON_EN_CHANGE(IDC_EDIT_MESSAGE, OnChangeEditMessage)
	ON_BN_CLICKED(IDC_BUTTON_GENERATE_KEY, OnButtonGenerateKey)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgRSA message handlers

void CDlgRSA::OnChangeEditMessage() 
{
    // TODO: Add your control notification handler code here
    m_bEncrypt = false;
}

BOOL CDlgRSA::OnInitDialog() 
{
    CDialog::OnInitDialog();
    
    // TODO: Add extra initialization here
    char ch;
    FILE *fp = fopen("Gettysburg.txt","r");
    while( (ch=fgetc(fp))!=EOF )
    {
        if( ch=='\n' )  m_strMsg += '\r';
        m_strMsg += ch;
    }
    fclose(fp);
    UpdateData(FALSE);

    m_bEncrypt = false;
    m_bDecrypt = true;
    
    return TRUE;
}

void CDlgRSA::OnButtonEncrypt() 
{
    // TODO: Add your control notification handler code here
    if( m_bEncrypt==true )  return;
    if( !m_RSA.GetInitial( ) )
    {
        MessageBox("RSA method has not been initialed!", "Warning", MB_OK);
        return;
    }
    
    UpdateData(TRUE);
    
    m_RSA.Encrypt( m_strMsg, m_strCrypt );   
    m_bEncrypt = true;
    m_bDecrypt = false;
    
    UpdateData(FALSE);
}

void CDlgRSA::OnButtonDecrypt( ) 
{
    // TODO: Add your control notification handler code here
    if( m_bDecrypt==true )  return;

    UpdateData(TRUE);
    
    m_RSA.Decrypt( m_strCrypt, m_strDecrypt );
    m_bDecrypt = true;
    
    UpdateData(FALSE);
}

void CDlgRSA::OnButtonGenerateKey() 
{
	// TODO: Add your control notification handler code here
	m_RSA.Initial( );
    m_RSA.GetKeyN( m_strKey );

    m_bEncrypt = false;
    m_bDecrypt = true;

    UpdateData(FALSE);
}

⌨️ 快捷键说明

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