// SecureTalkDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SecureTalk.h"
#include "SecureTalkDlg.h"
#include ".\securetalkdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CSecureTalkDlg dialog
CSecureTalkDlg::CSecureTalkDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSecureTalkDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSecureTalkDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT_G, m_Text_g);
DDX_Control(pDX, IDC_EDIT_N, m_Text_n);
DDX_Control(pDX, IDC_EDIT_X, m_Text_X);
DDX_Control(pDX, IDC_EDIT_Y, m_Text_Y);
DDX_Control(pDX, IDC_EDIT_K, m_Text_k);
DDX_Control(pDX, IDC_CHECK1, m_Sender);
DDX_Control(pDX, IDC_GEN_PUBLIC, m_Button_GenPubKey);
DDX_Control(pDX, IDC_SEND_INTERIM, m_Button_SenderInterim);
DDX_Control(pDX, IDC_RECV_INTERIM, m_Button_RecieverInterim);
}
BEGIN_MESSAGE_MAP(CSecureTalkDlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_GEN_PUBLIC, OnBnClickedGenPublic)
ON_BN_CLICKED(IDC_CHECK1, OnBnClickedCheck1)
ON_BN_CLICKED(IDC_SEND_INTERIM, OnBnClickedSendInterim)
ON_BN_CLICKED(IDC_RECV_INTERIM, OnBnClickedRecvInterim)
ON_BN_CLICKED(IDC_CREATE_KEY, OnBnClickedCreateKey)
END_MESSAGE_MAP()
// CSecureTalkDlg message handlers
BOOL CSecureTalkDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
m_Sender.SetCheck(1);
this->OnBnClickedCheck1();
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CSecureTalkDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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 function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSecureTalkDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CSecureTalkDlg::OnBnClickedGenPublic()
{
__int64 n = 0;
__int64 g = 0;
DH.CreateKeys(g,n);
char str_g[255] = {0};
char str_n[255] = {0};
sprintf_s( str_g, 255, "%I64d", g );
sprintf_s( str_n, 255, "%I64d", n );
m_Text_g.SetWindowText(str_g);
m_Text_n.SetWindowText(str_n);
}
void CSecureTalkDlg::OnBnClickedCheck1()
{
if (m_Sender.GetCheck())
{
this->m_Button_GenPubKey.EnableWindow();
this->m_Button_RecieverInterim.EnableWindow(FALSE);
this->m_Button_SenderInterim.EnableWindow();
}
else
{
this->m_Button_GenPubKey.EnableWindow(FALSE);
this->m_Button_RecieverInterim.EnableWindow();
this->m_Button_SenderInterim.EnableWindow(FALSE);
}
}
void CSecureTalkDlg::OnBnClickedSendInterim()
{
if ( DH.GetIsPublicKeyCreated() == false )
{
MessageBox(_T("The public keys need to be generated first"), _T("Oops!"), MB_ICONINFORMATION);
return;
}
__int64 SInterim = 0;
if ( DH.CreateSenderInterKey(SInterim) == 0 )
{
char strInterim[255] = {0};
sprintf_s( strInterim, 255, "%I64d", SInterim );
m_Text_X.SetWindowText(strInterim);
}
}
void CSecureTalkDlg::OnBnClickedRecvInterim()
{
__int64 SInterim = 0;
CString nStr;
CString gStr;
m_Text_n.GetWindowText(nStr);
m_Text_g.GetWindowText(gStr);
__int64 n = atoi(nStr);
__int64 g = atoi(gStr);
if (g==0 || n==0)
{
MessageBox(_T("The Generator and Modulus need to be filled from Sender Information"), _T("Oops!"), MB_ICONINFORMATION);
return;
}
DH.CreateRecipientInterKey(SInterim,g,n);
char strInterim[255] = {0};
sprintf_s(strInterim, 255, "%I64d", SInterim );
m_Text_Y.SetWindowText(strInterim);
}
void CSecureTalkDlg::OnBnClickedCreateKey()
{
__int64 SenderInterim = 0;
__int64 RecipientInterim = 0;
__int64 EncryptionKey = 0;
CString StrRecipientInterim;
CString StrSenderInterim;
m_Text_X.GetWindowText(StrSenderInterim);
m_Text_Y.GetWindowText(StrRecipientInterim);
SenderInterim = _atoi64(StrSenderInterim);
RecipientInterim = _atoi64(StrRecipientInterim);
if (m_Sender.GetCheck())
{
//SENDER
if ( DH.GetIsPublicKeyCreated() == false )
{
MessageBox(_T("The public keys need to be generated first"), _T("Oops!"), MB_ICONINFORMATION);
return;
}
if ( SenderInterim == 0 )
{
MessageBox(_T("The Sender Interim needs to be generated first"), _T("Oops!"), MB_ICONINFORMATION);
return;
}
if ( RecipientInterim == 0 )
{
MessageBox(_T("The Reciever Interim key needs to be supplied from the Reciever"), _T("Oops!"), MB_ICONINFORMATION);
return;
}
DH.CreateSenderEncryptionKey( EncryptionKey, RecipientInterim );
}
else
{
//RECIEVER
if ( DH.GetIsPublicKeyCreated() == false )
{
MessageBox(_T("The Generator and Modulus need to be filled from Sender Information"), _T("Oops!"), MB_ICONINFORMATION);
return;
}
if (SenderInterim == 0)
{
MessageBox(_T("The Sender Interim key needs to be supplied from the Sender"), _T("Oops!"), MB_ICONINFORMATION);
return;
}
if ( RecipientInterim == 0 )
{
MessageBox(_T("The Recipient Interim needs to be generated first"), _T("Oops!"), MB_ICONINFORMATION);
return;
}
DH.CreateRecipientEncryptionKey( EncryptionKey, SenderInterim );
}
char strKey[255] = {0};
sprintf_s( strKey, 255, "%I64d", EncryptionKey );
m_Text_k.SetWindowText(strKey);
}