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

📄 filemain.c

📁 这是能将文件进行加密的一个工具
💻 C
字号:
///////////////////////////////////////////////////////////////////////////////
//
//  文	件: FileMain.c
//		主函数
//
//  作  者: 江南孤峰 
//  联  系:QQ: 403324669   
//  时  间: 2007--3--3
//
///////////////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <direct.h>
#include <io.h>
#include <time.h>
#include <conio.h>
#include "FilePass.h"

// 全局变量
int	iBackupProgram = ON;		   // 备分器开关
char	strBackupDirect[_MAX_PATH] = {""}; // 存储备分目录,即加密器所在目录

// 显示功能菜单
void	ShowFunctionMenu(void){
	printf("=========================== 功 能 菜 单 ===========================\n");
	printf("%-36s%-36s\n"," 1: 手动加密单个文件",
			      " 2: 手动解密单个文件");
	printf("%-36s%-36s\n"," 3: 自动加密当前目录里的所有文件",
			      " 4: 自动解密当前目录里的所有文件");
	printf("%-36s%-36s\n"," 5: 递归加密指定目录下的所有文件",
			      " 6: 递归解密指定目录下的所有文件");
	printf("%-36s%-36s\n"," 7: 自动加密我的电脑里的所有文件",
			      " 8: 自动解密我的电脑里的所有文件");
	printf("%-36s%-36s\n"," 9: 修改加密器配制",
			      "10: 恢复被加密文件至原始位置");
	printf("%-36s\n",     "11: 退出程序");
	printf("====================================================================\n");
	printf("选择你要执行的操作:");
}

// 主函数
int main(void){
	char	strFileName[FILE_LENGTH+6] = {""};
	char	strAddFileSuffix[FILE_SUFFIX_LENGTH] = {".txt"};
	char	strFreeFileSuffix[FILE_SUFFIX_LENGTH] = {".pass"};
	char    strDES[DES_LENGTH + 2] = {""}; 
	char	strPass[PASS_LENGTH + 2] = {""};
	char	strPartition[10] = {""}; 
	int	iUserCmd = 0;
	int	iContinueFlag = TRUE;
	int	iDrivers = 0;
	int	count = 0;
	int	nFileDealMethod = DELETE_PASS_SOURCE_FILE;
	
	printf("********************************************************************\n");
	printf("\t简 单 文 本 文 件 加 密 器 ( DOS版 )\n");
	printf("\t作   者: 江 南 孤 峰 [ QQ:403324669 ]\n");
	printf("\t时   间: 2007 -- 3 -- 7\n");
	printf("********************************************************************\n");

	_getcwd(strBackupDirect,_MAX_PATH);
	strcat(strBackupDirect,"\\backup");
	CreateBackupDirectAndFile();

	while(iContinueFlag == TRUE){
		ShowMenu(strAddFileSuffix,strFreeFileSuffix,nFileDealMethod);
		scanf("%d",&iUserCmd);
		getchar();
		if(iUserCmd < 9 && iUserCmd > 0){
			if( (iUserCmd % 2) && 
			    (GetFilePassDES(strPass,strDES,ADD_PASS) == FAILED) )
				continue;
			else if( !(iUserCmd % 2) && 
				 (GetFilePassDES(strPass,strDES,FREE_PASS) == FAILED) )
				continue;
		}
		switch(iUserCmd){
			case 1:	// 手动加密文件
				printf("请输入欲加密的文件名:");
				if( GetUserInputFileName(strFileName)==SUCCESS &&	
				    AddPassForFile(	   
					strFileName,	   
					strAddFileSuffix,  
					strFreeFileSuffix,
					strPass,	  
					strDES		  
				    ) == SUCCESS
				 ){
					printf("文件 %s 加密完成\n",strFileName);
					MyDeleteFile(strFileName,nFileDealMethod,ADD_PASS);
				}
				else
					printf("文件 %s 加密失败\n",strFileName);
				break;
			case 2:	// 手动解密文件
				printf("请输入欲解密的文件名:");
				if( GetUserInputFileName(strFileName) == SUCCESS &&
				    FreePassForFile(
					strFileName,
					strFreeFileSuffix,
					strPass,
					strDES
				    ) == SUCCESS 
				  ){
					printf("文件 %s 解密完成\n",strFileName);
					MyDeleteFile(strFileName,nFileDealMethod,FREE_PASS);
				}
				else
					printf("文件 %s 解密失败\n",strFileName);
				break;
			case 3: // 自动加密当前目录里的所有文件
				count = AutoAddPassForCurrentDirFile(
					strAddFileSuffix,
					strFreeFileSuffix,
					nFileDealMethod,
					strPass,
					strDES
				);
				printf("\n共加密文件: %d \n",count);
				break;
			case 4: // 自动解密当前目录里的所有文件
				count = AutoFreePassForCurrentDirFile(
					strFreeFileSuffix,
					nFileDealMethod,
					strPass,
					strDES
				);
				printf("\n共解密文件: %d \n",count);
				break;
			case 5:// 递归加密指定目录下的所有文件
				if(ChangeCurrentDirect() == SUCCESS){ 	
					count = AutoAddPassForUserDefDirFile(
						strAddFileSuffix,
						strFreeFileSuffix,
						nFileDealMethod,
						strPass,
						strDES
					);
					printf("\n共加密文件: %d \n",count);
				}
				break;
			case 6:// 递归解密指定目录下的所有文件
				if(ChangeCurrentDirect() == SUCCESS){			
					count = AutoFreePassForUserDefDirFile(
						strFreeFileSuffix,
						nFileDealMethod,
						strPass,
						strDES
					);
					printf("\n共解密文件: %d \n",count);
				}
				break;
			case 7:// 加密我的电脑里的所有文件
				if(iBackupProgram == OFF){
					puts("备分器处于关闭状态,为了安全,请先打开备分器 !");
					break;
				}
				count = AutoAddPassForAllFile(
						strAddFileSuffix,
						strFreeFileSuffix,
						nFileDealMethod,
						strPass,
						strDES
					);
				printf("\n共加密文件: %d \n",count);
				break;
			case 8: // 解密我的电脑里的所有文件
				count = AutoFreePassForAllFile(
						strFreeFileSuffix,
						nFileDealMethod,
						strPass,
						strDES
					);
				printf("\n共解密文件: %d \n",count);
				break;
			case  9: // 修改加密器的配制
				UpdateProgramStation(
					strAddFileSuffix,
					strFreeFileSuffix,
					&nFileDealMethod
				);
				break;
			case 10: // 从备分目录中恢复被加密文件到原位置
				GetBackFile(strAddFileSuffix,strFreeFileSuffix);
				break;
			case 11: // 结束程序
				iContinueFlag = FALSE;
				break;
			default:
				printf("\n错误:没有该选项 !\n");
				break;
		}
		iUserCmd = -1;	// 清除原输入
		system("pause");
	}
	return SUCCESS;
}
		

⌨️ 快捷键说明

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