您的位置 首页 PR课程

pre课程设计


关于pre课程设计最佳答案


pre课程设计


1.您已经说得很清楚了您仍然不会写? ? ?


关于pre课程设计相关答案


2.* 这是我写的一个文件加密的程序,可以对任何文件进行 加密,利用加密时的密码可以进行解密*#include #include #include * 文件操作 API*#define GET_WRITE_FILE_NAME(O) \{ \ char ftype[10] = {0}; \ char *tmp = 0; \ char *position = 0; \ tmp = (O); \ while(1) \ { \ position = tmp; \ tmp = strchr(tmp, '.'); \ if(tmp != NULL) \ tmp++; \ else if(position > (O)) \ { \ strcpy(ftype, position); \ position = position – 1; \ break; \ } \ else \ break; \ } \ if(position != NULL) \ { \ *position = '\0'; \ strcat((O), "_bak."); \ strcat((O), ftype); \ } \}int remove_file(char *fname){ if(0 != remove(fname)) return -1; else return 0;}int rename_file(char *oldname, char *newname){ if(0 != rename(oldname, newname)) return -1; return 0;}FILE* open_file_read(char* fname){ FILE * f; f = fopen(fname, "rb"); if(!f) return NULL; else return f; }void close_file_read(FILE *f){ if(f) fclose(f);}FILE* open_file_write(char* fname){ FILE * f; f = fopen(fname, "wb"); if(!f) return NULL; else return f; }void close_file_write(FILE *f){ if(f) fclose(f);}int read_byte(FILE *f, char *ch){ if(f) if(fread(ch, 1, 1, f) < 1) return -1; return 0;}int write_byte(FILE *f, char *ch){ if(f) if(fwrite(ch, 1, 1, f) : "); for(;;) { if(i == 100) { printf("Too complicated file path!!\n"); return; } scanf("%c", pchar); if(*pchar == '\n') { *pchar = 0; break; } else pchar++; i++; } strcpy(fname_bak, fname); printf("input in encrypt key\n==>: "); gets(key); printf("input option(1—encrypt, 2—decrypt)\n==>: "); chpre = getchar(); if(chpre == '1') encrypt = 1; else if(chpre == '2') decrypt = 1; else return; fr = open_file_read(fname); if(!fr) { printf("No such file!!\n"); goto exit; } GET_WRITE_FILE_NAME(fname); fw = open_file_write(fname); if(!fw) { printf("cant create the file %s!!\n", fname); goto exit; } chpre = 0; while(1) { if(0 == read_byte(fr, chr)) { decry_encry_byte(chr, chw, key, chpre); if(encrypt) chpre = chr; else chpre = chw; if(0 != write_byte(fw, chw)) break; } else break; } succeed = 0;exit: if(fr) close_file_read(fr); if(fw) close_file_write(fw); if(succeed == 0) { remove_file(fname_bak); rename_file(fname, fname_bak); }}


了解更多pre课程设计类似问题


想学pr报什么课程

热门文章

发表评论

邮箱地址不会被公开。 必填项已用*标注