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

📄 crypt.txt

📁 包含MD5,SHA-1,DES,RSA的程序代码
💻 TXT
📖 第 1 页 / 共 5 页
字号:
poWnd = GetDlgItem(IDC_LBLHEX2); 
poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE); 
poWnd = GetDlgItem(IDC_EDITHEX2); 
poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE); 
} 
void CEncryAndDecryptDlg::MoveFileGroup() 
{ 
//获取y坐标 
CRect oRect; 
CWnd* poWnd; 
poWnd = GetDlgItem(IDC_BORDER); 
poWnd->GetWindowRect(&oRect); 
int iYRef = oRect.bottom; 
poWnd = GetDlgItem(IDC_LBLFILE); 
poWnd->GetWindowRect(&oRect); 
int iDelta = oRect.top - iYRef; 
//坐标转化 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
//设置各个控件的位置 
// 
poWnd = GetDlgItem(IDC_EDITFILE); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_BTNFILE); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_STATICBMPARROW1); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_BTNFILEDIGEST); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_LBLSTR1); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_EDITSTR1); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_BTNSAVEAS); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_LBLHEX1); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_EDITHEX1); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
} 
void CEncryAndDecryptDlg::MoveStringGroup() 
{ 
//获取y坐标 
CRect oRect; 
CWnd* poWnd; 
poWnd = GetDlgItem(IDC_BORDER); 
poWnd->GetWindowRect(&oRect); 
int iYRef = oRect.bottom; 
poWnd = GetDlgItem(IDC_LBLSTR); 
poWnd->GetWindowRect(&oRect); 
int iDelta = oRect.top - iYRef; 
//坐标转化 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
//设置各个控件的位置 
// 
poWnd = GetDlgItem(IDC_EDITALPHA); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_EDITHEX); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_RADALPHA); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_RADHEX); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_STATICBMPARROW2); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_BTNSTRINGDIGEST); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_LBLSTR2); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_EDITSTR2); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_LBLHEX2); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
// 
poWnd = GetDlgItem(IDC_EDITHEX2); 
poWnd->GetWindowRect(&oRect); 
ScreenToClient(oRect); 
poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER); 
} 

//点击浏览按钮 
void CEncryAndDecryptDlg::OnBtnfile() 
{ 
// TODO: Add your control notification handler code here 
CFileDialog m_FileOpen(TRUE); 
//设置打开窗体的标题 
   m_FileOpen.m_ofn.lpstrTitle = _T("打开文件"); 
   m_FileOpen.m_ofn.lpstrFilter = _T("文件 (*.*)\0*.*\0\0"); 
//点击浏览按钮 
if(IDOK == m_FileOpen.DoModal()) 
{ 
 //获取打开的文件路径 
 CString m_FileName = m_FileOpen.GetPathName(); 
 CEdit* pEdit = (CEdit*)(GetDlgItem(IDC_EDITFILE)); 
 //将选择的文件路径名显示到IDC_EDITFILE表识的EDIT中 
 pEdit->SetWindowText(m_FileName); 
} 
} 

//点击按钮保存 
void CEncryAndDecryptDlg::OnBtnsaveas() 
{ 
// TODO: Add your control notification handler code here 
CFileDialog oFileOpen(FALSE); 
//设置保存文件的标题 
   oFileOpen.m_ofn.lpstrTitle = _T("保存加密文件"); 
   oFileOpen.m_ofn.lpstrFilter = _T("文件格式 (*.txt)\0*.txt\0(*.*)\0*.*\0\0"); 
if(oFileOpen.DoModal() == IDOK) 
{ 
 //获取文件路径 
 CString oStrFileName = oFileOpen.GetPathName(); 
 oStrFileName += ".txt"; 
 CFile oFile; 
 //文件异常类,用于捕获文件异常 
 CFileException oFileException; 
 TCHAR szBuff[MAX_PATH+1]; 
 _tcscpy(szBuff, LPCTSTR(oStrFileName)); 
 //获取路径或文件名中的文件扩展名 
 CString pcExt = ::PathFindExtension(oStrFileName); 
 //创建文件来保存,以二进制形式来保存 
 BOOL bOpen = oFile.Open(oStrFileName, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary, &oFileException); 
 if(bOpen == TRUE) 
 { 
  //打开文件处理 
  char acDigest[65] = {0}; 
  CEdit* poEdit = (CEdit*)(GetDlgItem(IDC_EDITHEX1)); 
  CString oStrHex; 
  poEdit->GetWindowText(oStrHex); 
  int iLength; 
  switch(m_iMethod) 
  { 
   case DES: 
    AfxMessageBox("采用DES算法"); 
    break; 
   case MD5: 
    iLength = 16; 
    break; 
   case RSA: 
    AfxMessageBox("采用RSA算法"); 
    break; 
   default: 
    ASSERT(0); 
  } 
  Hex2Binary(LPCTSTR(oStrHex), reinterpret_cast<unsigned char*>(acDigest), iLength); 
  oFile.Write(acDigest, iLength); 
  oFile.Close(); 
  AfxMessageBox("保存文件成功!"); 
 } 
 else 
 { 
  AfxMessageBox("保存文件失败!"); 
 } 
} 
} 


