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;

}

相关推荐
benchmark_cc5 小时前
如何用 Python + QuantDash 快速构建高胜率“配对交易(Pairs Trading)”策略?
开发语言·人工智能·python·pandas·量化交易·quantdash
程序员无隅6 小时前
Coding Agent 为什么压缩上下文后还能继续工作?上下文模块设计拆解
java·开发语言·数据库
Python+996 小时前
Java 枚举类(Enum)详解:从基础到高级应用
java·开发语言·python
二炮手亮子6 小时前
浅记java线程池
java·开发语言
zmzb01037 小时前
C++课后习题训练记录Day157
开发语言·c++
dunge20267 小时前
2026年7月最新ChatGPT Plus / Pro 与 Codex:当 AI Agent 最新5.6版本来袭,必须理解事务、幂等与补偿
开发语言·人工智能·python
爱吃牛肉的大老虎8 小时前
rust基础之环境搭建
java·开发语言·rust
openKylin8 小时前
与全球技术演进同频,openKylin 3.0从C迈向Rust
c语言·开发语言·rust·开源·开放原子·openkylin
迷茫、Peanut9 小时前
C语言sizeof和strlen
c语言
疯狂打码的少年9 小时前
【软件工程】结构化设计:模块独立性与耦合内聚
java·开发语言·笔记·软件工程