图片加密解密程序2
来源:互联网 发布:军人证件照软件 编辑:程序博客网 时间:2024/04/28 09:10
图片加密解密c语言实现
#include<stdio.h>#include<stdlib.h>#include<conio.h>#include<string.h>typedef unsigned char BYTE;typedef unsigned short WORD;void ECBencrypto(char *in_fname,char *password,char *out_fname);void CBCencrypto(char *in_fname,char *password,char *out_fname);int main(){ char in_fname[30]; char out_fname[30]; char password[10];printf("-------------welcome to use zsh program -------------/n"); printf("/nplease input infile name/n"); gets(in_fname); printf("/t/t请选择要加密的方式:1.EBC 2.CBC 0.退出/t/n"); char ch; ch=getchar(); while(!(ch>='0'&&ch<='2'))ch=getchar(); while(1) { switch(ch) { case '1': printf("/nplease input outfile name/n"); fflush(stdin); gets(out_fname); printf("/nplease input password /n"); fflush(stdin); gets(password); ECBencrypto(in_fname,password,out_fname); break; case '2': printf("/nplease input outfile name/n"); fflush(stdin); gets(out_fname); printf("/nplease input password /n"); fflush(stdin); gets(password); CBCencrypto(in_fname,password,out_fname); break; case '0': return 0; } printf("/t/t请选择要加密的方式:1.EBC 2.CBC 0.退出/t/n"); ch=getchar(); // fflush(stdin); while(!(ch>='0'&&ch<='2'))ch=getchar(); } printf("end/n"); return 0;}long Getfilesize(FILE *stream){ long curpos1,curpos2,length; curpos1=ftell(stream);//测定文件当前指向 fseek(stream,0L,SEEK_END); curpos2=ftell(stream);//测定文件当前指向 length=curpos2-curpos1; fseek(stream,curpos1,SEEK_SET);//恢复文件开始位置 //printf("%ld/n",length); return length; // fclose(stream);}void ECBencrypto(char *in_fname,char *password,char *out_fname){ FILE *fp1,*fp2; if(NULL==(fp1=fopen(in_fname,"rb")))//以只读的方式打开二进制文件 { printf("can not open the file/n"); exit(1); } if(NULL==(fp2=fopen(out_fname,"wb")))//以只写的方式打开一个二进制文件,如果文件不存在,则创建该文件 { printf("can not create file /n"); exit(1); } //printf("file bkwood.bmp open success./n"); WORD fileType; fread(&fileType,1,sizeof(WORD),fp1); fwrite(&fileType,1,sizeof(WORD),fp2); if(fileType != 0x4d42) { printf("file is not .bmp file!"); return; } long length=Getfilesize(fp1); printf("此文件的大小为:%ld/n/n",length); int len=0; while(password[++len]);//获取密码长度 BYTE buf; fread(&buf,1,sizeof(buf),fp1); for(int i=0;i<50;i++) { fwrite(&buf,1,sizeof(buf),fp2); fread(&buf,1,sizeof(buf),fp1); } int j=0; while(!feof(fp1)) { buf^=password[j>=len?j=0:j++];//以EBC方式加密 fwrite(&buf,1,sizeof(buf),fp2); fread(&buf,1,sizeof(buf),fp1); } printf("do Ebc/n"); fclose(fp1); fclose(fp2); }void CBCencrypto(char *in_fname,char *password,char *out_fname){ FILE *fp1,*fp2; if(NULL==(fp1=fopen(in_fname,"rb")))//以只读的方式打开二进制文件 { printf("can not open the file/n"); exit(1); } if(NULL==(fp2=fopen(out_fname,"wb")))//以只写的方式打开一个二进制文件,如果文件不存在,则创建该文件 { printf("can not create file /n"); exit(1); } //printf("file bkwood.bmp open success./n"); WORD fileType; fread(&fileType,1,sizeof(WORD),fp1); fwrite(&fileType,1,sizeof(WORD),fp2); if(fileType != 0x4d42) { printf("file is not .bmp file!"); return; } long length=Getfilesize(fp1); printf("此文件的大小为:%ld/n/n",length); int len=0; while(password[++len]);//获取密码长度 BYTE buf; fread(&buf,1,sizeof(buf),fp1); for(int i=0;i<50;i++) { fwrite(&buf,1,sizeof(buf),fp2); fread(&buf,1,sizeof(buf),fp1); } int j=0; char temp; while(!feof(fp1)) { buf^=password[j>=len?j=0:j++]; temp=buf^=password[j>=len?j=0:j++];//以CBC方式加密 buf^=temp; fwrite(&buf,1,sizeof(buf),fp2); fread(&buf,1,sizeof(buf),fp1); } printf("do Cbc/n"); fclose(fp1); fclose(fp2);}
- 图片加密解密程序2
- 图片加密解密程序
- 图片加密解密
- 加密解密程序
- VB 加密解密程序
- 加密解密程序
- 加密解密小程序
- asp加密解密程序
- 文件加密解密程序
- 加密解密小程序
- AES加密解密程序。
- 加密解密程序
- AES加密解密图片资源
- android imageloader加密解密图片
- DESede加密解密程序(java)
- 自解密加密程序制作
- 简单的加密,解密程序
- 链接字符串加密、解密程序
- Lambda表达式
- MATLABr2006a序列号
- 循环与递归
- 联手培养高质量IT人才
- 放假
- 图片加密解密程序2
- Bash shell中的位置参数$#,$*,$@,$0,$1,$2...及特殊参数$?,$-等的含义
- MFC中 关于(About) 信息的实现
- GDI+源码:美女涂鸦
- 在新建类中获取其他的类
- O'Reilly书名
- IP与交换机端口绑定
- synchronized的用法
- Struts 2框架整合Spring