在好例子网,分享、交流、成长!
您当前所在位置:首页C/C++ 开发实例C/C++语言基础 → 希尔密码加密、解密和破密HillCodor

希尔密码加密、解密和破密HillCodor

C/C++语言基础

下载此实例
  • 开发语言:C/C++
  • 实例大小:4.07M
  • 下载次数:10
  • 浏览次数:231
  • 发布时间:2019-07-13
  • 实例类别:C/C++语言基础
  • 发 布 人:crazycode
  • 文件格式:.rar
  • 所需积分:2
 相关标签: 密码 解密 加密

实例介绍

【实例简介】

【调试说明】

如果提示【“iostream.h”: No such file or directory】,那么请将【#include "iostream.h"】更换为【#include <iostream>   using namespace std;】

【实例截图】

from clipboard

【核心代码】


// HillCodorDlg.cpp : implementation file
//

#include "StdAfx.h"
#include "HillCodor.h"
#include "HillCodorDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CHillCodorDlg dialog

CHillCodorDlg::CHillCodorDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CHillCodorDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CHillCodorDlg)
	m_strEnMFilePath = _T("");
	m_strEnEFilePath = _T("");
	m_strEnKeyFilePath = _T("");
	m_strEnKey = _T("");
	m_strDisMFilePath = _T("");
	m_strDisKeyFilePath = _T("");
	m_strDisEFilePath = _T("");
	m_strUnMFilePath = _T("");
	m_strUnEFilePath = _T("");
	m_strUnKey = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CHillCodorDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CHillCodorDlg)
	DDX_Text(pDX, IDC_EN_M_FILE_PATH, m_strEnMFilePath);
	DDX_Text(pDX, IDC_EN_E_FILE_PATH, m_strEnEFilePath);
	DDX_Text(pDX, IDC_EN_KEY_FILE_PATH, m_strEnKeyFilePath);
	DDX_Text(pDX, IDC_EN_KEY, m_strEnKey);
	DDX_Text(pDX, IDC_DIS_M_FILE_PATH, m_strDisMFilePath);
	DDX_Text(pDX, IDC_DIS_KEY_FILE_PATH, m_strDisKeyFilePath);
	DDX_Text(pDX, IDC_DIS_E_FILE_PATH, m_strDisEFilePath);
	DDX_Text(pDX, IDC_UN_M_FILE_PATH, m_strUnMFilePath);
	DDX_Text(pDX, IDC_UN_E_FILE_PATH, m_strUnEFilePath);
	DDX_Text(pDX, IDC_UNCODE_KEY, m_strUnKey);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CHillCodorDlg, CDialog)
	//{{AFX_MSG_MAP(CHillCodorDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_OPEN_M_FILE, OnButtonOpenMFile)
	ON_BN_CLICKED(IDC_BUTTON_SAVE_E_FILE, OnButtonSaveEFile)
	ON_BN_CLICKED(IDC_BUTTON_SAVE_KEY_FILE, OnButtonSaveKeyFile)
	ON_BN_CLICKED(IDC_BUTTON_ENCRYPTION, OnButtonEncryption)
	ON_BN_CLICKED(IDC_BUTTON_SAVE_M_FILE, OnButtonSaveMFile)
	ON_BN_CLICKED(IDC_BUTTON_OPEN_E_FILE, OnButtonOpenEFile)
	ON_BN_CLICKED(IDC_BUTTON_OPEN_KEY_FILE_DIS, OnButtonOpenKeyFileDis)
	ON_BN_CLICKED(IDC_BUTTON_DISCRYPTION, OnButtonDiscryption)
	ON_BN_CLICKED(IDC_BUTTON_GET_KEY, OnButtonGetKey)
	ON_BN_CLICKED(IDC_BUTTON_OPEN_M_UN, OnButtonOpenMUn)
	ON_BN_CLICKED(IDC_BUTTON_OPEN_E_UN, OnButtonOpenEUn)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHillCodorDlg message handlers

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

void CHillCodorDlg::OnButtonOpenMFile() 
{
	// TODO: Add your control notification handler code here
	// 提示选择打开文件路径
	
	CFileDialog dlg(TRUE, "txt", m_strEnMFilePath, OFN_HIDEREADONLY, 
		"txt文本文件 (*.txt) | *.txt|所有文件 (*.*) | *.*||", NULL);
	
	// 提示用户选择保存的路径
	if (dlg.DoModal() != IDOK)
	{
		// 返回
		return;
	}
	
	// 获取用户指定的文件路径
	m_strEnMFilePath = dlg.GetPathName();
	
	// 更新
	UpdateData(FALSE);
}

