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

📄 my_capdlg.cpp

📁 这是我编的包括古典密码
💻 CPP
字号:
// MY_CAPDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MY_CAP.h"
#include "Stream_Cipher.h"
#include "RC4_Cipher.h"
#include "DES_Cipher.h"
#include "IDEA_Cipher.h"
#include "MY_CAPDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CMY_CAPDlg dialog

CMY_CAPDlg::CMY_CAPDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMY_CAPDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMY_CAPDlg)
	m_Plaintext = _T("");
	m_Ciphertext = _T("");
	m_Stream_Cipher.Create(IDD_STREAMCIPHER,this);
	m_RC4_Cipher.Create(IDD_RC4CIPHER,this);
	m_Caeser_Cipher.Create(IDD_CCAESER_CIPHER,this);
	m_KeyWord_Cipher.Create(IDD_KEYWORD_CIPHER,this);
	m_Vigenere_Cipher.Create(IDD_VIGENERE_CIPHER,this);
	m_Playfair_Cipher.Create(IDD_PLAYFAIR_CIPHER,this);
	m_DES_Cipher.Create (IDD_DES_CIPHER, this);
	m_IDEA_Cipher.Create (IDD_IDEA_CIPHER, this);
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMY_CAPDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMY_CAPDlg)
	DDX_Text(pDX, IDC_PLAINTEXT, m_Plaintext);
	DDX_Text(pDX, IDC_CIPHERTEXT, m_Ciphertext);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMY_CAPDlg, CDialog)
	//{{AFX_MSG_MAP(CMY_CAPDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(IDD_STREAM_CIPHER, OnStreamCipher)
	ON_COMMAND(IDD_RC4_CIPHER, OnRc4Cipher)
	ON_COMMAND(IDD_CAESER, OnCaeser)
	ON_COMMAND(IDD_KEYWORD, OnKeyword)
	ON_COMMAND(IDD_VIGENERE, OnVigenere)
	ON_COMMAND(IDD_PLAYFAIR, OnPlayfair)
	ON_COMMAND(IDD_DES_CIPHER, OnDES)
	ON_COMMAND(IDD_IDEA_CIPHER, OnIDEA)
	ON_COMMAND(IDD_HELP, OnHelp)
	ON_COMMAND(IDD_ABOUT, OnAbout)
	ON_COMMAND(IDD_QUIT, OnQuit)
    ON_COMMAND(IDD_OPENP, OnSelect_Plaintext)
	ON_COMMAND(IDD_OPENC, OnSelect_Ciphertext)
	ON_COMMAND(IDD_SAVEP, OnSave_Plaintext)
	ON_COMMAND(IDD_SAVEC, OnSave_Ciphertext)
	
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMY_CAPDlg message handlers

BOOL CMY_CAPDlg::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
	SetWindowText ("密码系统 By 许志平");
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CMY_CAPDlg::OnStreamCipher() 
{
	// TODO: Add your command handler code here
	m_Stream_Cipher.ShowWindow(SW_SHOW);
	m_Stream_Cipher.Trans_Dialog(this);
}

void CMY_CAPDlg::OnRc4Cipher() 
{
	// TODO: Add your command handler code here
	m_RC4_Cipher.ShowWindow(SW_SHOW);
	m_RC4_Cipher.Trans_Dialog(this);
	
}

void CMY_CAPDlg::OnCaeser() 
{
	// TODO: Add your command handler code here
	
	m_Caeser_Cipher.ShowWindow(SW_SHOW);
	m_Caeser_Cipher.Trans_Dialog(this);
}

void CMY_CAPDlg::OnKeyword() 
{
	// TODO: Add your command handler code here
	m_KeyWord_Cipher.ShowWindow(SW_SHOW);
	m_KeyWord_Cipher.Trans_Dialog(this);
}

void CMY_CAPDlg::OnVigenere() 
{
	// TODO: Add your command handler code here
	
	m_Vigenere_Cipher.ShowWindow(SW_SHOW);
	m_Vigenere_Cipher.Trans_Dialog(this);
}

