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

📄 securedlg.cpp

📁 计算机安全的 多种密码算法演示
💻 CPP
字号:
// secureDlg.cpp : implementation file
//

#include "stdafx.h"
#include "secure.h"
#include "secureDlg.h"
#include "DES1.h"
#include "DES2.h"
#include "DES3.h"
#include "Sha1.h"
#include "RIPEMD.h"
#include "Md5A.h"
#include "SINGLE.h"
#include "DOUBLEJM.h"
#include "AES.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()

/////////////////////////////////////////////////////////////////////////////
// CSecureDlg dialog

CSecureDlg::CSecureDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSecureDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSecureDlg)
	m_yuanwen = _T("");
	m_miwen = _T("");
	m_mingwen = _T("");
	m_keytext = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSecureDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSecureDlg)
	DDX_Control(pDX, IDC_COMBO1, m_list);
	DDX_Text(pDX, IDC_YUANWEN, m_yuanwen);
	DDX_Text(pDX, IDC_MIWEN, m_miwen);
	DDX_Text(pDX, IDC_MINGWEN, m_mingwen);
	DDX_Text(pDX, IDC_KEYTEXT, m_keytext);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSecureDlg, CDialog)
	//{{AFX_MSG_MAP(CSecureDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_DESTROY()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_ENCODE, OnEncode)
	ON_BN_CLICKED(IDC_DECODE, OnDecode)
	ON_CBN_CLOSEUP(IDC_COMBO1, OnCloseupCombo1)
	ON_BN_CLICKED(IDC_CLEAR, OnClear)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSecureDlg message handlers

BOOL CSecureDlg::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 CSecureDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

void CSecureDlg::OnDestroy()
{
	WinHelp(0L, HELP_QUIT);
	CDialog::OnDestroy();
}

// 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 CSecureDlg::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 CSecureDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
DES1 des1;
DES2 des2;
DES3 des3;
CRIPEMD ripemd;
CMd5A md5;
CSHA sha;
SINGLE single;
DOUBLEJM duobiao;
AES aes;
void CSecureDlg::OnEncode() 
{
	// TODO: Add your control notification handler code here
CString item;	
	int i=0;
     UpdateData(TRUE);
	static char cTempChar[255],cMima[255];
   static char cResultChar[255];
   char* cResultString;
  int length=m_mingwen.GetLength();
   for(i=0;i<=length-1;i++)
	{
		cTempChar[i]=m_mingwen.GetAt(i);
	}
 int length2=m_keytext.GetLength();
	for(i=0;i<=length2-1;i++)
	{
		cMima[i]=m_keytext.GetAt(i);
	}


 m_list.GetWindowText(item);
 

 if(length==0) {AfxMessageBox("ERROR!:请输入明文!"); } 
 else{ if(item=="") AfxMessageBox("ERROR!:请选择一种算法");
  if(length2==0&&(item!="MD5"||item!="RIPEMD"||item!="SHA")){AfxMessageBox("ERROR!:请输入密码!"); } 
	 //DES1---------------------------------------------------
if(item=="1DES"&&length2!=0)
{for(i=0;i<=length-1;i++)
    des1.plaintext[i]=cTempChar[i];
  	for(i=0;i<=length2-1;i++)
 	des1.keytext[i]=cMima[i];
	m_miwen=des1.endes();
}
 
//DES2---------------------------------------------------
if(item=="2DES"&&length2!=0)
{for(i=0;i<=length-1;i++)
    des2.plaintext[i]=cTempChar[i];
  	for(i=0;i<=7;i++)
	{
	des2.keytext1[i]=cMima[i];
		}
for(i=8;i<=15;i++)
{des2.keytext2[i]=cMima[i];
}
	m_miwen=des2.endes2();
}


//DES3---------------------------------------------------
if(item=="3DES"&&length2!=0)
{for(i=0;i<=length-1;i++)
    des3.plaintext[i]=cTempChar[i];
  	for(i=0;i<=7;i++)
	{
	des3.keytext1[i]=cMima[i];
		}
for(i=8;i<=15;i++)
{des3.keytext2[i]=cMima[i];
}
	
for(i=16;i<=23;i++)
{des3.keytext2[i]=cMima[i];
}
m_miwen=des3.endes3();
}

	   
//SHA1-------------------------------------		 
if(item=="SHA")
{	cResultString=sha.SHAString(cTempChar);
	m_miwen=(CString)cResultString; 
}




//RIPEMD-------------------------------------------------
if(item=="RIPEMD")
{	cResultString=ripemd.RIPString(cTempChar);
	m_miwen=(CString)cResultString;
}


//md5-------------------------------------------------
  
 if(item=="MD5")
 {	
	 cResultString=md5.MDString(cTempChar);
	 m_miwen=(CString)cResultString; 
 }



  //single-----------------------------------------
 if(item=="SINGLE FORM"&&length2!=0) 
 { for(i=0;i<=length-1;i++)
    single.I[i]=cTempChar[i];
	  single.len=length;
     for(i=0;i<=length2-1;i++)
 	  single.num[i]=cMima[i];
	  
  	 m_miwen=single.encode();
 }

//DUOBIAO-----------------------------
 if(item=="DOUBLE FORM"&&length2!=0)
 {	for(i=0;i<=length-1;i++)
    duobiao.A[i]=cTempChar[i];
    for(i=0;i<=length2-1;i++)
 	  duobiao.B[i]=cMima[i];
  m_miwen=duobiao.encode();
 }


//AES-------------------------------------

 if(item=="AES")
 {	for(i=0;i<=length-1;i++)
    aes.block[i]=cTempChar[i];
    for(i=0;i<=length2-1;i++)
 	  aes.key[i]=cMima[i];
  m_miwen=aes.encode();
 }






 }
 UpdateData(FALSE);

}

