




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、C語言課程設計實驗報告實驗名稱:文件加密解密院系:軟件學院 學號:日期:2012年9月3日9月17日 一:設計題目1:設計圖形用戶界面。2:對文件進行加密并對加密文件進行保存。3:對加密了的文件進行解密。 二:設計過程設計過程中遇到的困難和解決方法:1:不能很好地理解題意(通過老師的講解)。2:不知道如何設計加密解密程序(通過翻閱書籍和上網查找資料)過程:首先通過學習老師提供的資料了解大致的設計過程并懂得運用一些以前沒有學習過的c語言。先利用文本文件設計出加密解密的主要過程并能運行。知道如何運用fopen將原文件打開并用fread將原文件內容讀出來,然后進行加密設計并將加密的數據用fwrite
2、寫進指定的文件中并保存。然后讀出加密的文件并解密并保存。最后在寫出的程序中加入圖形用戶界面,運用window,box,gotoxy等進行設計。 三:源代碼#include /* 標準輸入、輸出函數 */#include /* 標準庫函數 */#include /*字符串處理函數 */#include /* 字符操作函數 */#include #include #define key_down 80 #define key_up 72 #define key_esc 1 #define key_enter 28#define SIZE 1void box(int startx,int start
3、y,int high,int width);int get_key();char buf20*20*4;/*/加密解密 */void fun(char *list,char *sd) /*加密過程*/ FILE *fp1,*fp2; char buf1000; /*文件臨時存放處*/ register int ch; fp1=fopen(e:list.txt,r); /*用可讀方式打開文件*/ fp2=fopen(e:sd.txt,w); /*用可寫方式創建一個文件*/ if(fp1=NULL) printf(cannot open filen); exit(1); if(fp2=NULL)
4、printf(cannot build filen); exit(1); ch=fgetc(fp1); /*讀出打開文件的光標處的一個字符*/ while(!feof(fp1) /*讀出的字符不是最后的字符*/ ch=ch1; /*解密方式*/ fputc(fh,fp3); /*解密的字符存放在指定的地方*/ fh=fgetc(fp2); fread(buf1,sizeof(buf1),1,fp3); /*讀出buf1中所存放的數據*/ printf(%s,buf1); void main() int k; char *f=jiami,jiemi; /*界面的形式/ int key,y; in
5、t j,q; char list300; char sd300; char ds300; char ch,fh; char buf1000; char buf11000; FILE *fp1; FILE *fp2; int l1,l2; window(1,1,80,25); /*left,top,right,bottom,相對于屏幕的字符坐標,屏幕原點在左上角*/ gettext( 20,10,40,14,buf); /*保存矩形屏幕上的字符*/ textbackground(7); /*背景顏色*/ textcolor(0); /*字體顏色*/ clrscr(); /*清除矩形屏幕上的所有字
6、符*/ gotoxy(24,10); /*將當前字符屏幕的光標位置移動到x,y的坐標位子*/ printf(%s,f0); gotoxy(24,14); printf(%s,f1); gettext(10,8,60,16,buf); box(22,9,3,30); /*建立一個小窗口*/ key=0; while(1) while(bioskey(1)=0); /*讀取鍵盤值查詢鍵盤是否按下*/ key=get_key(); /*按下了什么鍵盤*/ if(key=key_up|key=key_down) y=wherey(); /*得到字符模式下窗口光標的x坐標數值*/ if(key=key_
7、up) y=y=10? y+4:10; /*當y=10光標向下移動四個位置否則將光標移動到y=10處*/ if(key=key_down) y=y=14? y-4:14; /*當y=14光標向下移動四個位置否則將光標移動到y=14處*/ puttext(10,8,60,16,buf); /*將gettext函數保存的字符恢復到屏幕上 */ gotoxy(24,y); if(y=10) textbackground(7); textcolor(0); box(22,9,3,30); textbackground(3); textcolor(15); gotoxy(24,y); cprintf(%
8、s,f0); else textbackground(7); textcolor(0); box(22,13,3,30); textbackground(3); textcolor(15); gotoxy(24,y); cprintf(%s,f1); if(key=key_enter&y=10)且光標在y=10處 /*當按下enter鍵且光標在y=10處進行下步*/ clrscr(); textbackground(3); textcolor(15); /*clrscr(); */ gotoxy(24,5); printf(input the file name for jiamin);/*用
9、戶給需要加密的文件加密 */ l1=strlen(input the file name for jiami:); /*待求長度的字符串指針*/ gotoxy(24+l1,5); scanf(%s,list); gotoxy(24,10); printf(input file name for saven);/*給加密后的文件命名,并保存*/ l2=strlen(input file name for save:); gotoxy(24+l2,10); scanf(%s,sd); fun(list,sd); fp1=fopen(e:sd.txt,rb); fread(buf1,sizeof(b
10、uf1),1,fp1); gotoxy(10,15); printf(%sn,buf1); getch(); printf(file haven jiami ,save now); getche(); break; if(key=key_enter&y=14) clrscr(); textbackground(3); textcolor(15); gotoxy(24,5); printf(input the file name for jiemi n);/*用戶給需要解密的文件解密 */ l1=strlen(input the file name for jiemi: ); gotoxy(24
11、+l1,5); scanf(%s,sd); gotoxy(24,10); printf(input file name for save:n);/*對解密的文件系統又可以提供保存路徑 */ l2=strlen(input file name for save: ); gotoxy(24+l2,10); scanf(%s,ds); man(sd,ds); fp2=fopen(e:ds.txt,rb); fread(buf1,sizeof(buf1),1,fp2); gotoxy(10,15); printf(%sn,buf1); getch(); printf(file haven jiemi,
12、save now); getche(); break; window(1,1,80,25); gettext( 20,10,40,14,buf); textbackground(7); textcolor(0); clrscr(); gotoxy(24,10); printf(%s,f0); gotoxy(24,14); printf(%s,f1); gettext(10,8,60,16,buf); box(22,9,3,30); key=0; while(1) while(bioskey(1)=0); key=get_key(); if(key=key_up|key=key_down) y=
13、wherey(); if(key=key_up) y=y=10? y+4:10; if(key=key_down) y=y=14? y-4:14; puttext(10,8,60,16,buf); gotoxy(24,y); if(y=10) /*光標在10處的窗口*/ textbackground(7); textcolor(0); box(22,9,3,30); textbackground(3); textcolor(15); gotoxy(24,y); cprintf(%s,f0); else textbackground(7); textcolor(0); box(22,13,3,3
14、0); textbackground(3); textcolor(15); gotoxy(24,y); cprintf(%s,f1); if(key=key_enter&y=10) clrscr(); textbackground(3); textcolor(15); /*clrscr(); */ gotoxy(24,5); printf(input the file name for jiamin);/*用戶給需要加密的文件加密 */ l1=strlen(input the file name for jiami:); gotoxy(24+l1,5); scanf(%s,list); got
15、oxy(24,10); printf(input file name for saven);/*給加密后的文件命名,并保存*/ l2=strlen(input file name for save:); gotoxy(24+l2,10); scanf(%s,sd); fun(list,sd); fp1=fopen(e:sd.txt,rb); fread(buf1,sizeof(buf1),1,fp1); gotoxy(10,15); printf(%sn,buf1); getch(); printf(file haven jiami ,save now); getche(); if(key=k
16、ey_enter&y=14) clrscr(); textbackground(3); textcolor(15); gotoxy(24,5); printf(input the file name for jiemi n);/*用戶給需要解密的文件解密 */ l1=strlen(input the file name for jiemi: ); gotoxy(24+l1,5); scanf(%s,sd); gotoxy(24,10); printf(input file name for save:n);/*對解密的文件系統又可以提供保存路徑 */ l2=strlen(input file
17、name for save: ); gotoxy(24+l2,10); scanf(%s,ds); man(sd,ds); fp2=fopen(e:ds.txt,rb); fread(buf1,sizeof(buf1),1,fp2); gotoxy(10,15); printf(%sn,buf1); getch(); printf(file haven jiemi,save now); getche(); break; int get_key() union REGS rg; rg.h.ah=0; int86(0x16,&rg,&rg); return rg.h.ah; getchar();v
18、oid box(int startx,int starty,int high,int width) /*屏幕的建立*/ int i; gotoxy(startx,starty); putch(0xda); for (i=startx+1;i width;i+) putch(0xc4); putch(0xbf); for(i=starty+1;i high+starty;i+) gotoxy(startx,i); putch(0xb3); gotoxy(width,i); putch(0xb3); gotoxy(startx,starty+high-1); putch(0xc0); gotoxy(startx+1,s
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 江西省寧岡縣中2023-2024學年高二上學期語文開學考試試卷(含答案)
- 2025至2030中國煙熏香味劑行業市場深度研究及發展前景投資可行性分析報告
- 2025至2030中國液壓操作臺行業市場占有率及投資前景評估規劃報告
- 2025至2030中國消費貸款行業深度研究及發展前景投資評估分析
- 2025至2030中國海藻小吃行業產業運行態勢及投資規劃深度研究報告
- 2025至2030中國油脂化工行業產業運行態勢及投資規劃深度研究報告
- 江蘇省無錫市洛社初級中學2025屆高一下化學期末統考試題含解析
- 2025屆廣東省汕頭市龍湖區高一下化學期末監測試題含解析
- 2025屆山東省菏澤、煙臺高一下化學期末考試試題含解析
- 共享出行平臺信用評級與用戶滿意度提升策略2025研究報告
- 內科護理學消化性潰瘍
- 北京市第一零一中學2023-2024學年高一下學期期末考試地理試題(解析版)
- 中小學暑期安全教育班會課件
- 2024年荊州市荊發控股集團招聘考試真題
- 2025年新疆維吾爾自治區中考歷史真題(解析版)
- 2025至2030中國新能源行業市場發展分析及前景趨勢與對策戰略報告
- 空壓機考試題及答案
- 中國再生水行業發展分析與發展趨勢預測研究報告2025-2028版
- 慢病智能監測-洞察及研究
- 2025至2030年中國直驅電機行業發展策略分析及投資前景研究報告
- 2025年內蒙古呼倫貝爾農墾集團有限公司招聘筆試沖刺題(帶答案解析)
評論
0/150
提交評論