檢視 模板:資訊安全:SDES 的原始碼
←
模板:資訊安全:SDES
前往:
導覽
,
搜尋
由於下列原因,您沒有權限進行 編輯此頁面 的動作:
您請求的操作只有這個群組的使用者能使用:
管理員
您可以檢視並複製此頁面的原始碼。
===Simplified DES=== * [http://sdrv.ms/YX9S0s S-DES教學] * [http://sdrv.ms/125igf1 S-DES填空表單] Simplified DES (S-DES) has similar properties and structure to DES with much smaller parameters (See following S-DES scheme). ====s-DES Scheme(S-DES 圖解)==== [[File:S-DES Scheme.png|600px]] ====s-DES 金鑰產生過程==== Following is the key generation process: [[File:Key Generation for S-DES.png|600px]] ====s-DES加密過程==== Encryption: [[File:S-DES Encryption Detail.png|600px]] ====S-DES的Java程式==== <source lang="c"> public class sdes{ private static short[] plainText={0,0,0,0,0,0,0,0}; //明文空間,將輸入的8位元一一放入此short陣列(為求運算方便) private static short[] Key1 ={1,0,1,0,0,1,0,0}; //子金鑰1 private static short[] Key2 ={0,1,0,0,0,0,1,1};//子金鑰2 private static short[] bitIndex={128,64,32,16,8,4,2,1}; private static char[] IP = {'1','5','2','0','3','7','4','6'}; //"26314857"; private static char[] IP1 = {'3','0','2','4','6','1','7','5'}; //"41357286"; private static char[] EP = {'3','0','1','2','1','2','3','0'}; //"41232341"; private static char[] P4 = {'1','3','2','0'}; //"2431"; private static char[] SW = {'4','5','6','7','0','1','2','3'}; //"56781234"; private static char[] P8 = {'5','2','6','3','7','4','9','8'}; //637485A9"; private static char[] P10 = {'2','4','1','6','3','9','0','8','7','5'}; //35274A1986"; private static short[][] S0 = {{1,0,3,2}, {3,2,1,0}, {0,2,1,3}, {3,1,3,2}}; private static short[][] S1 = {{0,1,2,3}, {2,0,1,3}, {3,0,1,0}, {2,1,0,3}}; private static short[] tempText = {0,0,0,0,0,0,0,0}; private static void printText(short[] Text){ int i; for(i=0;i<8;i++) System.out.print(Text[i]); System.out.println(); } public static void fx(short[] PT, short[] Key){ int i,r,c,s; short[] leftText = {0,0,0,0}; short[] rightText = {0,0,0,0}; short[] fText = {0,0,0,0,0,0,0,0}; short[] temp4Text = {0,0,0,0}; for(i=4;i<8;i++) rightText[i-4] = PT[i]; //extract right part of plaintext //perform EP for(i=0; i<8; i++) tempText[i] = rightText[(short)EP[i]-48]; for(i=0; i<8; i++) fText[i] = tempText[i]; System.out.print("After E/P : ");printText(fText); for(i=0; i<8; i++) fText[i] ^= Key[i]; //Xor! System.out.print("Key is "); printText(Key); System.out.print("After XOR with Key : ");printText(fText); for(i=0;i<4;i++) leftText[i] = fText[i]; for(i=4;i<8;i++) rightText[i-4] = fText[i]; //perform S0 and S1 r = (leftText[0]<<1) + leftText[3]; System.out.print("S0, Row is "+r+","); c = (leftText[1]<<1) + leftText[2]; System.out.print("Col is "+c+" "); s = S0[r][c]; System.out.println("S0 is "+s); temp4Text[0] = ((s&2) == 0)? (short)0:(short)1; temp4Text[1] = ((s&1) == 0)? (short)0:(short)1; r = (rightText[0]<<1) + rightText[3]; System.out.print("S1, Row is "+r+","); c = (rightText[1]<<1) + rightText[2]; System.out.print("Col is "+c+" "); s = S1[r][c]; System.out.println("S1 is "+s); temp4Text[2] = ((s&2) == 0)? (short)0:(short)1; temp4Text[3] = ((s&1) == 0)? (short)0:(short)1; //Perform P4 for(i=0; i<4; i++) tempText[i] = temp4Text[(short)P4[i]-48]; for(i=0; i<4; i++) temp4Text[i] = tempText[i]; System.out.print("Apply P4 "); for(i=0; i<4; i++) System.out.print(temp4Text[i]); System.out.println(); for(i=0; i<4; i++) leftText[i] = PT[i]; //Xor left and right processed with F-Box System.out.print("After XOR with the left part(See the above of diagram):"); for(i=0; i<4; i++) { leftText[i] ^= temp4Text[i]; System.out.print(leftText[i]); } System.out.println(); for(i=0; i<4; i++) PT[i] = leftText[i]; } public static void main(String args[]){ short plainInt,i; if (args.length == 0) System.exit(0); plainInt = Short.parseShort(args[0]); //將將輸入的明文字串轉換成short for (i=0; i<8; i++) plainText[i] = ((plainInt & bitIndex[i])== 0) ? (short)0 : (short)1; //將明文數字中的每一個位元一一抓取出來測試,設定明文陣列 System.out.print("The plaintext is "); printText(plainText); //Perform IP operation for(i=0; i<8; i++) tempText[i] = plainText[(short)IP[i]-48]; for(i=0; i<8; i++) plainText[i] = tempText[i]; System.out.print("plaintexst after IP is "); printText(plainText); //Round 1 System.out.println("Round 1..... "); fx(plainText, Key1); System.out.print("After round1, the plaintext is ");printText(plainText); //Perform SW for(i=0; i<8; i++) tempText[i] = plainText[(short)SW[i]-48]; for(i=0; i<8; i++) plainText[i] = tempText[i]; System.out.print("After SW, plaintext is "); printText(plainText); //Round 2 System.out.println("\nRound 2..... "); fx(plainText, Key2); System.out.print("After round 2, the plaintext is ");printText(plainText); //Perform IP-1 for(i=0; i<8; i++) tempText[i] = plainText[(short)IP1[i]-48]; for(i=0; i<8; i++) plainText[i] = tempText[i]; System.out.print("Finally, ciphertext is "); printText(plainText); } } </source>
返回至
模板:資訊安全:SDES
。
導覽選單
個人工具
登入
命名空間
模板
討論
變體
檢視
閱讀
檢視原始碼
檢視歷史
更多
搜尋
導覽
首頁
基本資料
專案計劃
教授課程(本學期)
創意3D列印實務
程式設計
資料結構
WordPress
教授課程(所有)
資訊安全
科技英文
資料庫管理
管理專業英文
管理資訊系統
作業系統
專利與發明
程式設計
學生專題
網路概論
技術與學習
Delphi XE
3D印表機
SCJP考題
Arduino/pcDuino
Android
Linux/Unix
虛擬/雲端作業系統
網站功能
Wiki安裝設定筆記
隨機頁面
說明
工具
連結至此的頁面
相關變更
特殊頁面
頁面資訊