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

📄 work.cpp.bak

📁 DES写的文件加密软件,可以用于对整个文件进行加密并且设定加密密码来网络传输!
💻 BAK
字号:
// work.cpp : Defines the entry point for the application.
//


#include "des.h"
#include "File.h"
#include "resource.h"
#include "Send.h"
#include "work.h"
//#include "yxyDES.h"

#include <winsock.h>
#include <commctrl.h>




char szFilePath[MAX_PATH];
char szFilePath2[MAX_PATH];

int flag=-1;
HANDLE hFile=NULL;


bool FileGo(HANDLE hFile);


BOOL CALLBACK DlgMainProc(
						  HWND hwndDlg,  // handle to dialog box
						  UINT uMsg,     // message
						  WPARAM wParam, // first message parameter
						  LPARAM lParam  // second message parameter
						  );
BOOL CALLBACK DlgAboutProc(
						  HWND hwndDlg,  // handle to dialog box
						  UINT uMsg,     // message
						  WPARAM wParam, // first message parameter
						  LPARAM lParam  // second message parameter
						  );

HINSTANCE hInst;

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	// TODO: Place code here.
	memset(szFilePath,0,MAX_PATH);
	memset(szFilePath2,0,MAX_PATH);

	hInst=hInstance;
	DialogBox(hInstance,MAKEINTRESOURCE(IDD_DES),NULL,(DLGPROC)DlgMainProc);
	
	
	//	MessageBox(NULL,str,NULL,MB_OK);
	
	return 0;
}


