C语言加密汉字、图片

// encryp.cpp : 定义控制台应用程序的入口点。

//

#include "stdafx.h"

#include <string.h>

#include <stdlib.h>

unsigned char doEncryp(const unsigned char* src, int srcLen, unsigned char* out_) {

if (!src || !srcLen || !out_)

return 0;

for (int i = 0; i < srcLen - 1; i += 2) {

out_i = srci + 1;

out_i + 1 = srci;

}

if (0 != srcLen % 2) {

out_srcLen - 1 = srcsrcLen - 1;

}

return 1;

}

int _tmain(int argc, _TCHAR* argv\[\])

{

while (1) {

printf("请输入指令,0:退出,1:加密汉字,2:加密图片:");

int cmd = 0;

scanf("%d", &cmd);

if (0 == cmd)

break;

if (1 == cmd) {

printf("请输入汉字:");

char swords4096 = { 0 };

scanf("%s", swords);

char result4096 = { 0 };

if (doEncryp((unsigned char*)swords, strlen(swords), (unsigned char*)result)) {

printf("加密后的汉字是:%s\r\n", result);

}

}

else if (2 == cmd) {

printf("请输入图片完整路径(比如:c:\\1.jpg):");

char picPath255 = { 0 };

scanf("%s", picPath);

FILE* fp = fopen(picPath, "rb");

if (!fp) {

printf("输入的文件路径不存在!!!\r\n");

}

else {

fseek(fp, 0, SEEK_END);

int fsize = ftell(fp);

fseek(fp, 0, SEEK_SET);

unsigned char* src = (unsigned char*)malloc(fsize);

unsigned char* dest = (unsigned char*)malloc(fsize);

fread(src, fsize, 1, fp);

fclose(fp);

if (doEncryp(src, fsize, dest)) {

char destFname255 = { 0 };

sprintf(destFname, "%s_加密", picPath);

FILE* fp2 = fopen(destFname, "wb");

fwrite(dest, fsize, 1, fp2);

fclose(fp2);

printf("加密后的图片已保存到:%s\r\n", destFname);

}

free(src);

free(dest);

}

}

}

return 0;

}

相关推荐
神一样的老师1 小时前
WS63 BLE 配网实战:用 Python 在 PC 上替代手机完成 WiFi 配网
开发语言·python·智能手机
geovindu2 小时前
python: Decision Tree
开发语言·后端·python·决策树
时间的情敌3 小时前
Three.js 工业场景性能优化合集|大批量管线、InstancedMesh 实例化、合并 Geometry、显存释放
开发语言·javascript·性能优化·three.js
Go-higher3 小时前
C语言--数据结构-栈、队列、堆
c语言·数据结构
步峰代理-盾山4 小时前
R语言爬虫实战:使用httr与XML解析网页数据并进行统计分析
xml·开发语言·爬虫·r语言·网络爬虫
sharemylove14 小时前
Java集合框架全面详解
java·开发语言·经验分享·笔记·学习
郝学胜-神的一滴18 小时前
Effective Python 条款43:自定义容器类
开发语言·windows·python·pandas·scikit-learn·pyqt
2601_9664923118 小时前
C语言变量揭秘
c语言·变量·编译器·线程安全·内存布局
好焊孙辉19 小时前
一条产线省下 30 个电机位:Z 轴和 R 轴,该合成一个了
开发语言·r语言
布莱克60519 小时前
Swift 中的逃逸闭包与非逃逸闭包:@escaping 到底在做什么
开发语言·ios·swift·闭包·逃逸