void CHillCodorDlg::OnButtonSaveEFile() 
{
	// TODO: Add your control notification handler code here
	// 提示选择保存文件路径
	
	CFileDialog dlg(FALSE, "txt", m_strEnEFilePath, OFN_HIDEREADONLY, 
		"txt文本文件 (*.txt) | *.txt|所有文件 (*.*) | *.*||", NULL);
	
	// 提示用户选择保存的路径
	if (dlg.DoModal() != IDOK)
	{
		// 返回
		return;
	}
	
	// 获取用户指定的文件路径
	m_strEnEFilePath = dlg.GetPathName();
	
	// 更新
	UpdateData(FALSE);
}

void CHillCodorDlg::OnButtonSaveKeyFile() 
{
	// TODO: Add your control notification handler code here
	// 提示选择保存文件路径
	
	CFileDialog dlg(FALSE, "txt", m_strEnKeyFilePath, OFN_HIDEREADONLY, 
		"txt文本文件 (*.txt) | *.txt|所有文件 (*.*) | *.*||", NULL);
	
	// 提示用户选择保存的路径
	if (dlg.DoModal() != IDOK)
	{
		// 返回
		return;
	}
	
	// 获取用户指定的文件路径
	m_strEnKeyFilePath = dlg.GetPathName();
	
	// 更新
	UpdateData(FALSE);
}

void CHillCodorDlg::OnButtonEncryption() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CFile fileM; // 明文
	CFileException fe;

	if(!fileM.Open(m_strEnMFilePath.GetBuffer(0), CFile::modeRead, &fe))
	{
		CString strError = "";
		strError.Format("Error!\r\nCan't open the file:%s\r\nCode: %d",
			m_strEnMFilePath.GetBuffer(0), fe.m_cause);
		AfxMessageBox(strError);
		return;
	}

	CFile fileE;  // 密文
	if(!fileE.Open(m_strEnEFilePath.GetBuffer(0), CFile::modeWrite|CFile::modeCreate, &fe))
	{
		CString strError = "";
		strError.Format("Error!\r\nCan't open the file:%s\r\nCode: %d",
			m_strEnMFilePath.GetBuffer(0), fe.m_cause);
		AfxMessageBox(strError);
		return;
	}

	CFile fileKey; // 解密密钥文件
	if(!fileKey.Open(m_strEnKeyFilePath.GetBuffer(0), CFile::modeWrite|CFile::modeCreate, &fe))
	{
		CString strError = "";
		strError.Format("Error!\r\nCan't open the file:%s\r\nCode: %d",
			m_strEnMFilePath.GetBuffer(0), fe.m_cause);
		AfxMessageBox(strError);
		return;
	}

	CHillCode codeEncryptor;
	long *pEncryKey = NULL;
	char * pM = NULL;
	char * pE = NULL;
	int nLen = m_strEnKey.GetLength(); // 块大小
	int i = 0;

	nLen = (int)sqrt((nLen));
	pM = new char[nLen];
	if(NULL == pM)
	{
		exit(1);
	}
	pE = new char[nLen];
	if(NULL == pM)
	{
		exit(1);
	}
	int nKeyLen = nLen * nLen;
	pEncryKey = new long[nKeyLen];
	if(NULL == pEncryKey)
	{
		exit(1);
	}
	for(i=0; i<nKeyLen; i  )
	{
		pEncryKey[i] = m_strEnKey.GetAt(i);
	}

	BeginWaitCursor();

	// 设置密钥
	if(!codeEncryptor.SetEncryKey(pEncryKey, nKeyLen))
	{
		MessageBox("密钥不合适,请重新输入!");		
		if(NULL != pEncryKey)
		{
			delete pEncryKey;
			pEncryKey = NULL;
		}
		if(NULL != pM)
		{
			delete pM;
			pM = NULL;
		}
		if(NULL != pE)
		{
			delete pE;
			pE = NULL;
		}
		fileM.Close();
		fileE.Close();
		fileKey.Close();
		
		return;
	}
	m_strEnKey = m_strEnKey.Left(nKeyLen);
	UpdateData(FALSE);

	// 写入解密密钥(一个密钥元素占4个字节)
	long * pDiscryKey = NULL;
	pDiscryKey = new long[nKeyLen];
	if(NULL == pDiscryKey)
	{
		exit(1);
	}
	memcpy(pDiscryKey, codeEncryptor.GetDiscryptedKey(), sizeof(long) * nKeyLen);
	fileKey.Write((char *)pDiscryKey, sizeof(long) * nKeyLen);

	// 写入明文长度
	long nMFileLen = fileM.GetLength();
	fileKey.Write(&nMFileLen, sizeof(long));

	// 分块循环加密
	int nBlockNum = nMFileLen / nLen;
	for(i=0; i<nBlockNum; i  )
	{
		fileM.Read(pM, nLen);
		codeEncryptor.SetM((const unsigned char *)pM, nLen);
		memcpy(pE, codeEncryptor.Encrypting(), nLen);
		fileE.Write(pE, nLen);
	}

	// 加密最后一块
	NULL;

	EndWaitCursor();
	
	// 结束处理
	if(NULL != pDiscryKey)
	{
		delete pDiscryKey;
		pDiscryKey = NULL;
	}
	if(NULL != pEncryKey)
	{
		delete pEncryKey;
		pEncryKey = NULL;
	}
	if(NULL != pM)
	{
		delete pM;
		pM = NULL;
	}
	if(NULL != pE)
	{
		delete pE;
		pE = NULL;
	}
	fileM.Close();
	fileE.Close();
	fileKey.Close();
}



