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

📄 clientdlg.cpp

📁 单点登录源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	}
	else
	{
		Encrypt(m_szSendBuffer,szKeyAB);
	}
	send(m_sockClient,m_szSendBuffer,(int)strlen(m_szSendBuffer)+1,0);
	m_szRecBuffer[0] = '\0';
	recv(m_sockClient,m_szRecBuffer,500,0);
	if(m_szRecBuffer[0])
	{
		CString sRec(m_szRecBuffer);
		if(sRec.Find(_T("p4"))!=-1 || sRec.Find(_T("P4"))!=-1)//Alice
		{
			sRec = sRec.Mid(3);
			sLeft = sRec.Left(sRec.Find(',',sRec.Find(',')+1));
			//AfxMessageBox(sLeft+_T("\r\n"));
			sRight = sRec.Mid(sRec.Find(',',sRec.Find(',')+1)+1);
			//AfxMessageBox(sRight+_T("\r\n"));
			CString2Char(szLeft,500,sLeft);
			CString2Char(szRight,500,sRight);
			Decrypt(szLeft,szKeyS);
			GetKey(szLeft,szKeyAB);
			strcpy(szSendToBob,szRight);
			m_sGet += _T("\r\n已接收TGS验证信息");
		}
		else if(sRec.Find(_T("p2"))!=-1 || sRec.Find(_T("P2"))!=-1)//Alice
		{
			sRec = sRec.Mid(3);
			sLeft = sRec.Left(sRec.Find(','));
			//AfxMessageBox(sLeft+_T("\r\n"));
			sRight = sRec.Mid(sRec.Find(',')+1);
			//AfxMessageBox(sRight+_T("\r\n"));
			CString2Char(szLeft,500,sLeft);
			CString2Char(szRight,500,sRight);
			CString2Char(szMyKey,7,m_sSelfKey);
			Decrypt(szLeft,szMyKey);
			strcpy(szKeyS,szLeft);
			Decrypt(szRight,szMyKey);
			strcpy(szSendToTGS,szRight);
			m_sGet += _T("\r\n已通过AS验证");
		}
		else if(sRec.Find(_T("p6"))!=-1 || sRec.Find(_T("P6"))!=-1)//Alice
		{
			sRec = sRec.Mid(3);
			CString2Char(szLeft,500,sRec);
			Decrypt(szLeft,szKeyAB);
			Decrypt(szTime,szKeyAB);
			TimeIncreator(szTime);
			if(strcmp(szTime,szLeft) == 0)
			{
				m_sGet += _T("\r\n开始进行通信:");
			}
			else
			{
				m_sGet += _T("\r\n时间戳错误!");
			}
		}
		UpdateData(FALSE);
	}
	closesocket(m_sockClient);
}	


void CClientDlg::OnBnClickedButton4()
{
	// TODO: 在此添加控件通知处理程序代码
	m_sGet = _T("监听端已启动");
	UpdateData(FALSE);
	CreateThread(NULL,0,ThreadProc,(LPVOID)this,0,NULL);
}

void CClientDlg::OnEnChangeEdit3()
{
	// TODO:  如果该控件是 RICHEDIT 控件,则它将不会
	// 发送该通知,除非重写 CDialog::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
	UpdateData(TRUE);
}

void CClientDlg::OnEnChangeEdit4()
{
	// TODO:  如果该控件是 RICHEDIT 控件,则它将不会
	// 发送该通知,除非重写 CDialog::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
	UpdateData(TRUE);
}

int CClientDlg::CharLen(char* lpszStr)
{
	int nResult = 0;

	while(lpszStr[nResult] != '\0')
	{
		nResult++;
	}

	return nResult;
}

LRESULT CClientDlg::MyUpdatedata(WPARAM wParam, LPARAM lParam)
{
	UpdateData(FALSE);
	return S_OK;
}
void CClientDlg::OnEnChangeEdit5()
{
	// TODO:  如果该控件是 RICHEDIT 控件,则它将不会
	// 发送该通知,除非重写 CDialog::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
	UpdateData(TRUE);
}

void CClientDlg::OnEnChangeEdit6()
{
	// TODO:  如果该控件是 RICHEDIT 控件,则它将不会
	// 发送该通知,除非重写 CDialog::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
	int i;

	UpdateData(TRUE);

	if(m_sSelfKey.GetLength() > 6)
	{
		AfxMessageBox(_T("密钥位数只能是6位"));
		m_sSelfKey = "";
		UpdateData(FALSE);
	}
	else if(m_sSelfKey.GetLength() == 6)
	{
		for(i=0;i<m_sSelfKey.GetLength();i++)
		{
			if(m_sSelfKey.GetAt(i) != '0' && m_sSelfKey.GetAt(i) != '1' && m_sSelfKey.GetAt(i) != '2' && m_sSelfKey.GetAt(i) != '3' && m_sSelfKey.GetAt(i) != '4' && m_sSelfKey.GetAt(i) != '5' && m_sSelfKey.GetAt(i) != '6' && m_sSelfKey.GetAt(i) != '7' && m_sSelfKey.GetAt(i) != '8' && m_sSelfKey.GetAt(i) != '9')
			{
				AfxMessageBox(_T("密钥位数只能由数字构成"));
				m_sSelfKey = "";
				UpdateData(FALSE);
			}
		}
	}
}