//下面是16进制和字符以及二进制相互转化的全局函数 
//将字符转化为16进制 
void Char2Hex(unsigned char ch, char* szHex) 
{ 
static unsigned char saucHex[] = "0123456789ABCDEF"; 
szHex[0] = saucHex[ch >> 4]; 
szHex[1] = saucHex[ch&0xF]; 
szHex[2] = 0; 
} 

//将16进制数据转化为字符类型 
bool Hex2Char(char const* szHex, unsigned char& rch) 
{ 
if(*szHex >= '0' && *szHex <= '9') 
 rch = *szHex - '0'; 
else if(*szHex >= 'A' && *szHex <= 'F') 
 rch = *szHex - 55; 
else 
 //不是16进制数据 
 return false; 
szHex++; 
if(*szHex >= '0' && *szHex <= '9') 
 (rch <<= 4) += *szHex - '0'; 
else if(*szHex >= 'A' && *szHex <= 'F') 
 (rch <<= 4) += *szHex - 55; 
else 
 //不是16进制数据 
 return false; 
return true; 
} 

//将二进制数据转化为16进制数据 
void Binary2Hex(unsigned char const* pucBinStr, int iBinSize, char* pszHexStr) 
{ 
int i; 
char szHex[3]; 
unsigned char const* pucBinStr1 = pucBinStr; 
*pszHexStr = 0; 
for(i=0; i<iBinSize; i++,pucBinStr1++) 
{ 
 Char2Hex(*pucBinStr1, szHex); 
 strcat(pszHexStr, szHex); 
} 
} 

//将16进制转化为2进制 
bool Hex2Binary(char const* pszHexStr, unsigned char* pucBinStr, int iBinSize) 
{ 
int i; 
unsigned char ch; 
for(i=0; i<iBinSize; i++,pszHexStr+=2,pucBinStr++) 
{ 
 if(false == Hex2Char(pszHexStr, ch)) 
  return false; 
 *pucBinStr = ch; 
} 
return true; 
} 

BOOL CEncryAndDecryptDlg::OnInitDialog() 
{ 
CDialog::OnInitDialog(); 

// Add "About..." menu item to system menu. 

// IDM_ABOUTBOX must be in the system command range. 
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); 
ASSERT(IDM_ABOUTBOX < 0xF000); 

CMenu* pSysMenu = GetSystemMenu(FALSE); 
if (pSysMenu != NULL) 
{ 
 CString strAboutMenu; 
 strAboutMenu.LoadString(IDS_ABOUTBOX); 
 if (!strAboutMenu.IsEmpty()) 
 { 
  pSysMenu->AppendMenu(MF_SEPARATOR); 
  pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); 
 } 
} 

// 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_oMenu.LoadMenu(IDR_MENU); 
SetMenu(&m_oMenu); 

//对控件颜色进行显示 
m_oEditDES.SubclassDlgItem(IDC_EDITDES,this); 
m_oEditP.SubclassDlgItem(IDC_EDITP,this); 
m_oEditQ.SubclassDlgItem(IDC_EDITQ,this); 
m_oEditFile.SubclassDlgItem(IDC_EDITFILE, this); 
m_oEditStr1.SubclassDlgItem(IDC_EDITSTR1, this); 
m_oEditHex1.SubclassDlgItem(IDC_EDITHEX1, this); 
m_oEditAlpha.SubclassDlgItem(IDC_EDITALPHA, this); 
m_oEditHex.SubclassDlgItem(IDC_EDITHEX, this); 
m_oEditStr2.SubclassDlgItem(IDC_EDITSTR2, this); 
m_oEditHex2.SubclassDlgItem(IDC_EDITHEX2, this); 

