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

📄 simpsub.cpp

📁 .net2003下写的多种加密加密算法的演示
💻 CPP
字号:
// SimpSub.cpp : 实现文件
//

#include "stdafx.h"
#include "LmCrypt.h"
#include "SimpSub.h"
#include ".\simpsub.h"


// CSimpSub 对话框

IMPLEMENT_DYNAMIC(CSimpSub, CDialog)
CSimpSub::CSimpSub(CWnd* pParent /*=NULL*/)
	: CDialog(CSimpSub::IDD, pParent)
	, str_subinput(_T(""))
	, list_sel(0)
	, sel_sel(0)
{
	DocLeft.RemoveAll();
	DocSel.RemoveAll();
}

CSimpSub::~CSimpSub()
{
}

void CSimpSub::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, str_subinput);
	DDV_MaxChars(pDX, str_subinput, 52);
	DDX_Control(pDX, IDC_LIST_DOC, lb_list);
	DDX_Control(pDX, IDC_LIST_SEL, lb_sel);
	DDX_LBIndex(pDX, IDC_LIST_DOC, list_sel);
	DDX_LBIndex(pDX, IDC_LIST_SEL, sel_sel);
}


BEGIN_MESSAGE_MAP(CSimpSub, CDialog)
	ON_EN_CHANGE(IDC_EDIT1, OnEnChangeEdit1)
	ON_BN_CLICKED(IDOK, OnBnClickedOk)
	ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
END_MESSAGE_MAP()


// CSimpSub 消息处理程序

BOOL CSimpSub::OnInitDialog()
{
	CDialog::OnInitDialog();
/*
	CFont *p_font;
	//CClientDC dc(this->GetDlgItem(IDC_STATIC));
	VERIFY(p_font->CreateFont(
   12,                        // nHeight
   0,                         // nWidth
   0,                         // nEscapement
   0,                         // nOrientation
   FW_NORMAL,                 // nWeight
   FALSE,                     // bItalic
   FALSE,                     // bUnderline
   0,                         // cStrikeOut
   ANSI_CHARSET,              // nCharSet
   OUT_DEFAULT_PRECIS,        // nOutPrecision
   CLIP_DEFAULT_PRECIS,       // nClipPrecision
   DEFAULT_QUALITY,           // nQuality
   DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
   (LPCTSTR)"Arial"));                 // lpszFacename

	this->GetDlgItem(IDC_STATIC)->SetFont(p_font);


	*/

	//::AfxGetApp()->m_pRecentFileList
	CDocManager * p_docm=::AfxGetApp()->m_pDocManager;

	   //p_docm->
	   //::AfxGetMainWnd()->get
	
	POSITION pos= ::AfxGetApp()->GetFirstDocTemplatePosition(); 
	 CDocTemplate *pTemplate = ::AfxGetApp()->GetNextDocTemplate(pos);
	 POSITION pos_doc;
     CDocument* m_doc;
	 int i_doccount=p_docm->GetOpenDocumentCount();
	pos_doc=pTemplate->GetFirstDocPosition();
	for(int j=0;j<i_doccount;j++){
		m_doc=pTemplate->GetNextDoc(pos_doc);
	   // m_doclist[j]=m_doc;
	
	    //CListBox * p_listdoc=(CListBox *)GetDlgItem(IDC_LIST_DOC);
		lb_list.AddString(m_doc->GetTitle());
		DocLeft.Add((CObject*)m_doc);

		//s_doc=pTemplate->GetNextDoc();
	}
	 str_sub=_T("a b c d e f g h e j k l m n o p q r s t u v w x y z");

	CEdit * p_edit=(CEdit *)this->GetDlgItem(IDC_EDIT1);
	p_edit->SetWindowText(str_sub);
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

void CSimpSub::OnEnChangeEdit1()
{
	// TODO:  如果该控件是 RICHEDIT 控件,则它将不会
	// 发送该通知,除非重写 CDialog::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。
	UpdateData();
    str_sub=str_subinput;
	UpdateData();
//subchar[]
	// TODO:  在此添加控件通知处理程序代码
}

void CSimpSub::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	
	Encyp();
	OnOK();
}


CHAR  CSimpSub::GetSub(CHAR buf)
{
	//int i;
	if(buf<=96&&buf>=61)
	{
	
		return subchar[buf-61];
	}
	else
	
		if(buf<=122&&buf>=97)
			return subchar[buf-97];
		else
		return buf;
}

int CSimpSub::Encyp(void)
{
	str_sub.MakeLower();
	for(int i=0;i<26;i++)
	{
		subchar[i]=str_sub.GetAt(i);
	}
	int i_doccount=DocSel.GetCount();
	for(int i=0;i<i_doccount;i++)
	{
		CDocument* m_subdoc=(CDocument*)DocSel.GetAt(i);
	
	CString str_path=m_subdoc->GetPathName();

	int ii=str_path.ReverseFind('.');

	CString str_newfile=str_path.Left(ii);
	str_newfile=str_newfile+"enc.txt";


	CFile f_cur,f_enc;
	CFileException ex;
   // open the source file for reading

   if (!f_cur.Open(str_path,
      CFile::modeRead | CFile::shareDenyWrite, &ex))
   {
      // complain if an error happened
      // no need to delete the ex object
      TCHAR szError[1024];
      ex.GetErrorMessage(szError, 1024);
     // cout << "Couldn't open source file: ";
      //cout << szError;
     
   }

   if (!f_enc.Open(str_newfile,
	   CFile::modeCreate|CFile::modeWrite , &ex))
   {
      // complain if an error happened
      // no need to delete the ex object
      TCHAR szError[1024];
      ex.GetErrorMessage(szError, 1024);
     // cout << "Couldn't open source file: ";
      //cout << szError;
     
   }
   

	ULONGLONG l_leng=f_cur.GetLength();
	CHAR buf[1];
	for(ULONGLONG i=0;i<l_leng;i++)
	{
	f_cur.Read(buf,1);
	
	buf[0]=GetSub(buf[0]);
	f_enc.Write(buf,1);


	}
	f_cur.Close();
	f_enc.Close();


	}
	return 1;
}

void CSimpSub::OnBnClickedButton2()
{
	UpdateData(true);
	if(lb_sel.GetCount()<1||sel_sel>=lb_sel.GetCount()||sel_sel<0)
		return;
	CString str_title;
	lb_sel.GetText(sel_sel,str_title);
	lb_list.AddString(str_title);
	
	DocLeft.Add(DocSel.GetAt(sel_sel));
	DocSel.RemoveAt(sel_sel);

	lb_sel.DeleteString(sel_sel);
	UpdateData(true);

}

void CSimpSub::OnBnClickedButton1()
{
	UpdateData(true);
	if(lb_list.GetCount()<1||list_sel>=lb_list.GetCount()||list_sel<0)
		return;
	CString str_title;
	lb_list.GetText(list_sel,str_title);
	lb_sel.AddString(str_title);
	
	DocSel.Add(DocLeft.GetAt(list_sel));
	DocLeft.RemoveAt(list_sel);
    lb_list.DeleteString(list_sel);
	UpdateData(true);
}

⌨️ 快捷键说明

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