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

📄 randomdlg.cpp

📁 1、对于凯撒密文
💻 CPP
字号:
// RandomDlg.cpp : implementation file
//

#include "stdafx.h"
#include "030300816.h"
#include "RandomDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CRandomDlg dialog


CRandomDlg::CRandomDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRandomDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRandomDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CRandomDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRandomDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRandomDlg, CDialog)
	//{{AFX_MSG_MAP(CRandomDlg)
	ON_BN_CLICKED(IDC_RESET, OnReset)
	ON_BN_CLICKED(IDC_ENCIPHER, OnEncipher)
	ON_BN_CLICKED(IDC_KEY, OnKey)
	ON_WM_SETCURSOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRandomDlg message handlers

void CRandomDlg::OnReset() 
{
	// TODO: Add your control notification handler code here
	SetDlgItemText(IDC_SUB,"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z");
	SetDlgItemText(IDC_PLAIN,"");
	SetDlgItemText(IDC_CIPHER,"");
	strcpy( dec , "abcdefghijklmnopqrstuvwxyz" );
}

void CRandomDlg::OnEncipher() 
{
	// TODO: Add your control notification handler code here
	char buffout[100000];
	CString m_cipherString , m_plainString;
	GetDlgItemText(IDC_PLAIN,m_plainString);
	int length = m_plainString.GetLength();
	buffout[length] = '\0';
	for ( int i = 0 ; i < length ; i ++ )
				{
		if((m_plainString[i]>='a')&&(m_plainString[i]<='z'))
			buffout[i]=dec[m_plainString[i]-'a'];
		else if((m_plainString[i]>='A')&&(m_plainString[i]<='Z'))
			buffout[i]=dec[m_plainString[i]-'A']-'a'+'A';
		else
			buffout[i]=m_plainString[i];
				}
				m_cipherString.Format( "%s" , buffout );
				SetDlgItemText(IDC_CIPHER,m_cipherString);
}

void CRandomDlg::OnKey() 
{
	// TODO: Add your control notification handler code here
	rndstr(dec);
	showkey();
}

BOOL CRandomDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_hArrow = AfxGetApp()->LoadCursor(IDC_MYARROW);
	m_hHand = AfxGetApp()->LoadCursor(IDC_MYHAND);
	m_hBeam = AfxGetApp()->LoadCursor(IDC_MYBEAM);
	m_hPen = AfxGetApp()->LoadCursor(IDC_MYPEN);
	m_hMove = AfxGetApp()->LoadCursor(IDC_MYMOVE);
	dec[26] = '\0';
	strcpy( dec , "abcdefghijklmnopqrstuvwxyz" );
	srand( time(&t) );//根据时间生成随机数起始点
	m_wndTaskbarNotifier->Show("欢迎进入随机代入法加密系统!\r\n本系统利用时间生成一个随机的对应关系,然后对明文进行加密!");
//	pSkin2->ApplySkin((long)m_hWnd);
	// TODO: Add extra initialization here
	
	// CG: The following block was added by the ToolTips component.	{		// Create the ToolTip control.		m_tooltip.Create(this);		m_tooltip.Activate(TRUE);		m_tooltip.AddTool(GetDlgItem(IDC_ENCIPHER), "对明文进行加密");
		m_tooltip.AddTool(GetDlgItem(IDC_RESET), "清空明文密文");
		m_tooltip.AddTool(GetDlgItem(IDC_CIPHER), "此处为密文");
		m_tooltip.AddTool(GetDlgItem(IDC_PLAIN), "请输入明文");
		m_tooltip.AddTool(GetDlgItem(IDC_KEY), "点击随机生成对应关系");		// TODO: Use one of the following forms to add controls:		// m_tooltip.AddTool(GetDlgItem(IDC_<name>), <string-table-id>);		// m_tooltip.AddTool(GetDlgItem(IDC_<name>), "<text>");	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CRandomDlg::rndstr(char *d)
{
	int i , j , k;
	char n;
	strcpy( d , "abcdefghijklmnopqrstuvwxyz" );
	i = ( rand() % 1000 ) + 100;//100-1000次的调整
	while( i-- )
	{ 
		j = rand() % 26;
		k = rand() % 26;
		if( j != k )
		{ 
			n = d[j];
			d[j] = d[k];
			d[k] = n;
		}
	}
}

void CRandomDlg::showkey()
{
	CString temp;
				//temp.Format("\n%.2lf %s\n",bestoverall,dec);
	temp.Format("%c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c" , 
		dec[0] , dec[1] , dec[2] , dec[3] , dec[4] ,
		dec[5] , dec[6] , dec[7] , dec[8] , dec[9] ,
		dec[10] , dec[11] , dec[12] , dec[13] , dec[14] ,
		dec[15] , dec[16] , dec[17] , dec[18] , dec[19] ,
		dec[20] , dec[21] , dec[22] , dec[23] , dec[24] ,
		dec[25]);
	temp.MakeUpper();
	SetDlgItemText(IDC_SUB , temp );
}

BOOL CRandomDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	// TODO: Add your message handler code here and/or call default
	if ( pWnd == GetDlgItem(IDC_RESET) 
		|| pWnd == GetDlgItem(IDC_ENCIPHER)
		|| pWnd == GetDlgItem(IDC_KEY)
		)
		::SetCursor(m_hHand);
	else if ( pWnd == GetDlgItem(IDC_PLAIN)
		|| pWnd == GetDlgItem(IDC_CIPHER)
		)
		::SetCursor(m_hBeam);
	else if ( nHitTest == HTCAPTION )
		::SetCursor(m_hMove);
	else
		::SetCursor(m_hArrow);
	return true;
	//return CDialog::OnSetCursor(pWnd, nHitTest, message);
}

BOOL CRandomDlg::PreTranslateMessage(MSG* pMsg)
{
	// CG: The following block was added by the ToolTips component.	{		// Let the ToolTip process this message.		m_tooltip.RelayEvent(pMsg);	}	return CDialog::PreTranslateMessage(pMsg);	// CG: This was added by the ToolTips component.
}

⌨️ 快捷键说明

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