資源描述:
《關(guān)于c語言的des加密算法實現(xiàn)》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、關(guān)于C語言的DES加密算法實現(xiàn).txt13母愛是迷惘時苦口婆心的規(guī)勸;母愛是遠(yuǎn)行時一聲殷切的叮嚀;母愛是孤苦無助時慈祥的微笑。/******************************************author:TroyLiu*time:2011.05.26*說明:由于本人C語言編程能力有限,此代碼僅供參考。*其中各個功能的實現(xiàn)具有一定的參考價值。*代碼的部分書寫習(xí)慣亦可參考。*如果有能力者,可以考慮分函數(shù)完成。*請記?。核械拇a都寫到main()函數(shù)是一個很不良的編程習(xí)慣!!!*********************
2、*********************//*********************************************這僅是DES的第一輪加密*輸入明文:computer#*輸入密文:program#*書本的錯誤:*1.密鑰k經(jīng)過置換后得到的D0最后一位有錯誤,應(yīng)該為1(這個錯誤不影響往后的結(jié)果)*2.通過8個s盒得到32位的序列第二組前四位有錯,應(yīng)該為1101,而不是0011*3.往后的結(jié)果均由上2的錯誤導(dǎo)致********************************************//********D
3、ES密碼的加密過程*******************1.將字母轉(zhuǎn)化為二進制數(shù)(明文&密文)分成兩組完成*2.對明文m進行初始IP置換完成*3.對密鑰k進行密鑰置換完成*4.對密鑰k進行壓縮置換完成*5.對R0進行擴展變換32->48完成*6.結(jié)果和k進行異或運算完成*7.將結(jié)果分成8組,通過8個s盒完成*8.對s盒的輸出序列進行P置換完成*9.對p置換的結(jié)果與L0進行異或運算完成********************************************/#includeintip[]={//IP置換5
4、8,50,42,34,26,18,10,2,60,52,44,36,28,20,12,4,62,54,46,38,30,22,14,6,64,56,48,40,32,24,16,8,57,49,41,33,25,17,9,1,59,51,43,35,27,19,11,3,61,53,45,37,29,21,13,5,63,55,47,39,31,23,15,7};intjiou[]={7,15,23,31,39,47,55,63//進行密鑰添加奇偶校驗位使用};intki[]={//密鑰置換57,49,41,33,25,17,9,1,5
5、8,50,42,34,26,18,10,2,59,51,43,35,27,19,11,3,60,52,44,36,63,55,47,39,31,23,15,7,62,54,46,38,30,22,14,6,61,53,45,37,29,21,13,5,28,20,12,4};intkyasuo[]={//對密鑰進行壓縮置換14,17,11,24,1,5,3,28,15,6,21,10,23,19,12,4,26,8,16,7,27,20,13,2,41,52,31,37,47,55,30,40,51,45,33,48,44,49,39,
6、56,34,53,46,42,50,36,29,32};intmkuozhan[]={32,1,2,3,4,5,4,5,6,7,8,9,8,9,10,11,12,13,12,13,14,15,16,17,16,17,18,19,20,21,20,21,22,23,24,25,24,25,26,27,28,29,28,29,30,31,32,1};ints[8][4][16]={//8個s盒{{14,4,13,1,2,15,11,8,3,10,6,12,5,9,0,7},{0,15,7,4,14,2,13,1,10,6,12,11,9,5
7、,3,8},{4,1,14,8,13,6,2,11,15,12,9,7,3,10,5,0},{15,12,8,2,4,9,1,7,5,11,3,14,10,0,6,13}},{{15,1,8,14,6,11,3,4,9,7,2,13,12,0,5,10},{3,13,4,7,15,2,8,14,12,0,1,10,6,9,11,5},{0,14,4,11,10,4,13,1,5,8,12,6,9,3,2,15},{13,8,10,1,3,15,4,2,11,6,7,12,0,5,14,9}},{{10,0,9,14,6,3,15,5,1
8、,13,12,7,11,4,2,8},{13,7,0,9,3,4,6,10,2,8,5,14,12,11,15,1},{13,6,4,9,8,15,3,0,11,1,2,12,5,10,14,7},{1,1