파일이 하나 안 읽어서 그러는데 소스좀 봐 주세여
상큼한캔디
이 코드에 dec 파일이 안 읽는데여 왜인지 잘 모르겠어여 설명좀 부탁드립니다.
#includestdio.h
#includestdlib.h
int hash1 (FILE* sp);
void encrypt(FILE* sp, FILE* cip, int key);
void decrypt(FILE* sp, FILE* cip, FILE* dec, int key);
int main()
{
int key,st1;
FILE* sp;
FILE* cip;
FILE* dec;
printf(enter the key value\n);
scanf(%d, &key);
if(!(sp=fopen(cleartext.txt, r+)))
{
printf(Error opening file\n);
exit(1);
}
if(!(cip=fopen(ciphertext.bin,w+b)))
{
printf(Error opening file\n);
exit(1);
}
if(!(dec=fopen(cleartext.new,w)))
{
printf(Error opening file\n);
exit(1);
}
if(key0)
{
printf(Input error\n);
exit(1);
}
encrypt(sp,cip,key);
decrypt(sp,cip,dec,key);
st1=hash1(sp);
printf(The value of hash is %u\n,st1);
fclose(sp);
fclose(cip);
fclose(dec);
return 0;
}
int hash1(FILE* sp)
{
unsigned int hash=0,message=0;
char cd;
if(sp==NULL)
{
printf(File open error\n);
exit(1);
}
rewind(sp);
while((cd=fgetc(sp))!=EOF)
{
fseek(sp,-1,SEEK_CUR);
fread(&message,sizeof(int),1,sp);
hash=hash+message;
}
return hash;
}
void encrypt(FILE* sp,FILE* cip,int key)
{
char cd;
unsigned int message,cipher;
if(sp==NULL)
{
printf(File open error\n);
exit(1);
}
while((cd=fgetc(sp))!=EOF)
{
fseek(sp,-1,SEEK_CUR);
fread(&message,sizeof(char),1,sp);
cipher=message^key;
fwrite(&cipher,sizeof(char),1,cip);
}}
void decrypt(FILE *sp, FILE *cip, FILE *dec, int key)
{
char cd,ab;
unsigned int message,cipher;
if(cip==NULL)
{
printf(File open error\n);
exit(1);
}
rewind(cip);
while((cd=fgetc(cip))!=EOF)
{
fseek(cip,-1,SEEK_CUR);
fread(&cipher,sizeof(char),1,cip);
message=cipher^key;
fputc(message,stdout);
fputc(message,dec);
}
}