请给出c语言文件加密的编程
推荐于2016-04-26
展开全部
参考如下代码:
#include <stdio.h>
#include <stdlib.h>
#define DWORD unsigned long
#define BYTE unsigned char
#define false 0
#define true 1
int main(int argc, char *argv[])
{
FILE *hSource;
FILE *hDestination;
DWORD dwKey=0xfcba0000;
char* pbBuffer;
DWORD dwBufferLen=sizeof(DWORD);
DWORD dwCount;
DWORD dwData;
if(argv[1]==0||argv[2]==0)
{
printf("missing argument!\n");
return false;
}
char* szSource=argv[1];
char* szDestination=argv[2];
hSource = fopen(szSource,"rb");// 打开源文件.
hDestination = fopen(szDestination,"wb"); //打开目标文件
if (hSource==NULL) {printf("open Source File error !"); return false ;}
if (hDestination==NULL){ printf("open Destination File error !"); return false ;}
//分配缓冲区
pbBuffer=(char* )malloc(dwBufferLen);
do {
// 从源文件中读出dwBlockLen个字节
dwCount = fread(pbBuffer, 1, dwBufferLen, hSource);
//加密数据
dwData = *(DWORD*)pbBuffer; //char* TO dword
dwData^=dwKey; //xor operation
pbBuffer = (char *) &dwData;
// 将加密过的数据写入目标文件
fwrite(pbBuffer, 1, dwCount, hDestination);
} while(!feof(hSource));
//关闭文件、释放内存
fclose(hSource);
fclose(hDestination);
printf("%s is encrypted to %s\n",szSource,szDestination);
return 0;
2011-05-30
展开全部
3.126 icePub_encryptFile
l 函数原型:
int WINAPI icePub_encryptFile(char *strFilename, char *strOutputFilename, char *strKey)
输入:strFilename 待加密文件名
strOutputFilename 加密后文件名
strKey 密钥,任意长度
输出:
返回码:
3.127 icePub_decryptFile
l 函数原型:
int WINAPI icePub_decryptFile(char *strFilename, char *strOutputFilename, char *strKey)
输入:strFilename 加密文件名
strOutputFilename 解密后文件名
strKey 密钥,任意长度
输出:
返回码:
char key[128];
strcpy(key,"11223344");
{
typedef int (WINAPI ICEPUB_ENCRYPTFILE)(char *strFilename, char *strOutputFilename, char *strKey);
ICEPUB_ENCRYPTFILE *icePub_encryptFile = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_encryptFile=(ICEPUB_ENCRYPTFILE *)GetProcAddress(hDLLDrv,"icePub_encryptFile");
}
if(icePub_encryptFile)
icePub_encryptFile("e:\\a.jpg","e:\\a.dat",key);
if(hDLLDrv)
FreeLibrary(hDLLDrv);
}
{
typedef int (WINAPI ICEPUB_DECRYPTFILE)(char *strFilename, char *strOutputFilename, char *strKey);
ICEPUB_DECRYPTFILE *icePub_decryptFile = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_decryptFile=(ICEPUB_DECRYPTFILE *)GetProcAddress(hDLLDrv,"icePub_decryptFile");
}
if(icePub_decryptFile)
icePub_decryptFile("e:\\a.dat","e:\\a.jpg",key);
if(hDLLDrv)
FreeLibrary(hDLLDrv);
}
http://dl.icese.net/dev.php?f=icePubDll.rar 下载
l 函数原型:
int WINAPI icePub_encryptFile(char *strFilename, char *strOutputFilename, char *strKey)
输入:strFilename 待加密文件名
strOutputFilename 加密后文件名
strKey 密钥,任意长度
输出:
返回码:
3.127 icePub_decryptFile
l 函数原型:
int WINAPI icePub_decryptFile(char *strFilename, char *strOutputFilename, char *strKey)
输入:strFilename 加密文件名
strOutputFilename 解密后文件名
strKey 密钥,任意长度
输出:
返回码:
char key[128];
strcpy(key,"11223344");
{
typedef int (WINAPI ICEPUB_ENCRYPTFILE)(char *strFilename, char *strOutputFilename, char *strKey);
ICEPUB_ENCRYPTFILE *icePub_encryptFile = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_encryptFile=(ICEPUB_ENCRYPTFILE *)GetProcAddress(hDLLDrv,"icePub_encryptFile");
}
if(icePub_encryptFile)
icePub_encryptFile("e:\\a.jpg","e:\\a.dat",key);
if(hDLLDrv)
FreeLibrary(hDLLDrv);
}
{
typedef int (WINAPI ICEPUB_DECRYPTFILE)(char *strFilename, char *strOutputFilename, char *strKey);
ICEPUB_DECRYPTFILE *icePub_decryptFile = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_decryptFile=(ICEPUB_DECRYPTFILE *)GetProcAddress(hDLLDrv,"icePub_decryptFile");
}
if(icePub_decryptFile)
icePub_decryptFile("e:\\a.dat","e:\\a.jpg",key);
if(hDLLDrv)
FreeLibrary(hDLLDrv);
}
http://dl.icese.net/dev.php?f=icePubDll.rar 下载
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/************************************************************************/
/* 版权所有:信息工程学院 王明 使用时请注明出处!! */
/* 算法:凯撒密码体制 */
/************************************************************************/
#include <stdio.h>
#define N 5
void jiami(char namea[256])
{
FILE *fp_jiami,*fp_file2;
char c;
fp_jiami=fopen(namea,"rb");
fp_file2=fopen("file2.txt","wb");
while(EOF!=(fscanf(fp_jiami,"%c",&c)))
{
if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
{
c=c+N;
if (!((c>='A'&&c<='Z')||(c>='a'&&c<='z')))c=c-26;
if(c>='a'&&c<='z')c=c-32;
}
fprintf(fp_file2,"%c",c);
}
fclose(fp_file2);
fclose(fp_jiami);
}
void jiemi(char en_name[256])
{
FILE *fp_jiemi,*fp_file3;
char c;
fp_jiemi=fopen(en_name,"rb");
fp_file3=fopen("file3.txt","wb");
while(EOF!=(fscanf(fp_jiemi,"%c",&c)))
{
if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
{
c=c-N;
if (!((c>='A'&&c<='Z')||(c>='a'&&c<='z')))c=c+26;
if(c>='A'&&c<='Z')c=c+32;
}
fprintf(fp_file3,"%c",c);
}
fclose(fp_file3);
fclose(fp_jiemi);
}
int main()
{
char name[256];
int n;
printf("输入你要操作的TXT文本:");
gets(name);
printf("\n请选择需要进行的操作:\n");
printf(" 1:加密 2:解密 \n");
printf("输入你的选择:");
scanf("%d",&n);
switch(n) {
case 1:{jiami(name);printf("\t加密成功!!\n\n");
break;}
case 2:{jiemi(name);printf("\t解密成功!!\n\n");
break;}
default:{printf("输入操作不存在!");}
}
return 0;
}
/* 版权所有:信息工程学院 王明 使用时请注明出处!! */
/* 算法:凯撒密码体制 */
/************************************************************************/
#include <stdio.h>
#define N 5
void jiami(char namea[256])
{
FILE *fp_jiami,*fp_file2;
char c;
fp_jiami=fopen(namea,"rb");
fp_file2=fopen("file2.txt","wb");
while(EOF!=(fscanf(fp_jiami,"%c",&c)))
{
if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
{
c=c+N;
if (!((c>='A'&&c<='Z')||(c>='a'&&c<='z')))c=c-26;
if(c>='a'&&c<='z')c=c-32;
}
fprintf(fp_file2,"%c",c);
}
fclose(fp_file2);
fclose(fp_jiami);
}
void jiemi(char en_name[256])
{
FILE *fp_jiemi,*fp_file3;
char c;
fp_jiemi=fopen(en_name,"rb");
fp_file3=fopen("file3.txt","wb");
while(EOF!=(fscanf(fp_jiemi,"%c",&c)))
{
if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
{
c=c-N;
if (!((c>='A'&&c<='Z')||(c>='a'&&c<='z')))c=c+26;
if(c>='A'&&c<='Z')c=c+32;
}
fprintf(fp_file3,"%c",c);
}
fclose(fp_file3);
fclose(fp_jiemi);
}
int main()
{
char name[256];
int n;
printf("输入你要操作的TXT文本:");
gets(name);
printf("\n请选择需要进行的操作:\n");
printf(" 1:加密 2:解密 \n");
printf("输入你的选择:");
scanf("%d",&n);
switch(n) {
case 1:{jiami(name);printf("\t加密成功!!\n\n");
break;}
case 2:{jiemi(name);printf("\t解密成功!!\n\n");
break;}
default:{printf("输入操作不存在!");}
}
return 0;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询