void Decrypt(char* strCypherText,char* strKey)
{
	int i,nKey;

	nKey = atoi(strKey);
	for(i=0;i<(int)strlen(strCypherText);i++)
	{
		if(strCypherText[i]>='0' && strCypherText[i]<='9')
		{//数字
			if(strCypherText[i]-(nKey%26)%10<'0')
			{
				strCypherText[i] = strCypherText[i]-(nKey%26)%10+10;
			}
			else
			{
				strCypherText[i] = strCypherText[i]-(nKey%26)%10;
			}
		}
		else if(strCypherText[i]>='A' && strCypherText[i]<='Z')
		{//大写字母
			if(strCypherText[i]-nKey%26<'A')
			{
				strCypherText[i] = strCypherText[i]-nKey%26+26;
			}
			else
			{
				strCypherText[i] = strCypherText[i]-nKey%26;
			}
		}
		else if(strCypherText[i]>='a' && strCypherText[i]<='z')
		{//小写字母
			if(strCypherText[i]-nKey%26<'a')
			{
				strCypherText[i] = strCypherText[i]-nKey%26+26;
			}
			else
			{
				strCypherText[i] = strCypherText[i]-nKey%26;
			}
		}
	}
	return;
}

void Encrypt(char* strPlainText,char* strKey)
{
	int i,nKey;

	nKey = atoi(strKey);
	for(i=0;i<(int)strlen(strPlainText);i++)
	{
		if(strPlainText[i]>='0' && strPlainText[i]<='9')
		{//数字
			if(strPlainText[i]+(nKey%26)%10>'9')
			{
				strPlainText[i] = strPlainText[i]+(nKey%26)%10-10;
			}
			else
			{
				strPlainText[i] = strPlainText[i]+(nKey%26)%10;
			}
		}
		else if(strPlainText[i]>='A' && strPlainText[i]<='Z')
		{//大写字母
			if(strPlainText[i]+nKey%26>'Z')
			{
				strPlainText[i] = strPlainText[i]+nKey%26-26;
			}
			else
			{
				strPlainText[i] = strPlainText[i]+nKey%26;
			}
		}
		else if(strPlainText[i]>='a' && strPlainText[i]<='z')
		{//小写字母
			if(strPlainText[i]+nKey%26>'z')
			{
				strPlainText[i] = strPlainText[i]+nKey%26-26;
			}
			else
			{
				strPlainText[i] = strPlainText[i]+nKey%26;
			}
		}
	}
	return;
}

void CString2Char(char* lpStr,int nLen,CString s)
{
	int i;

	for(i=0;i<s.GetLength()&&i<nLen-1;i++)
	{
		lpStr[i] = s.GetAt(i);
	}
	lpStr[i] = '\0';
	return;
}

void GetKey(const char* szLeft,char* szKey)
{
	int i,j;
	BOOL bStart = FALSE;

	j=0;
	for(i=0;i<(int)strlen(szLeft);i++)
	{
		if(bStart)
		{
			szKey[j] = szLeft[i];
			j++;
		}
		if(szLeft[i] == ',')
		{
			bStart = TRUE;
		}
	}
	szKey[j] = '\0';
}

void GetName(const char* szLeft,char* szName)
{
	int i;

	for(i=0;i<(int)strlen(szLeft);i++)
	{
		if(szLeft[i] == ',')
		{
			break;
		}
		szName[i] = szLeft[i];
	}
	szName[i] = '\0';
	return;
}

void TimeIncreator(char* lpszTime)
{
	if(lpszTime[4] == '5'&& lpszTime[5] == '9')
	{
		lpszTime[4] = '0';
		lpszTime[5] = '0';
		if(lpszTime[2] == '5' && lpszTime[3] == '9')
		{
			lpszTime[2] = '0';
			lpszTime[3] = '0';
			if(lpszTime[0] == '2' && lpszTime[1] == '3')
			{
				lpszTime[0] = '0';
				lpszTime[1] = '0';
			}
			else
			{
				lpszTime[1] += 1;
				if(lpszTime[1]>'9')
				{
					lpszTime[1] -= 10;
					lpszTime[0] += 1;
				}
			}
		}
		else
		{
			lpszTime[3] += 1;
			if(lpszTime[3]>'9')
			{
				lpszTime[3] -= 10;
				lpszTime[2] += 1;
			}
		}
	}
	else
	{
		lpszTime[5] += 1;
		if(lpszTime[5]>'9')
		{
			lpszTime[5] -= 10;
			lpszTime[4] += 1;
		}
	}
	return;
}

void GetTime(char* lpszTime)
{
	SYSTEMTIME SysTime;

	GetLocalTime(&SysTime);
	if(SysTime.wHour<10)
	{
		lpszTime[0] = '0';
		itoa(SysTime.wHour,lpszTime+1,10);
	}
	else
	{
		itoa(SysTime.wHour,lpszTime,10);
	}
	if(SysTime.wMinute<10)
	{
		lpszTime[2] = '0';
		itoa(SysTime.wMinute,lpszTime+3,10);
	}
	else
	{
		itoa(SysTime.wMinute,lpszTime+2,10);
	}
	if(SysTime.wSecond<10)
	{
		lpszTime[4] = '0'; 
		itoa(SysTime.wSecond,lpszTime+5,10);
	}
	else
	{
		itoa(SysTime.wSecond,lpszTime+4,10);
	}
	lpszTime[6] = '\0';

	return;
}
void CClientDlg::OnEnChangeEdit7()
{
	// TODO:  如果该控件是 RICHEDIT 控件,则它将不会
	// 发送该通知,除非重写 CDialog::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
	UpdateData(TRUE);
}

⌨️ 快捷键说明

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