文件加密算法

文件加密算法

/*============================================================================ 
 Name        : Exercise.cbp 
 Author      : Haier 
 Version     : 1.01 
 Copyright   : Copyright (c) 2014 
 Description : File Encryption in C, Ansi-style, Compile by Code::Block 
 ============================================================================*/  
#include <stdio.h>
#include <stdlib.h>

/**************************************************************************** 
* Function     : Encryption 
* Description  : File Encryption Algorithm 
* Input        : FileName of input ,FileName of Output, Key
* Return       : void 
*****************************************************************************/ 
void Encryption(FILE *InputFile,FILE *OutputFile,char *Key)
{
    char TempChar;
    int i=0;

    while((TempChar=getc(InputFile))!=EOF)
    {
        TempChar=TempChar^*(Pwd+i++);
        putc(TempChar,OutputFile);

        if(i>9)
        {
            i=0;
        }
    }
}

/**************************************************************************** 
* Function     : main 
*****************************************************************************/ 

int main(int argc,char *argv[])
{
    FILE *InputFile,*OutputFile;
    char Pwd[10];

    if(argc!=3)
    {
        printf("Usage: Exercise InputFile OutputFile");
        exit(1);
    }

    if((InputFile=fopen(argv[1],"rb"))==NULL)
    {
        printf("Can not open %s !\n",argv[1]);
        exit(1);
    }

    if((OutputFile=fopen(argv[2],"wb"))==NULL)
    {
        printf("Can not open %s !\n",argv[2]);
        exit(1);
    }

    printf("Please input the password : ");
    scanf("%s",Pwd);
    Encryption(InputFile,OutputFile,Pwd);

    fclose(InputFile);
    fclose(OutputFile);
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值