BOOL CALLBACK DlgMainProc(
						  HWND hwndDlg,  // handle to dialog box
						  UINT uMsg,     // message
						  WPARAM wParam, // first message parameter
						  LPARAM lParam  // second message parameter
						  )
{


//	key=new unsigned char [10];
	switch(uMsg)
	{
	case WM_INITDIALOG:

		return true;
	case WM_COMMAND:
		{
			WORD wmID=LOWORD(wParam);
			switch(wmID)
			{
			case IDC_JIA:
				flag=1;
				return true;
			case IDC_ABOUT:
				DialogBox(hInst,MAKEINTRESOURCE(IDD_ABOUT),NULL,(DLGPROC)DlgAboutProc);
			case IDC_JIE:
				flag=0;
				return true;
			case IDC_JIAMI:
			{
				if(FileGo(hFile))
					MessageBox(NULL,"加密解密成功!","",MB_OK);
				//	SetDlgItemText(hwndDlg,IDC_EDIT_SAVE,szFilePath2);
				//	SetDlgItemText(hwndDlg,IDC_EDIT_OPEN,szFilePath2);
				//	char szCmd[]="notepad.exe";
	/*				PROCESS_INFORMATION ProcessInformation;
					STARTUPINFO si;
					ZeroMemory(&si,sizeof(si));
					si.dwFlags=STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
					si.wShowWindow=SW_SHOWDEFAULT;
					
			//		strcat(szCmd,);
					CreateProcess(szCmd,szFilePath2,NULL,NULL,false,0,NULL,NULL,&si,&ProcessInformation);*/
				return true;
			}
			
			case IDC_OPEN:
				{
					if(OpenFileDlg(hwndDlg,szFilePath))
					SetDlgItemText(hwndDlg,IDC_EDIT_OPEN,szFilePath);
			
					hFile=CreateFile(szFilePath,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
					if(!hFile)
						MessageBox(hwndDlg,"打开文件失败","错误",MB_OK);
					return 1;
				}
			case IDC_SEND:
				DialogBox(hInst,MAKEINTRESOURCE(IDD_SEND),NULL,(DLGPROC)DlgSendProc);
				return true;
			case IDC_SAVE:
				if(SaveFileDlg(hwndDlg,szFilePath2))
					SetDlgItemText(hwndDlg,IDC_EDIT_SAVE,szFilePath2);
				return true;
			case IDC_EXIT:
				SendMessage(hwndDlg,WM_CLOSE,0,0);
				return true;	
			}
			break;
		}
	case WM_CLOSE:
		EndDialog(hwndDlg,0);
		return true;
	}
	return false;
}


bool FileGo(HANDLE hFile)
{
	if(flag==-1)
	{
		MessageBox(NULL,"请选择加解密方式","警告",MB_OK);
		return false;
	}
	if(strcmp(szFilePath,szFilePath2)==0)
	{
		MessageBox(NULL,"请输入源文件和目标文件路径!","警告",MB_OK);
		return false;
	}
	if(hFile==NULL)
		return false;
//		unsigned char key[]="liheying";
	char *buffer1,*buffer2;
	buffer1=new  char [20];
	buffer2=new  char [20];
	ZeroMemory(buffer1,20);
	ZeroMemory(buffer2,20);
	HWND hwnd=FindWindow(NULL,"Des加密解密");
	
	if(!GetDlgItemText(hwnd,IDC_KEY1,buffer1,20)|!GetDlgItemText(hwnd,IDC_KEY2,buffer2,20))

	{
		MessageBox(hwnd,"请输入密码","警告",MB_OK);
		return false;
	}

	if(strcmp(buffer1,buffer2)!=0)
	{
		MessageBox(hwnd,"两次输入的密钥不一样","警告",MB_OK);
		return false;
	}


	
	unsigned char *buf,*str;
	buf=new unsigned char [1024];
	str=new unsigned char [1024];
	ZeroMemory(buf,1024);
	ZeroMemory(str,1024);
	DWORD dwReaders=0,dwWrites=0;
	HANDLE hf=CreateFile(szFilePath2,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,0,NULL);
	ReadFile(hFile,buf,1024,&dwReaders,NULL);
	while(dwReaders)	
	{
		DesGo2(str,buf,dwReaders,(unsigned char *)buffer1,flag);

		WriteFile(hf,str,dwReaders,&dwWrites,NULL);
	//	ZeroMemory(buf,256);
	//	ZeroMemory(str,256);
		ReadFile(hFile,buf,1024,&dwReaders,NULL);

	}
	delete str;
	delete buf;
	delete buffer1;
	delete buffer2;
	CloseHandle(hf);
	CloseHandle(hFile);
	return true;
}
	/*
//	unsigned char key[]="liheying";
	yxyDES *my_des=new yxyDES();
	ZeroMemory(my_des,sizeof(my_des));
	my_des->InitializeKey("12345678");
	DWORD dwReaders=0,dwWrites=0;
	HANDLE hf=CreateFile(szFilePath2,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,0,NULL);
	if(flag==1)
	{
		ReadFile(hFile,my_des->szFPlaintextAnyLength,2560,&dwReaders,NULL);
		while(dwReaders)
		{
			
			my_des->EncryptAnyLength(my_des->szFPlaintextAnyLength);
			WriteFile(hf,my_des->szFCiphertextAnyLength,dwReaders,&dwWrites,NULL);
			ReadFile(hFile,my_des->szFPlaintextAnyLength,256,&dwReaders,NULL);
		}
	}
	else 
	{
		ReadFile(hFile,my_des->szFCiphertextAnyLength,2560,&dwReaders,NULL);
		while(dwReaders)
		{
			my_des->GetCiphertextAnyLength();
			my_des->DecryptAnyLength(my_des->szFCiphertextAnyLength);
			WriteFile(hf,my_des->szFPlaintextAnyLength,dwReaders,&dwWrites,NULL);
			ReadFile(hFile,my_des->szFPlaintextAnyLength,256,&dwReaders,NULL);
		}
	}
//	strcpy(str,my_des->szFCiphertextAnyLength);
//	my_des->DecryptAnyLength(my_des->szFCiphertextAnyLength);
//	strcpy(buf2,my_des->szFPlaintextAnyLength);
//	strcpy(buf2,my_des->szFPlaintextAnyLength);
/*	while(dwReaders)	
	{
//		DesGo(str,buf,dwReaders,key,flag);
		
		WriteFile(hf,str,dwReaders,&dwWrites,NULL);
		ReadFile(hFile,buf,255,&dwReaders,NULL);
		my_des->GetPlaintextAnyLength()

	}*//*
	delete my_des;
	CloseHandle(hf);
	CloseHandle(hFile);
	return true;
}
*/
BOOL CALLBACK DlgAboutProc(
						  HWND hwndDlg,  // handle to dialog box
						  UINT uMsg,     // message
						  WPARAM wParam, // first message parameter
						  LPARAM lParam  // second message parameter
						  )
{

	switch(uMsg)
	{
	case WM_INITDIALOG:
		return TRUE;
		
	case WM_COMMAND:
		if (LOWORD(wParam) == IDOK) 
		{
			SendMessage(hwndDlg,WM_CLOSE,0,0);
			return TRUE;
		}
		break;
	case WM_CLOSE:
		EndDialog(hwndDlg,0);
		return true;
	}
	return false;
}


BOOL CALLBACK DlgSendProc(
  HWND hwnd,  // handle to dialog box
  UINT uMsg,     // message
  WPARAM wParam, // first message parameter
  LPARAM lParam  // second message parameter
)
{
//	int m_flag=0;
	switch(uMsg)
	{
	case WM_INITDIALOG:
		EnableWindow(GetDlgItem(hwnd,IDC_SET),true);
		EnableWindow(GetDlgItem(hwnd,IDC_SEND),false);
		EnableWindow(GetDlgItem(hwnd,IDC_IPADDRESS),false);
		CheckRadioButton(hwnd,IDC_SEVER,IDC_CLIENT,IDC_SEVER);
		return true;
	case WM_COMMAND:
		{

			WORD wm=LOWORD(wParam);
			switch(wm)
			{
	/*		case IDC_SEND_OPEN:
				if(!OpenFileDlg(hwnd,szSendPath))
				SetDlgItemText(hwnd,IDC_EDIT_SEND_PATH,szSendPath);
				return true;*/
			case IDC_SEVER:
				EnableWindow(GetDlgItem(hwnd,IDC_SET),true);
				EnableWindow(GetDlgItem(hwnd,IDC_SEND),false);
				EnableWindow(GetDlgItem(hwnd,IDC_IPADDRESS),false);
				return true;
			case IDC_CLIENT:
				EnableWindow(GetDlgItem(hwnd,IDC_SET),false);
				EnableWindow(GetDlgItem(hwnd,IDC_SEND),true);
				EnableWindow(GetDlgItem(hwnd,IDC_IPADDRESS),true);
				return true;
			case IDC_SET:
			
				HANDLE hThread1;
				hThread1=CreateThread(NULL,0,SeverThread,NULL,0,NULL);
				CloseHandle(hThread1);
				return true;
			case IDC_SEND:
				HANDLE hThread2;
				hThread2=CreateThread(NULL,0,ClientThread,NULL,0,NULL);
				CloseHandle(hThread2);
				return true;

				
			}
		
		}
		break;
	case WM_CLOSE:
		EndDialog(hwnd,0);
		return true;

	}
	return false;
}




⌨️ 快捷键说明

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