Beispiel #1
0
void CCodeStringForm::OnEnChangeEditHexAnsi()
{
	UpdateData();

	//过滤输入的字符
	int nCheckHex = CStrCheckHex(m_strHexAnsi);
	if( -1 != nCheckHex )
	{
		m_strHexAnsi.Delete(nCheckHex);
		m_editHexAnsi.SetWindowText(m_strHexAnsi);
		m_editHexAnsi.SetSel(nCheckHex,nCheckHex,TRUE);
		return;
	}

	m_strNormal = AnsiHex2Text(m_strHexAnsi);

	UpdateData(FALSE);

	OnEnChangeEditStringNormal();

}
Beispiel #2
0
// DES加密过程
void CBlockDESForm::DoEncrypt()
{

	// 判断明文和密钥是否为空,为空则不计算。
	if((m_strPlainTextHex.IsEmpty())||(m_strKeyHex.IsEmpty())) 
	{
		m_strCipherText.Empty();
		m_strCipherTextHex.Empty();
		m_btnPrevPage.EnableWindow(FALSE);
		m_btnNext.EnableWindow(FALSE);
		m_ctrlPage.EnableWindow(FALSE);
		m_strPage.Empty();
		// 56位压缩密钥
		m_strKeyCompress.Empty();
		// Ci
		m_strCi.Empty();
		// Di
		m_strDi.Empty();
		// Ciplus
		m_strCiplus.Empty();
		// Diplus
		m_strDiplus.Empty();
		// LeftMove
		m_strLeftMove.Empty();
		// Ki
		m_strKi.Empty();
		// 64位明文初始置换
		m_strChushi.Empty();
		// Li
		m_strRi.Empty();
		// Di
		m_strLi.Empty();
		// Liplus
		m_strLiplus.Empty();
		// Riplus
		m_strRiplus.Empty();
		// RiXorKi
		m_strRiXorKi.Empty();
		// FRiKi
		m_strFRiKi.Empty();
		// FSbox
		m_strFSbox.Empty();
		// 终结置换前的密文
		m_strPlainEnd.Empty();


		UpdateData(FALSE);
		return;
	}

	// 刷新控件的成员变量
	UpdateData(TRUE);


	////////////////////////////////////////////////////////////////////////////////
	// 获取明文和密文,ANSI方式存储的二进制数据

	char szSourceKey[8],szPlaintextData[8];

	// 整理字符串
	memset(szSourceKey,0,8);
	memset(szPlaintextData,0,8);

	//将明文十六进制转换为ANSI方式存储的字符串
	for( int i = 0; i < m_strPlainTextHex.GetLength(); i+=2 )
	{
		CString strTemp=m_strPlainTextHex.Mid(i,2);
		int nhex = _tcstoul(strTemp, 0, 16);

		szPlaintextData[i/2]=nhex;
	}

	//将密钥十六进制转换为ANSI方式存储的字符串
	for( int i = 0; i < m_strKeyHex.GetLength(); i+=2 )
	{
		CString strTemp=m_strKeyHex.Mid(i,2);
		int nhex = _tcstoul(strTemp, 0, 16);

		szSourceKey[i/2]=nhex;
	}

	////////////////////////////////////////////////////////////////////////////////
	// DES加密

	m_pDES = new DES();

	// 导入密钥
	m_pDES->InitializeKey(szSourceKey,0);

	// 开始加密
	m_pDES->EncryptAnyLength(szPlaintextData,m_strPlainTextHex.GetLength()/2,0);// 不能传入字符串长度,因为数据块中0后面可能有数据。

	
	// 输出密文十六进制
	m_strCipherTextHex=m_pDES->GetCiphertextInHex();


	////////////////////////////////////////////////////////////////////////////////
	// 将十六进制转换成字符串
	if(FALSE == m_stateRadioAnsi)
	{

		// 以ANSI方式的转换密文十六进制为字符串
		m_strCipherText=AnsiHex2Text(m_strCipherTextHex);
	}
	else
	{
		// 以Unicode方式的转换密文十六进制为字符串
		m_strCipherText=UnicodeHex2Text(m_strCipherTextHex);
	}

	DesShow();

	UpdateData(FALSE);

}