void CHillCodorDlg::OnButtonSaveMFile() 
{
	// TODO: Add your control notification handler code here
	// 提示选择保存文件路径
	
	CFileDialog dlg(FALSE, "txt", m_strDisMFilePath, OFN_HIDEREADONLY, 
		"txt文本文件 (*.txt) | *.txt|所有文件 (*.*) | *.*||", NULL);
	
	// 提示用户选择保存的路径
	if (dlg.DoModal() != IDOK)
	{
		// 返回
		return;
	}
	
	// 获取用户指定的文件路径
	m_strDisMFilePath = dlg.GetPathName();
	
	// 更新
	UpdateData(FALSE);
}

void CHillCodorDlg::OnButtonOpenEFile() 
{
	// TODO: Add your control notification handler code here
	// 提示选择打开文件路径
	
	CFileDialog dlg(TRUE, "txt", m_strDisEFilePath, OFN_HIDEREADONLY, 
		"txt文本文件 (*.txt) | *.txt|所有文件 (*.*) | *.*||", NULL);
	
	// 提示用户选择保存的路径
	if (dlg.DoModal() != IDOK)
	{
		// 返回
		return;
	}
	
	// 获取用户指定的文件路径
	m_strDisEFilePath = dlg.GetPathName();
	
	// 更新
	UpdateData(FALSE);
}

void CHillCodorDlg::OnButtonOpenKeyFileDis() 
{
	// TODO: Add your control notification handler code here
	// 提示选择打开文件路径
	
	CFileDialog dlg(TRUE, "txt", m_strDisKeyFilePath, OFN_HIDEREADONLY, 
		"txt文本文件 (*.txt) | *.txt|所有文件 (*.*) | *.*||", NULL);
	
	// 提示用户选择保存的路径
	if (dlg.DoModal() != IDOK)
	{
		// 返回
		return;
	}
	
	// 获取用户指定的文件路径
	m_strDisKeyFilePath = dlg.GetPathName();
	
	// 更新
	UpdateData(FALSE);
}

