파일이 하나 안 읽어서 그러는데 소스좀 봐 주세여
겨레
이 코드에 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);
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2690718 | 함수 포인터반환 함수 질문 | 에드워드 | 2025-04-07 |
2690685 | 2중for문 도와주세여..;; | 흰추위 | 2025-04-07 |
2690655 | 팩토리얼 계산문제..질문~ (9) | 옆집꼬마야 | 2025-04-06 |
2690627 | c 변수 선언후 변수값 저장안하고 출력 | 방방 | 2025-04-06 |
2690600 | 릴리즈 모드로 컴파일해서 다른 컴퓨터에서도 실행파일을 실행할수 있는 방법 알려주세요 (5) | 제나 | 2025-04-06 |
2690576 | bin파일 저장 | 다올 | 2025-04-06 |
2690547 | C언어 뒷부분이라 너무 어려워서요;; 프로그래밍 하나만 부탁드립니다 (4) | 그루터기 | 2025-04-05 |
2690517 | cygwin에서요.. (1) | 엘보어 | 2025-04-05 |
2690486 | 문자열과 문자형이요 ~ | 다스리 | 2025-04-05 |
2690344 | 일본어 주석 깨짐 문제 (3) | 연하얀 | 2025-04-04 |
2690314 | 암호문 만들기 -비제네르- | 이퓨리한나 | 2025-04-03 |
2690292 | 왕초보자의 질문!!!!!! 도와주세요 (1) | 하랑 | 2025-04-03 |
2690269 | 정올 문제 인데.. 흠 | 반월 | 2025-04-03 |
2690237 | sizeof에서 short형을 썻는데 왜 4byte가 나올까요? (1) | 바나나 | 2025-04-03 |
2690183 | 문자열과 포인트 비교 (2) | 미즈 | 2025-04-02 |
2690154 | a -48 ? | 희미한눈물 | 2025-04-02 |
2690094 | 테트리스 질문요. | 지후 | 2025-04-01 |
2690066 | 문자열비교!! (1) | 매디 | 2025-04-01 |
2689888 | 좀도와주세요;; ㅠㅠ | 사람 | 2025-03-30 |
2689856 | 메뉴 그리는 거 질문 | 나라빛 | 2025-03-30 |