版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、西華大學(xué)計算機系上機實踐報告課程名稱:密碼學(xué)指導(dǎo)教師:紀(jì)四維上機實踐名稱:對稱密碼算法上機實踐編號:a01年級:07級上機實踐成績:姓名:范存勇學(xué) 號 :上機實踐日期:2009-11-10312007080605104組號:上機實踐時間14: 00-17: 20一、目的通過用des算法對實際數(shù)據(jù)進行加密和解密來深刻了解des的運行原理。二、內(nèi)容與設(shè)計思想a) 算法分析。對加密解密時主要用到的五個函數(shù)進行分析。i. 密鑰生成函數(shù)ii. 加密函數(shù)iii. 解密函數(shù)iv. 測試函數(shù)v. 密鑰長度檢驗函數(shù)b) 使用實例分析。i. 對一個文件進行加密解密,提交程序代碼和執(zhí)行結(jié)果。ii. 加密時,將輸入(
2、如64比特分組)改變一位,比較輸出的變化,并說 明原因。三、使用環(huán)境運行windows 或linux 操作系統(tǒng)的 pc機,具有g(shù)cc(linux)、vc(windows)等c語言編譯環(huán)境四、核心代碼及調(diào)試過程#ifndef crypt_h_ #define crypt_h_ #include <assert.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h>#include <ctype.h>#include <
3、;limits.h>#ifdef _cplusplus extern "c" #endif/* version */#define crypt 0x0096#define scrypt ”0.96”/* error codes will be expanded in future releases */ enum crypt_ok=0,/* result ok */crypt_invalid_keysize, /* invalid key size given */ crypt_invalid_rounds, /* invalid number of rounds *
4、/ crypt_fail_testvector,產(chǎn) algorithm failed test vectors */;#define des/* use small code where possible */#define small_code/* enable self-test test vector checking */#define ltc.test/* type of argument checking, 0=default, 1 =fatal and 2=none */#define argtype 0/* chl-01-1 */* controls endianess and
5、 size of registers leave uncommented to get platform neutral slower code */* detect x86-32 machines somewhat */#ifdefined(intel_cc) | (defined(_msc_ver) && defined(win32) | (defined(_gnuc_) && (defined(_djgpp_) | defined(_cygwin_) | defined(_mingw32_) | defined(_i386)#define endian_l
6、ittle#define endian_32bitword#endif/* detects mips r5900 processors (ps2) */#if (defined(_r5900) | defined(r5900) | defined(_r5900_) && (defined(_mips) | defined(_mips_) | defined(mips)#define endian_little#define endian_64bitword#endif怦 #define endian_little 犁嚴(yán) #define endian_big */* #defin
7、e endian_32bitword */* #define endian_64bitword */#if (defined(endian_big) | defined(endian_little)&& !(defined(endian_32bitword) | defined(endian_64bitword) #error you must specify a word size as well as endianess#endif#訐!(defined(endian_big) | defined(endian_little) #define endian.neutral#
8、endif/* fix for msvc .evil! */#ifdef_msc_ver#define const64(n) n # ui64 typedef unsigned _int64 ulong64;#else#define const64(n) n # ull typedef unsigned long long ulong64;#endif/* this is the "32-bit at least" data type* re-define it to suit your platform but it must be at least 32-bits */
9、typedef unsigned long ulong32;/* - helper macros*/#ifdef endian.neutral#define store32l(x, y) (y)3 = (unsigned char)(x)»24)&255); (y)2j = (unsigned char)(x)»16)&255);(y)l = (unsigned char)(x)»8)&255); (y)0 = (unsigned char)(x)&255); #define load32l(x, y) x = (unsigned
10、long)(y)3 & 255)«24) | (unsigned long)(y)2 & 255)«16) | (unsigned long)(y)l & 255)«8)| (unsigned long)(y)|0| & 255); #define store32h(x, y) (y)|0| = (unsigned char)(x)»24)&255); (y)| 1 = (unsigned char)(x)»16)&255);(y)2 = (unsigned char)(x)»8)&am
11、p;255); (y)3 = (unsigned char)(x)&255); #define load32h(x, y) x = (unsigned long)(y)|0 & 255)«24) | (unsigned long)(y)l & 255)«16) | (unsigned long)(y)2 & 255)«8)| (unsigned long)(y)3 & 255); #enchf/* endian_neutral */#ifdef endian_little#define store32h(x, y) (y)0
12、 = (unsigned char)(x)»24)&255); (y)l = (unsigned char)(x)»16)&255);(y)2 = (unsigned char)(x)»8)&255); (y)3 = (unsigned char)(x)&255); #define load32h(x, y) x = (unsigned long)(y)0 & 255)«24) | (unsigned long)(y)l & 255)«16) | (unsigned long)(y)2 &
13、 255)«8)| (unsigned long)(y)3 & 255); #ifdef endian_32bitword#define store32l(x, y) unsigned long _t = (x); memcpy(y, &_t, 4); #define load32l(x, y) memcpy(&(x), y, 4);#else /* 64-bit words then */#define store32l(x, y) unsigned long _t = (x); memcpy(y, &_t, 4); #define load32l(
14、x, y) memcpy(&(x), y, 4); x &二 oxffffffff; #endif/* endian_64bitword */#endif/* endian_little */#ifdefendian_big#define store32l(x, y) (y)oj = (unsigned char)(x)»24)&255); (y)l = (unsigned char)(x)»16)&255);(y)2 = (unsigned char)(x)»8)&255); (y)3 = (unsigned char)(
15、x)&255); #define load32l(x, y) x = (unsigned long)(y)0 & 255)«24) | (unsigned long)(y)l & 255)«16) | (unsigned long)(y)2 & 255)«8)| (unsigned long)(y)3 & 255); #ifdef endian_32bitword#define store32h(x, y) unsigned long _t = (x); memcpy(y, &_t, 4); #define load
16、32h(x, y)memcpy(&(x), y, 4);#else /* 64-bit words then */#define store32h(x, y) unsigned long _t = (x); memcpy(y, &_t, 4); #define load32h(x, y) memcpy(&(x), y, 4); x &二 oxffffffff; #endif/* endian.64bitword */#endif/* endian_big */#define bswap(x) (x»24)&0x000000fful) | (x&
17、#171;24)&0xff000000ul)| (x»8)&0x0000ff00ul)| (x«8)&0x00ff0000ul)#ifdef_msc_ver#pragma intrinsic(rotl)#define ror(x,n) _lrotr(x,n)#define rol(x,n) _lrotl(x,n)#elif defined(_gnuc_) && defined(_i386_) && !defined(intel_cc)static inline unsigned long rol(unsigned lo
18、ng word, int i)_asm_(hroll %cl,%on:n=rn (word):”0” (word),ncn (i);return word;static inline unsigned long ror(unsigned long word, int i)_asm_(nrorl %cl,%0”:'-rh (word):”0” (word),nch (i);return word;#else/* rotates the hard way */#define rol(x, y) (unsigned long)(x)«(unsigned long)(y)&3
19、1) | (unsigned long)(x)&oxfffffffful)»(unsigned long)(32-(y)&31) & oxfffffffful)#define ror(x, y) (unsigned long)(x)&oxfffffffful)»(unsigned long)(y)&31) | (unsigned long)(x)«(unsigned long)(32-(y)&31) & oxfffffffful)#endif/* extract a byte portably */#ifde
20、f_msc_ver#define byte(x, n) (unsigned char)(x) » (8 * (n)#else#define byte(x, n) (x) » (8 * (n) & 255)#endiftypedef struct des_key ulong32 ek32, dk32;symmetric_key;extern int des_setup(const unsigned char *key, int keylen, int num_rounds? symmetric_key *skey);extern void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key * key); extern void des_ecb_decrypt(const unsigned char un
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 代理銷售協(xié)議范文
- 企業(yè)技術(shù)部年終工作總結(jié)
- 中職學(xué)生學(xué)期個人總結(jié)
- DB12T 533-2014 公共服務(wù)單位服務(wù)標(biāo)準(zhǔn)體系標(biāo)準(zhǔn)編號規(guī)則
- 中秋節(jié)晚會領(lǐng)導(dǎo)致辭(20篇)
- 畢業(yè)的實習(xí)報告六篇
- 文書模板-解除流轉(zhuǎn)合同
- 影響肉質(zhì)的營養(yǎng)因素
- 部編版歷史九年級上冊第七單元 第20課《第一次 工業(yè)革命》說課稿
- 普寧市勤建學(xué)校九年級上學(xué)期語文第一次月考試卷
- 五年級上冊數(shù)學(xué)教學(xué)設(shè)計-植樹問題 人教版
- 社區(qū)兒童健康管理案例分析報告
- 企業(yè)財務(wù)管理課件:如何正確認識企業(yè)財務(wù)管理
- 2024年哈爾濱鐵道職業(yè)技術(shù)學(xué)院高職單招(英語/數(shù)學(xué)/語文)筆試歷年參考題庫含答案解析
- 養(yǎng)老事業(yè)與養(yǎng)老產(chǎn)業(yè)的比較研究以日本養(yǎng)老事業(yè)與養(yǎng)老產(chǎn)業(yè)為例
- 下肢動脈閉塞癥的護理
- 微觀經(jīng)濟學(xué)(第三版)課程標(biāo)準(zhǔn)
- 單位職工酒駕檢討書范文
- 心臟驟停與猝死
- 《功能材料概論》課件
- 工程師職稱代評銷售話術(shù)
評論
0/150
提交評論