void CHillCodorDlg::OnButtonDiscryption() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CFile fileM; // 明文
	CFileException fe;

	if(!fileM.Open(m_strDisMFilePath.GetBuffer(0), CFile::modeWrite|CFile::modeCreate, &fe))
	{
		CString strError = "";
		strError.Format("Error!\r\nCan't open the file:%s\r\nCode: %d",
			m_strDisMFilePath.GetBuffer(0), fe.m_cause);
		AfxMessageBox(strError);
		return;
	}

	CFile fileE;  // 密文
	if(!fileE.Open(m_strDisEFilePath.GetBuffer(0), CFile::modeRead, &fe))
	{
		CString strError = "";
		strError.Format("Error!\r\nCan't open the file:%s\r\nCode: %d",
			m_strDisEFilePath.GetBuffer(0), fe.m_cause);
		AfxMessageBox(strError);
		return;
	}

	CFile fileKey; // 解密密钥文件
	if(!fileKey.Open(m_strDisKeyFilePath.GetBuffer(0), CFile::modeRead, &fe))
	{
		CString strError = "";
		strError.Format("Error!\r\nCan't open the file:%s\r\nCode: %d",
			m_strDisKeyFilePath.GetBuffer(0), fe.m_cause);
		AfxMessageBox(strError);
		return;
	}
	
	long *pDiscryKey = NULL;  // 存放解密密钥
	
	// 获取密钥长度(一个密钥元素占4个字节)
	int nKeyLen = (fileKey.GetLength() - sizeof(long)) / sizeof(long);

	// 获取密钥
	pDiscryKey = new long[nKeyLen];
	if(NULL == pDiscryKey)
	{
		exit(1);
	}
	fileKey.Read(pDiscryKey, nKeyLen*sizeof(long));

	// 获取明文文件长度
	int nMFileLen = 0;
	fileKey.Read(&nMFileLen, sizeof(long));

	// 获取解密块大小
	int nBlockSize = (long)sqrt((double)nKeyLen);
	if(nBlockSize*nBlockSize != nKeyLen)
	{
		if(NULL != pDiscryKey)
		{
			delete pDiscryKey;
			pDiscryKey = NULL;
		}
		fileM.Close();
		fileE.Close();
		fileKey.Close();

		return;
	}

	// 获取解密块数
	int nBlockNum = fileE.GetLength() / nBlockSize;

	// 分配明文块和密文块空间
	char * pM = NULL; // 存放明文快
	char * pE = NULL; // 存放密文块
	int i = 0;
	pM = new char[nBlockSize];
	if(NULL == pM)
	{
		exit(1);
	}
	pE = new char[nBlockSize];
	if(NULL == pE)
	{
		exit(1);
	}

	//设置解密密钥
	CHillCode codeDiscryptor;
	CMatrix matrixDiscryptKey(pDiscryKey, nBlockSize, nBlockSize);
	codeDiscryptor.SetDiscryKey(matrixDiscryptKey);

	BeginWaitCursor();

	// 循环解密
	for(i=0; i<nBlockNum; i  )
	{
		fileE.Read(pE, nBlockSize);
		codeDiscryptor.SetE((const unsigned char *)pE, nBlockSize);
		memcpy(pM, codeDiscryptor.Discrypting(), nBlockSize);
		fileM.Write(pM, nBlockSize);
	}

	// 处理最后一块
	NULL;

	EndWaitCursor();

	// 结束处理
	if(NULL != pE)
	{
		delete pE;
		pE = NULL;
	}
	if(NULL != pM)
	{
		delete pM;
		pM = NULL;
	}
	if(NULL != pDiscryKey)
	{
		delete pDiscryKey;
		pDiscryKey = NULL;
	}
	fileM.Close();
	fileE.Close();
	fileKey.Close();
}

