【加密解密】对exe文件的加密解密 <含源代码》
来源:互联网 发布:沙钢网络培训密码 编辑:程序博客网 时间:2024/04/25 05:10
//编译环境VS2013#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>int getFileSize(char *path){FILE *pf = fopen(path, "r");if (pf == NULL){return-1;}else{fseek(pf, 0, SEEK_END); //文件指针移动到文件末尾int length = ftell(pf);return length;}}//字符串加密 char *stringEncrypt(char *password, char *string){int passLength = strlen(password); //获取加密长度 int stringLength = strlen(string); //获取字符串长度 if (stringLength%passLength == 0)//字符串长度是密码长度的整数倍 {int times = stringLength / passLength;for (int i = 0; i < times; i++){for (int j = 0; j < passLength; j++){string[i*passLength + j] ^= password[j];//这里的下标计算画图很容易理解 }}}else{int times = stringLength / passLength;for (int i = 0; i < times; i++){for (int j = 0; j < passLength; j++){string[i*passLength + j] ^= password[j];}}int lastLength = stringLength%passLength;//不能整除的,也就是余数长度 for (int i = 0; i < lastLength; i++){string[passLength*(stringLength / passLength) + i] ^= password[i];//这里的解密要从前边已经整除完成的后一个位置开始, //假如说stringLength = 10,passLength = 4;那么除不尽的加密就从下标8开始, //(10 / 4)*4 = 8. }}return string;}//字符串解密算法 char *stringDecode(char *password, char *string){int passLength = strlen(password); //获取加密长度 int stringLength = strlen(string); //获取字符串长度 if (stringLength % passLength == 0)//字符串长度是密码长度的整数倍 {int times = stringLength / passLength;for (int i = 0; i < times; i++){for (int j = 0; j < passLength; j++){string[i*passLength + j] ^= password[j];}}}else{int times = stringLength / passLength;for (int i = 0; i < times; i++){for (int j = 0; j < passLength; j++){string[i*passLength + j] ^= password[j];}}int lastLength = stringLength%passLength;//不能整除的,也就是余数长度 for (int i = 0; i < lastLength; i++){string[passLength*(stringLength / passLength) + i] ^= password[i];//这里的解密要从前边已经整除完成的后一个位置开始, //假如说stringLength = 10,passLength = 4;那么除不尽的加密就从下标8开始, //(10 / 4)*4 = 8. }}return string;}//加密void Encrypt(char *oldPath, char *newPath, char *password){FILE *pfr, *pfw;pfr = fopen(oldPath, "rb");//以二进制读取pfw = fopen(newPath, "wb");if (pfr == NULL || pfw == NULL){fclose(pfr);fclose(pfw);return;}else{int length = getFileSize(oldPath);//获取原文件大小char *p = malloc(length*sizeof(char));//为新文件申请空间fread(p, sizeof(char), length, pfr);//读取二进制到文件stringEncrypt(password, p);fwrite(p, sizeof(char), length, pfw);//写入二进制到文件//文件操作完成之后关闭文件fclose(pfr);fclose(pfw);}}//解密void decode(char *oldPath, char *newPath, char *password){FILE *pfr, *pfw;pfr = fopen(oldPath, "rb");//以二进制读取pfw = fopen(newPath, "wb");if (pfr == NULL || pfw == NULL){fclose(pfr);fclose(pfw);return;}else{int length = getFileSize(oldPath);//获取原文件大小char *p = malloc(length*sizeof(char));//为新文件申请空间fread(p, sizeof(char), length, pfr);//读取二进制到文件stringDecode(password, p);fwrite(p, sizeof(char), length, pfw);//写入二进制到文件//文件操作完成之后关闭文件fclose(pfr);fclose(pfw);}}void main(){char *oldPath = "F:\\My Program\\20160313心型动态图.exe";char *newPath = "F:\\My Program\\20160313心型动态图a_password.exe";char *newDePath = "F:\\My Program\\20160313心型动态图b_password.exe";int length = getFileSize(oldPath);char *password = "ABCDE";printf("%d\n", length);Encrypt(oldPath, newPath, password);decode(newPath, newDePath, password);system("pause");}
原exe文件执行效果
加密后不能打开
解密后,正常打开
0 0
- 【加密解密】对exe文件的加密解密 <含源代码》
- 【加密解密】 文件的加密解密 <含源代码>
- 【文件】EXE文件加密解密
- 【加密解密】对字符串的加密解密
- 文件的加密解密
- 使用aspnet_regiis.exe 对配置字节的加密解密选项
- 对文本文件的加密解密
- 对字符串的加密解密
- 加密-解密源代码
- Des 加密解密源代码
- 利用"流"实现exe文件的加密解密
- 简单的加密解密文件
- 文件的加密与解密
- 文件的加密和解密
- 简单的文件加密解密
- 解密由加密大师加密的文件
- 文件加密解密 URl参数加密解密
- 使用crypto api的加密解密源代码
- fragment界面重叠问题的终极解决方法
- UCOSIII任务管理(待更)
- Android Service重启
- Bzoj4538:[Hnoi2016]网络:整体二分+树状数组
- UCOSIII系统内部任务(待更)
- 【加密解密】对exe文件的加密解密 <含源代码》
- String类中常用方法归纳
- Python实现简单爬虫
- Android Orientation Sensor(方向传感器)详解与应用
- Spring中Bean的作用域
- LINUX C语言,在文本中某一行插入内容
- 如何调优JVM - 优化Java虚拟机(大全+实例)
- UCOSIII中断和时间管理(待更)
- 在已经安装cocoa pods的情况下,打开终端给指定工程配置第三方