
Encrypt04.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | public class Encrypt04 { // 密碼表字元陣列 private char [] code = new char [26]; // 建構子 public Encrypt04() { setCode(); } // setter public void setCode() { int a = 0; int b = 0; a = ( int ) (Math.random() * 10); System.out. printf ( "%d, " , a); b = ( int ) (Math.random() * 10); System.out. printf ( "%d, " , b); int x, y, m, i; char c = 'a' ; for (i = 0; i < 26; i++) { x = c; y = x * a + b; m = y % 26; code[i] = ( char ) (m + 97); c++; } } // getter public char [] getCode() { return code; } // 編碼的方法 public String toEncode(String s) { return s; } // 解碼的方法 public String toDecode(String s) { return s; } // 測試的 main() public static void main(String[] args) { for ( int i = 0; i < 16; i++) { Encrypt04 e = new Encrypt04(); System.out.println(e.getCode()); } //String s = "There is no spoon"; //System.out.println(s); //String s1 = e.toEncode(s); //System.out.println(s1); //String s2 = e.toDecode(s1); //System.out.println(s2); } } /* 檔名: Encrypt04.java 作者: Kaiching Chang 時間: September, 2014 */ |
Encrypt05.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | public class Encrypt05 { // 密碼表字元陣列 private char [] code = new char [26]; // 建構子 public Encrypt05() { setCode(); } // setter public void setCode() { int a = 0; int b = 0; while (a % 2 == 0) { a = ( int ) (Math.random() * 10); b = ( int ) (Math.random() * 10); } System.out. printf ( "%d, " , a); System.out. printf ( "%d, " , b); int x, y, m, i; char c = 'a' ; for (i = 0; i < 26; i++) { x = c; y = x * a + b; m = y % 26; code[i] = ( char ) (m + 97); c++; } } // getter public char [] getCode() { return code; } // 編碼的方法 public String toEncode(String s) { return s; } // 解碼的方法 public String toDecode(String s) { return s; } // 測試的 main() public static void main(String[] args) { for ( int i = 0; i < 16; i++) { Encrypt05 e = new Encrypt05(); System.out.println(e.getCode()); } //String s = "There is no spoon"; //System.out.println(s); //String s1 = e.toEncode(s); //System.out.println(s1); //String s2 = e.toDecode(s1); //System.out.println(s2); } } /* 檔名: Encrypt05.java 作者: Kaiching Chang 時間: September, 2014 */ |
the end

沒有留言:
張貼留言