//对控件进行提示,便于用户进行输入 
if(!m_oToolTipCtrl.Create(this)) 
{ 
 TRACE("\nUnable to create ToolTip control");//创建失败 
} 
else 
{ 
 //添加提示信息 
 m_oToolTipCtrl.AddTool(&m_oEditDES,IDS_EDITDES); 
 m_oToolTipCtrl.AddTool(&m_oEditP,IDS_EDITP); 
 m_oToolTipCtrl.AddTool(&m_oEditQ,IDS_EDITQ); 
 m_oToolTipCtrl.AddTool(&m_oEditFile,IDS_EDITFILE); 
 m_oToolTipCtrl.AddTool(&m_oEditStr1,IDS_EDITSTR1); 
 m_oToolTipCtrl.AddTool(&m_oEditHex1,IDS_EDITHEX1); 
 m_oToolTipCtrl.AddTool(&m_oEditAlpha,IDS_EDITALPHA); 
 m_oToolTipCtrl.AddTool(&m_oEditHex,IDS_EDITHEX); 
 m_oToolTipCtrl.AddTool(&m_oEditStr2,IDS_EDITSTR2); 
 m_oToolTipCtrl.AddTool(&m_oEditHex2,IDS_EDITHEX2); 
 //激活控件 
 m_oToolTipCtrl.Activate(TRUE); 
} 
//初始化显示文件面板 
CRect oRect, oRectDlg; 
CWnd* poWnd = GetDlgItem(IDC_EDITHEX1); 
poWnd->GetWindowRect(&oRect); 
GetWindowRect(&oRectDlg); 
SetWindowPos(NULL, 0, 0, oRectDlg.Width(), oRect.bottom-oRectDlg.top+15, SWP_NOMOVE|SWP_NOZORDER);//通过设置窗体位置来确定文件面板 
//初始化单选框 
CButton* poButton; 
poButton = (CButton*)(GetDlgItem(IDC_RADFILE));//或者使用poButton = reinterpret_cast<CButton*>(GetDlgItem(IDC_RADFILE)); 
poButton->SetCheck(1); 
poButton = (CButton*)(GetDlgItem(IDC_RADALPHA));//或者使用poButton = reinterpret_cast<CButton*>(GetDlgItem(IDC_RADALPHA)); 
poButton->SetCheck(1); 
poButton = (CButton*)(GetDlgItem(IDC_RADENCRYPT));//或者使用poButton = reinterpret_cast<CButton*>(GetDlgItem(IDC_RADENCRYPT)); 
poButton->SetCheck(1); 
//初始化组合框 
CComboBox* poComboBox; 
poComboBox = (CComboBox*)(GetDlgItem(IDC_COMBO_METHODS));//或者使用poComboBox = static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_METHODS)); 
poComboBox->SetCurSel(0); 

//显示位图资源 
m_oBMP1.LoadBitmap(IDB_BMPDOWN); 
m_oBMP2.LoadBitmap(IDB_BMPUP); 
//对文件面板的位图进行显示 
m_oTransparentBitmap1.SubclassDlgItem(IDC_STATICBMPARROW1, this); 
m_oTransparentBitmap1.Initialize(HBITMAP(m_oBMP1), RGB(255,255,255), 1.0, 1.0); 
//对字符串面板的位图进行显示 
m_oTransparentBitmap2.SubclassDlgItem(IDC_STATICBMPARROW2, this); 
m_oTransparentBitmap2.Initialize(HBITMAP(m_oBMP1), RGB(255,255,255), 1.0, 1.0); 

return TRUE;  // return TRUE  unless you set the focus to a control 
} 

//通过处理鼠标事件来添加提示控件处理信息 
BOOL CEncryAndDecryptDlg::PreTranslateMessage(MSG* pMsg) 
{ 
// TODO: Add your specialized code here and/or call the base class 
//通过鼠标来显示提示信息 
m_oToolTipCtrl.RelayEvent(pMsg); 
return CDialog::PreTranslateMessage(pMsg); 
} 

void CEncryAndDecryptDlg::OnKickIdle() 
{ 
   //Call this member function to update the state of dialog buttons and other controls 
   //in a dialog box or window that uses the ON_UPDATE_COMMAND_UI callback mechanism 
UpdateDialogControls( this, FALSE ); 
} 

void CEncryAndDecryptDlg::OnSysCommand(UINT nID, LPARAM lParam) 
{ 
if ((nID & 0xFFF0) == IDM_ABOUTBOX) 
{ 
 CAboutDlg dlgAbout; 
 dlgAbout.DoModal(); 
} 
else 
{ 
 CDialog::OnSysCommand(nID, lParam); 
} 
} 

// 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 CEncryAndDecryptDlg::OnPaint() 
{ 
if (IsIconic()) 
{ 
 CPaintDC dc(this); // device context for painting 

 SendMessage(WM_ICONERASEBKGND, (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 to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CEncryAndDecryptDlg::OnQueryDragIcon() 
{ 
return (HCURSOR) m_hIcon; 
} 

//处理退出菜单事件 

⌨️ 快捷键说明

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