void CHillCodorDlg::OnButtonGetKey() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CFile fileM; // 明文
	CFileException fe;

	if(!fileM.Open(m_strUnMFilePath.GetBuffer(0), CFile::modeRead, &fe))
	{
		CString strError = "";
		strError.Format("Error!\r\nCan't open the file:%s\r\nCode: %d",
			m_strUnMFilePath.GetBuffer(0), fe.m_cause);
		AfxMessageBox(strError);
		return;
	}

	CFile fileE;  // 密文
	if(!fileE.Open(m_strUnEFilePath.GetBuffer(0), CFile::modeRead, &fe))
	{
		CString strError = "";
		strError.Format("Error!\r\nCan't open the file:%s\r\nCode: %d",
			m_strUnEFilePath.GetBuffer(0), fe.m_cause);
		AfxMessageBox(strError);
		return;
	}

	// 获取处理文件的大小
	int nFileLen = (fileM.GetLength() > fileE.GetLength())? fileE.GetLength(): fileM.GetLength();

	// 循环破译
	long lBlockSize = 1; // 处理块的大小
	long lLoop = nFileLen; // 在明文中找可逆的明文矩阵试探次数
	long lKeyLen = 1; // 密钥的长度
	const long BLOCK_SIZE_LIMIT = (long)sqrt(nFileLen);

	BeginWaitCursor();

	for(lBlockSize=1; lBlockSize<=BLOCK_SIZE_LIMIT; lBlockSize  )
	{
		// 重置文件指针
		fileM.SeekToBegin();
		fileE.SeekToBegin();

		// 获取猜测密文长度
		lKeyLen = lBlockSize * lBlockSize;
		
		// 初始化存储明文逆矩阵和密文矩阵
		CMatrix matrixM;  // 存储明文逆矩阵
		CMatrix matrixE;  // 存储密文矩阵
		matrixM.InitMatrix(lBlockSize, lBlockSize);
		matrixE.InitMatrix(lBlockSize, lBlockSize);
		char * szM = new char[lKeyLen];
		if(!szM)
		{
			exit(1);
		}
		char * szE = new char[lKeyLen];
		if(!szE)
		{
			exit(1);
		}
		int i = 0;
		lLoop = nFileLen / (lKeyLen);

		// 声明密钥矩阵
		CMatrix matrixKeyNew; // 存储最新获得的密钥
		CMatrix matrixKeyOld; // 存储上次循环获得的密钥

		for(i=0; i<lLoop; i  )
		{
			fileM.Read(szM, sizeof(char)*lBlockSize*lBlockSize);
			fileE.Read(szE, sizeof(char)*lBlockSize*lBlockSize);// 读取密文,并移动文件指针

			// 初始化明文逆矩阵
			int nRow = 0;
			int nCol = 0;
			for(nRow=0; nRow<lBlockSize; nRow  )
			{
				for(nCol=0; nCol<lBlockSize; nCol  )
				{
					matrixM.SetElement(nRow, nCol, (long)szM[nRow*lBlockSize nCol]);
				}
			}
			matrixM.Transpose();
			long lPhalanxValue = 0; 
			lPhalanxValue = matrixM.GetPhalanxValue();
			if(!lPhalanxValue || !(lPhalanxValue%2))
			{
				continue;
			}
			matrixM.Adjoint();
			matrixM = matrixM * Reciprocal(lPhalanxValue);
			matrixM.Mod(MAPLEN);
			
			// 初始化密文矩阵
			for(nRow=0; nRow<lBlockSize; nRow  )
			{
				for(nCol=0; nCol<lBlockSize; nCol  )
				{
					matrixE.SetElement(nRow, nCol, (long)szE[nRow*lBlockSize nCol]);
				}
			}
			matrixE.Transpose();

			// 获取新密钥
			matrixKeyNew = matrixE * matrixM;
			matrixKeyNew.Mod(MAPLEN);

			// 判断是否和上次求得的密钥是否相同
			if(matrixKeyOld.IsEmpty())
			{
				matrixKeyOld = matrixKeyNew;
			}
			else if(!(matrixKeyOld == matrixKeyNew))
			{// 该密钥长度是错误的
				break;
			}
		}
		if(szM)
		{
			delete szM;
			szM = NULL;
		}
		if(szE)
		{
			delete szE;
			szE = NULL;
		}

		// 显示密钥
		if(!matrixKeyOld.IsEmpty() && !matrixKeyNew.IsEmpty() && matrixKeyOld == matrixKeyNew)
		{
			long lValue = 0;
			int j = 0;
			char * szKey = new char[lKeyLen 1];
			if(!szKey)
			{
				exit(1);
			}
			memset(szKey, 0, lKeyLen 1);
			for(i=0; i<lBlockSize; i  )
			{
				for(j=0; j<lBlockSize; j  )
				{
					matrixKeyNew.GetElement(i, j, lValue);
					szKey[i*lBlockSize j] = (char)lValue;
				}
			}
			m_strUnKey = szKey;
			UpdateData(FALSE);
			if(szKey)
			{
				delete szKey;
				szKey = NULL;
			}
			break;
		}		
	}

	EndWaitCursor();

	// 结束处理
	fileM.Close();
	fileE.Close();
}

void CHillCodorDlg::OnButtonOpenMUn() 
{
	// TODO: Add your control notification handler code here
	// 提示选择打开文件路径
	
	CFileDialog dlg(TRUE, "txt", m_strUnMFilePath, OFN_HIDEREADONLY, 
		"txt文本文件 (*.txt) | *.txt|所有文件 (*.*) | *.*||", NULL);
	
	// 提示用户选择保存的路径
	if (dlg.DoModal() != IDOK)
	{
		// 返回
		return;
	}
	
	// 获取用户指定的文件路径
	m_strUnMFilePath = dlg.GetPathName();
	
	// 更新
	UpdateData(FALSE);
}

void CHillCodorDlg::OnButtonOpenEUn() 
{
	// TODO: Add your control notification handler code here
	// 提示选择打开文件路径
	
	CFileDialog dlg(TRUE, "txt", m_strUnEFilePath, OFN_HIDEREADONLY, 
		"txt文本文件 (*.txt) | *.txt|所有文件 (*.*) | *.*||", NULL);
	
	// 提示用户选择保存的路径
	if (dlg.DoModal() != IDOK)
	{
		// 返回
		return;
	}
	
	// 获取用户指定的文件路径
	m_strUnEFilePath = dlg.GetPathName();
	
	// 更新
	UpdateData(FALSE);
} 


标签: 密码 解密 加密

实例下载地址

希尔密码加密、解密和破密HillCodor

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警