void CMY_CAPDlg::OnPlayfair() 
{
	// TODO: Add your command handler code here
	
	m_Playfair_Cipher.ShowWindow(SW_SHOW);
	m_Playfair_Cipher.Trans_Dialog(this);
}

void CMY_CAPDlg::OnDES()
{
	m_DES_Cipher.ShowWindow (SW_SHOW);
	m_DES_Cipher.Trans_Dialog (this);
}

void CMY_CAPDlg::OnIDEA()
{
	m_IDEA_Cipher.ShowWindow (SW_SHOW);
	m_IDEA_Cipher.Trans_Dialog (this);
}

void CMY_CAPDlg::OnQuit()
{
	OnOK();
}

void CMY_CAPDlg::OnAbout()
{
	CAboutDlg about;
	about.DoModal();
}

void CMY_CAPDlg::OnHelp()
{
	WinExec("notepad.exe Help.txt",SW_SHOW);
}

void CMY_CAPDlg::OnSelect_Plaintext() // 通过文件选择明文
{
	
	CFileDialog m_ldFile(TRUE);
	CString path,Path;
	CFile cf;
	if(m_ldFile.DoModal() == IDOK)
	{
		path = m_ldFile.GetFileName();
		if(cf.Open(path,CFile::modeRead))
		{
			int length = cf.GetLength();
			char *Data = new char[length+1];
			m_Plaintext = "";
			Data[length] = 0;
			try
			{
				cf.Read (Data,sizeof(char)*length);
				m_Plaintext = Data;
				UpdateData (FALSE);
			}
			catch(CFileException *e)
			{
				e -> Delete();
			}
			delete []Data;
			cf.Close ();
		}
	}


}

void CMY_CAPDlg::OnSelect_Ciphertext() // 通过文件选择密文
{

	CFileDialog m_ldFile(TRUE);
	CString path,Path;
	CFile cf;
	if(m_ldFile.DoModal() == IDOK)
	{
		path = m_ldFile.GetFileName();
		if(cf.Open(path,CFile::modeRead))
		{
			int length = cf.GetLength();
		    char *Data = new char[length+1];
			m_Ciphertext = "";
		    Data[length] = 0;
		    try
			{
			    cf.Read (Data,sizeof(char)*length);
				m_Ciphertext = Data;
			    UpdateData (FALSE);
			}
		    catch(CFileException *e)
			{
			    e -> Delete();
			}
			delete []Data;
			cf.Close ();
		}
	}
}

void CMY_CAPDlg::OnSave_Plaintext() //保存明文
{
	int Option;
	Option = MessageBox("你要保存明文吗","明文",MB_YESNO);

	if (Option == IDYES)
	{
		UpdateData(TRUE);
		CFile text;
		CFileDialog m_ldFile(FALSE,"txt","*.txt");
		CString path;
		if(m_ldFile.DoModal() == IDOK)
		{
			path = m_ldFile.GetFileName();
			if(text.Open(path,CFile::modeCreate))
			{
				text.Close();
				if(text.Open(path,CFile::modeWrite))
				{
					try
					{
						text.Write(m_Plaintext,m_Plaintext.GetLength ());
					}
					catch(CFileException *e)
					{
					 e->Delete();
					}
					text.Close();
				}
			}
		}
	}

}

void CMY_CAPDlg::OnSave_Ciphertext() //保存密文
{
	int Option;
	Option = MessageBox("你要保存密文吗","密文",MB_YESNO);

	if (Option == IDYES)
	{
		UpdateData(TRUE);
		CFile text;
		CFileDialog m_ldFile(FALSE,"txt","*.txt");
		CString path;
		if(m_ldFile.DoModal() == IDOK)
		{
			path = m_ldFile.GetFileName();
			if(text.Open(path,CFile::modeCreate))
			{
				text.Close();
				if(text.Open(path,CFile::modeWrite))
				{
					try
					{
						text.Write(m_Ciphertext,m_Ciphertext.GetLength ());
					}
					catch(CFileException *e)
					{
					 e->Delete();
					}
					text.Close();
				}
			}
		}
	}

}

⌨️ 快捷键说明

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