void CSecureDlg::OnDecode() 
{
	// TODO: Add your control notification handler code here
CString item;
	int i=0;
	
static char cTempChar[255],cMima[255];
   static char cResultChar[255];
   int length=m_mingwen.GetLength();
   for(i=0;i<=length-1;i++)
	{
		cTempChar[i]=m_mingwen.GetAt(i);
	}
 int length2=m_keytext.GetLength();
	for(i=0;i<=length2-1;i++)
	{
		cMima[i]=m_keytext.GetAt(i);
	}	
	
	
	
	m_list.GetWindowText(item);	
	if(length==0||item=="MD5"||item=="RIPEMD"||item=="SHA") {AfxMessageBox("ERROR!:无法解密!"); } 
else {
//DES1------------------------------------------ 
if(item=="1DES")
	m_yuanwen=des1.dedes();

//DES2------------------------------------------ 
if(item=="2DES")
{
    for(i=0;i<=7;i++){des2.keytext1[i]=cMima[i];}
	for(i=8;i<=15;i++){des2.keytext2[i]=cMima[i];}	
    m_yuanwen=des2.dedes2();
}

//DES3-----------------------------------------------
  if(item=="3DES")
  {
   for(i=0;i<=7;i++){des3.keytext1[i]=cMima[i];}
   for(i=8;i<=15;i++){des3.keytext2[i]=cMima[i];}
   for(i=16;i<=23;i++){des3.keytext2[i]=cMima[i];}
    m_yuanwen=des3.dedes3();
  }

//SINGLE-----------------------------------------	
if(item=="SINGLE FORM")
   m_yuanwen=single.decode();

//DUOBIAO---------------------------------------
if(item=="DOUBLE FORM")
   m_yuanwen=duobiao.decode();

//AES------------------------
 if(item=="AES")
  m_yuanwen=aes.decode();






}	
	UpdateData(FALSE);
}

void CSecureDlg::OnCloseupCombo1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(FALSE);
}

void CSecureDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	AfxMessageBox("感谢您使用本软件!");
	CDialog::OnCancel();
}

void CSecureDlg::OnClear() 
{
	// TODO: Add your control notification handler code here
	m_mingwen="";
	m_keytext="";
	m_miwen="";
	m_yuanwen="";
	UpdateData(FALSE);

}

⌨️ 快捷键说明

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