這是Herr Deng桑的教學blog,主要處理作業與班導事務,另外還有數位小品。
明文:enigma老師,程式碼這樣貼可以嗎?如果不行或有錯誤,麻煩老師告知,謝謝程式碼:package 密碼1;import java.util.*;public class 密碼1_2 { static char T(char p,int key) {System.out.print( (char) (((int)(p-'a')+26-key)%26+'a')); return 0; } public static void main(String[] args) {Scanner sc=new Scanner(System.in);System.out.println("請輸入密文");String a=sc.next();char A[]=new char[a.length()]; for(int i=0 ;i<A.length;i++)A[i]=a.charAt(i); for(int K=1;K<26; K++){System.out.print("當KEY="+K+"時"); for(int i=0 ;i<A.length;i++) { char ch=A[i]; T(ch,K); }System.out.println("");
X=24,G=7,B=2,Z=26,F=6,T=20各減-1 到第7次得出ENIGMA
如無意外的話,明文是"ENIGMA"且鑰匙是第 7 把此程式碼使用 javascript 撰寫(不是 JAVA )程式碼:http://paste.plurk.com/show/1316919/可操作的網頁版:http://momijicore.co.cc/test/Caesar.html
package P1;import java.util.*;public class 密碼學 { static char decrypt(char p, int Key) { return (char) (((int)(p-'a')+26-Key)%26+'a'); } public static void main(String[] args) { String z; Scanner sc= new Scanner(System.in); System.out.println("輸入密文:"); z=sc.next(); char x[] =new char [z.length()]; int i=0,a=1; while(i<x.length) { x[i]=z.charAt(i); i++; } while(a<=25) { System.out.println(""); int q=0; System.out.print("key="+a+" "); while(q<x.length) { System.out.print(decrypt(x[q], a)); q++; } a++; } }}答案: key=19 enigma 翻譯:謎翻譯出處:http://www.bing.com/translator/?MKT=zh-TW
static char decrypt(char p, int Key){return (char) (((int)(p-'a')+26-Key)%26+'a');}public static void main(String[] args) {Scanner sc=new Scanner(System.in);System.out.print("輸入密文");String a = sc.next();int s = a.length();char[] b = a.toCharArray();for(int j=1;j<=26;j++){System.out.println("第"+j+"把鑰匙");for(int i=0;i<s;i++){System.out.print(decrypt(b[i],j));} System.out.println();}}第19把鑰匙:enigma
package tt;import java.util.*;public class t1 { static char decrypt(char p,int key){ return(char) (((int)(p-'a')+26-key)%26+'a'); } public static void main(String[] args){ Scanner sc=new Scanner(System.in); System.out.println("請輸入密文"); String a=sc.next(); char p[]=new char[a.length()]; for(int i=0 ;i<p.length;i++) p[i]=a.charAt(i); for(int j=1;j<26; j++){ for(int i=0 ;i<p.length;i++){ char t=p[i]; System.out.print(decrypt(t,j)); } System.out.println(""); }}}明文:enigma
明文是Enigma Caesar shift cipher 是以英文字母為數值增加,改變的元單字改寫方法X=24,G=7,B=2,Z=26,F=6,T=20以每次-1的方式暴力破解,會在K=7時得到Enigma
xgbzftyhcaguzidbhvajeciwbkfdjxclgekydmhflzenigma=ENIGMA密碼有意義明文:enigma
在第19把金鑰得出明文:enigma原始碼:package enigma;import java.util.*;public class CaesarShiftCipher { static char decrypt(char p, int Key) { return (char) (((int)(p-'a')+26-Key)%26+'a'); } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("輸入密文"); String ciphertext =input.next(); char text[]=new char[ciphertext.length()]; int no = 0, textlenght = ciphertext.length(); while(no != textlenght) { text[no] = ciphertext.charAt(no); no++; } //System.out.println(text); xgbzft for (int i=1;i<=26;i++) { System.out.print("第"+i+"把金鑰:"); for (int j=0;j<text.length;j++) {System.out.print(decrypt(text[j],i));} System.out.println(); } }}
X=23 G=4 B=1 Z=25 F=5 T=19M-K(MOD26)K=1923-19(MOD26)=4=E4-19(MOD26)=13=N1-19(MOD26)=8=I25-19(MOD26)=2=C5-19(MOD26)=12=MT-19(MOD26)=0=A
X=23 G=4 B=1 Z=25 F=5 T=19M(23 4 1 25 5 19)-K(MOD26)K=1~19 求得:23-19(MOD26)=4=E4-19(MOD26)=13=N1-19(MOD26)=8=I25-19(MOD26)=2=C5-19(MOD26)=12=MT-19(MOD26)=0=AAns: enicma
1:YHCAGU 2:ZIDBHV 3:AJECIW 4:BKFDJX 5:CLGEKY 6:DMHFLZ 7:ENIGMA 8:FOJHNB 9:GPKIOC 10:HQLJPD11:IRMKQE 12:JSNLRF 13:KTOMSG 14:LUPNTH 15:MVQOUI 16:NWRPVJ 17:OXSQWK 18:PYTRXL 19:QZUSYM 20:RAVTZN 21:SBWUAO 22:TCXVBP 23:UDYWCQ 24:VEZXDR 25:WFAYES由第7把得出明文"ENIGMA"
ENIGMAX=24,G=7,B=2,Z=26,F=6,T=20Xgbzft每次-1的方法暴力破解在第7次時得到明文ENIGMA
package P1;import java.util.*;public class 密碼學作業 { static char decrypt(char p, int Key) { return (char) (((int)(p-'a')+26-Key)%26+'a'); } public static void main(String[] args) { String z; Scanner sc= new Scanner(System.in); System.out.println("密文輸入:"); z=sc.next(); char y[] =new char [z.length()]; int i=0,u=1; for(int g=0 ;g<y.length;g++) { y[i]=z.charAt(g); } while(u<=25) { System.out.println(""); int q=0; System.out.print("第"+u+"把key"); while(q<y.length) { System.out.print(decrypt(y[q], u)); q++; } u++; } }}第19把key:enigma
package work1;import java.util.*;public class Use035 { static char 密碼文(char p, int Key) { return (char) (((int)(p-'a')+26-Key)%26+'a'); } public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.print("輸入密文"); String a = sc.next(); int s = a.length(); char[] b = a.toCharArray(); for(int x=1;x<=26;x++) { System.out.println("第"+x+"把鑰匙"); for(int i=0;i<s;i++) { System.out.print(密碼文(b[i],x)); } System.out.println(); } }}第19把KEY:enigma
明文 : ENIGMAX=24,G=7,B=2,Z=26,F=6,T=20KEY = 7參考網址:http://web.forret.com/tools/rot13.asp?rot=7&cipher=XGBZFT&clear=xgbzft&dir=encrypt
package P1;import java.util.*;public class B10033160 {static char decrypt(char p, int Key){return (char) (((int)(p-'a')+26-Key)%26+'a');}public static void main(String[] args) {String z;Scanner sc= new Scanner(System.in);System.out.println("輸入密文:");z=sc.next();char x[] =new char [z.length()];int i=0,a=1;while(i<x.length){x[i]=z.charAt(i);i++;}while(a<=25){System.out.println("");int q=0;System.out.print("key="+a+" ");while(q<x.length){System.out.print(decrypt(x[q], a));q++;}a++;}}}key=19 enigma
程式碼:function decodeCaesar(input){output=new Array;chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";output_.innerHTML=""; for(i=0;i<26;i++){ str=new String; for(j=0;j<input.length;j++){ str+=chars[(chars.search(input.charAt(j))+i)%26]; } output.push(str); } return output;}鑰匙是第 7 把可操作的網頁版:http://momijicore.co.cc/test/Caesar.html
decodeCaesar(input){output=new Array;chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";output_.innerHTML=""; for(i=0;i<26;i++){ str=new String; for(j=0;j<input.length;j++){ str+=chars[(chars.search(input.charAt(j))+i)%26]; } output.push(str); } return output;}且鑰匙是第 7 把可操作的網頁版:http://momijicore.co.cc/test/Caesar.html
根據解密函數D(c)=c-k k的範圍從1到25當k=19可解出明文 enigma
明文:ENIGMA解密的網頁:https://sites.google.com/site/913notebook/nwlahyc-yjcq-rb-odw-pjvn-cx-yujh
XGBZFTENIGMA參考來源https://sites.google.com/site/913notebook/nwlahyc-yjcq-rb-odw-pjvn-cx-yujh
package P1;import java.util.*;public class 密碼學作業{static char 密文(char p,int key){return(char) (((int)(p-'a')+26-key)%26+'a');}public static void main(String[] args){Scanner sc=new Scanner(System.in);System.out.println("輸入密文");String a=sc.next();char p[]=new char[a.length()];for(int i=0 ;i<p.length;i++)p[i]=a.charAt(i);for(int b=1;b<26; b++){System.out.print("第"+b+"組密碼");for(int x=0 ;x<p.length;x++){char t=p[x];System.out.print(密文(t,b));}System.out.println("");}}}第19把鑰匙=enigma
ENIGMA IST NICHT EINFACH ZU BRECHENpackage P1;import java.util.*;public class 密碼學作業{static char 密文(char p,int key){return(char) (((int)(p-'a')+26-key)%26+'a');}public static void main(String[] args){Scanner sc=new Scanner(System.in);System.out.println("輸入密文");String a=sc.next();char p[]=new char[a.length()];for(int i=0 ;i<p.length;i++)p[i]=a.charAt(i);for(int b=1;b<26; b++){System.out.print("第"+b+"組密碼");for(int x=0 ;x<p.length;x++){char t=p[x];System.out.print(密文(t,b));}System.out.println("");}}}第19把鑰匙=enigma
X=24,G=7,B=2,Z=26,F=6,T=20k=1~19 24-19(MOD267-19(mod262-19(mod2626-19(mod266-19(mod2620-19(mod26A:ENIGMA
ENIGMAX=24,G=7,B=2,Z=26,F=6,T=20Xgbzft每次-1的方法暴力破解在第7次時得到ENIGMA
decodeCaesar(input){output=new Array;chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";output_.innerHTML=""; for(i=0;i<26;i++){ str=new String; for(j=0;j<input.length;j++){ str+=chars[(chars.search(input.charAt(j))+i)%26]; } output.push(str); } return output;}且鑰匙是第 7 把
package P1;import java.util.*;public class 密碼學 { static char decrypt(char p, int Key) { return (char) (((int)(p-'a')+26-Key)%26+'a'); } public static void main(String[] args) { String z; Scanner sc= new Scanner(System.in); System.out.println("輸入密文:");z=sc.next(); char x[] =new char [z.length()]; int i=0,a=1; while(i<x.length) { x[i]=z.charAt(i); i++; } while(a<=25) { System.out.println(""); int q=0; System.out.print("key="+a+" "); while(q<x.length) { System.out.print(decrypt(x[q], a)); q++; } a++; } }}資料來源:翻譯出處:http://www.bing.com/translator/?MKT=zh-TW
static char decrypt(char p, int Key){return (char) (((int)(p-'a')+26-Key)%26+'a');}public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.print("密文");String x = sc.next();int str = x.length();char[] b = x.toCharArray();for(int i=1;i<=26;i++){System.out.println("第"+i+"把Key");for(int j=0;j<str;j++){System.out.print(decrypt(b[j],i));} System.out.println();}}答:enigma
package P1;import java.util.*;public class 密碼學 { static char decrypt(char p, int Key) { return (char) (((int)(p-'a')+26-Key)%26+'a'); } public static void main(String[] args) { String z; Scanner sc= new Scanner(System.in); System.out.println("輸入密文:");z=sc.next(); char x[] =new char [z.length()]; int i=0,a=1; while(i<x.length) { x[i]=z.charAt(i); i++; } while(a<=25) { System.out.println(""); int q=0; System.out.print("key="+a+" "); while(q<x.length) { System.out.print(decrypt(x[q], a)); q++; } a++; } }}答案: key=19 enigma 翻譯:謎翻譯出處:http://www.bing.com/translator/?MKT=zh-TW
明文是Enigma
X=24,G=7,B=2,Z=26,F=6,T=20Xgbzft每次-1的方法暴力破解在第7次時得到ENIGMA 0:XGBZFT1:YHCAGU2:ZIDBHV3:AJECIW4:BKFDJX5:CLGEKY6:DMHFLZ7:ENIGMA8:FOJHNB9:GPKIOC10:HQLJPD11:IRMKQE12:JSNLRF13:KTOMSG14:LUPNTH15:MVQOUI16:NWRPVJ17:OXSQWK18:PYTRXL19:QZUSYM20:RAVTZN21:SBWUAO22:TCXVBP23:UDYWCQ24:VEZXDR25:WFAYES
ENIGMAX=24,G=7,B=2,Z=26,F=6,T=200:XGBZFT1:YHCAGU2:ZIDBHV3:AJECIW4:BKFDJX5:CLGEKY6:DMHFLZ7:ENIGMA(此碼有意義)
package p1;import java.util.*;public class B10033156 {static char decrypt(char p, int Key){return (char) (((int)(p-'a')+26-Key)%26+'a');}public static void main(String[] args) {String z;Scanner sc= new Scanner(System.in);System.out.println("輸入密文:");z=sc.next();char x[] =new char [z.length()];int i=0,a=1;while(i<x.length){x[i]=z.charAt(i);i++;}while(a<=25){System.out.println("");int q=0;System.out.print("key="+a+" ");while(q<x.length){System.out.print(decrypt(x[q], a));q++;}a++;}}}答案: enigma
0.xgbzft1.yhcagu2.zidbhv3.ajeciw4.bkfdjx5.clgeky6.dmhflz7.enigma8.fojhnb9.gpkoc10.hqljpd11.irmkqe12.jsnlrf13.ktomsg14.lupnth15.mvqoui16.nwrpvj17.oxsqwk18.pytrxl19.qzusym20.ravtzn21.sbwuao22.tcxvbp23.udywcq24.vezxdr25.wfayes明文:enigma
明文 : ENIGMAX=24,G=7,B=2,Z=26,F=6,T=20KEY = 7
package P1;import java.util.*;public class hello {static char decrypt(char p, int Key){return (char) (((int)(p-'a')+26-Key)%26+'a');}public static void main(String[] args) {String z;Scanner sc= new Scanner(System.in);System.out.println("密文輸入:");z=sc.next();char y[] =new char [z.length()];int i=0,u=1;for(int g=0 ;g<y.length;g++){y[i]=z.charAt(g); }while(u<=25){System.out.println("");int q=0;System.out.print("第"+u+"把key");while(q<y.length){System.out.print(decrypt(y[q], u));q++;}u++;}}}第19把key:enigma
package P1;import java.util.*;public class test {static char decrypt(char p, int Key){return (char) (((int)(p-'a')+26-Key)%26+'a');}public static void main(String[] args) {String z;Scanner sc= new Scanner(System.in);System.out.println("密文輸入:");z=sc.next();char y[] =new char [z.length()];int i=0,u=1;for(int g=0 ;g<y.length;g++){y[i]=z.charAt(g); }while(u<=25){System.out.println("");int q=0;System.out.print("第"+u+"把key");while(q<y.length){System.out.print(decrypt(y[q], u));q++;}u++;}}}第19把key:enigma
package P1;import java.util.*;public class 密碼學作業 {static char decrypt(char p, int Key){return (char) (((int)(p-'a')+26-Key)%26+'a');}public static void main(String[] args) {String z;Scanner sc= new Scanner(System.in);System.out.println("密文輸入:");z=sc.next();char y[] =new char [z.length()];int i=0,u=1;for(int g=0 ;g<y.length;g++){y[i]=z.charAt(g); }while(u<=25){System.out.println("");int q=0;System.out.print("第"+u+"把key");while(q<y.length){System.out.print(decrypt(y[q], u));q++;}u++;}}}第19把key:enigma
package P1;import java.util.*;public class b10033128 {static char decrypt(char p, int Key){return (char) (((int)(p-'a')+26-Key)%26+'a');}public static void main(String[] args) {String z;Scanner sc= new Scanner(System.in);System.out.println("密文輸入:");z=sc.next();char y[] =new char [z.length()];int i=0,u=1;for(int g=0 ;g<y.length;g++){y[i]=z.charAt(g); }while(u<=25){System.out.println("");int q=0;System.out.print("第"+u+"把key");while(q<y.length){System.out.print(decrypt(y[q], u));q++;}u++;}}}第19把key:enigma
X=24,G=7,B=2,Z=26,F=6,T=20Key 7明文:Enigma
0:XGBZFT1:YHCAGU2:ZIDBHV3:AJECIW4:BKFDJX5:CLGEKY6:DMHFLZ7:ENIGMA8:FOJHNB9:GPKIOC10:HQLJPD11:IRMKQE12:JSNLRF13:KTOMSG14:LUPNTH15:MVQOUI16:NWRPVJ17:OXSQWK18:PYTRXL19:QZUSYM20:RAVTZN21:SBWUAO22:TCXVBP23:UDYWCQ24:VEZXDR25:WFAYES明文: ENIGMA
k=0,xgbzftk=1,yhcaguk=2,zidbhvk=3,ajeciwk=4,bkfdjxk=5,clgekyk=6,dmhflzk=7,enigma明文:enigma
0.xgbzft1.yhcagu2.zidbhv3.ajeciw4.bkfdjx5.clgeky6.dmhflz7.enigma8.fojhnb9.gpkoc10.hqljpd11.irmkqe12.jsnlrf13.ktomsg14.lupnth15.mvqoui16.nwrpvj17.oxsqwk18.pytrxl19.qzusym20.ravtzn21.sbwuao22.tcxvbp23.udywcq24.vezxdr25.wfayes7:明文:enigma
package P1;import java.util.*;public class B9733002鍾志捷{static char decrypt(char p, int Key){return (char) (((int)(p-'a')+26-Key)%26+'a');}public static void main(String[] args){String z;Scanner sc= new Scanner(System.in);System.out.println("密文輸入:");z=sc.next();char y[] =new char [z.length()];int i=0,u=1;for(int g=0 ;g<y.length;g++){y[i]=z.charAt(g);}while(u<=25){System.out.println("");int q=0;System.out.print("第"+u+"把key");while(q<y.length){System.out.print(decrypt(y[q], u));q++;}u++;}}}第19把key:enigma
package tt;import java.util.*;public class t1 {static char decrypt(char p,int key){return(char) (((int)(p-'a')+26-key)%26+'a');} public static void main(String[] args){Scanner sc=new Scanner(System.in);System.out.println("請輸入密文");String a=sc.next();char p[]=new char[a.length()];for(int i=0 ;i<p.length;i++)p[i]=a.charAt(i); for(int j=1;j<26; j++){for(int i=0 ;i<p.length;i++){char t=p[i];System.out.print(decrypt(t,j));}System.out.println("");}}}明文:enigma
package P1;import java.util.*;public class 密碼學 { static char decrypt(char p, int Key) { return (char) (((int)(p-'a')+26-Key)%26+'a'); } public static void main(String[] args) { String z; Scanner sc= new Scanner(System.in); System.out.println("輸入密文:");z=sc.next(); char x[] =new char [z.length()]; int i=0,a=1; while(i<x.length) { x[i]=z.charAt(i); i++; } while(a<=25) { System.out.println(""); int q=0; System.out.print("key="+a+" "); while(q<x.length) { System.out.print(decrypt(x[q], a)); q++; } a++; } }}答案: key=19 enigma
package P1;import java.util.*;public class 密碼學{static char decrypt(char p, int Key){return (char) (((int)(p-'a')+26-Key)%26+'a');}public static void main(String[] args){String z;Scanner sc= new Scanner(System.in);System.out.println("輸入密文:");z=sc.next();char x[] =new char [z.length()];int i=0,a=1;while(i<x.length){x[i]=z.charAt(i);i++;}while(a<=25){System.out.println("");int q=0;System.out.print("key="+a+" ");while(q<x.length){System.out.print(decrypt(x[q], a));q++;}a++;}}}資料來源:翻譯出處:http://www.bing.com/translator/?MKT=zh-TW
1:YHCAGU 2:ZIDBHV 3:AJECIW 4:BKFDJX 5:CLGEKY 6:DMHFLZ 7:ENIGMA 8:FOJHNB 9:GPKIOC 10:HQLJPD11:IRMKQE 12:JSNLRF 13:KTOMSG 14:LUPNTH 15:MVQOUI 16:NWRPVJ 17:OXSQWK 18:PYTRXL 19:QZUSYM 20:RAVTZN 21:SBWUAO 22:TCXVBP 23:UDYWCQ 24:VEZXDR 25:WFAYES由第7把得出明文"ENIGMA
package P1;import java.util.*;public class 密碼學 {static char decrypt(char p, int Key){return (char) (((int)(p-'a')+26-Key)%26+'a');}public static void main(String[] args) {String z;Scanner sc= new Scanner(System.in);System.out.println("輸入密文:");z=sc.next();char x[] =new char [z.length()];int i=0,a=1;while(i<x.length){x[i]=z.charAt(i);i++;}while(a<=25){System.out.println("");int q=0;System.out.print("key="+a+" ");while(q<x.length){System.out.print(decrypt(x[q], a));q++;}a++;}}}答案: key=19 enigma
package P1;import java.util.*;public class 密碼學 {static char decrypt(char p, int Key){return (char) (((int)(p-'a')+26-Key)%26+'a');}public static void main(String[] args) {String z;Scanner sc= new Scanner(System.in);System.out.println("輸入密文:");z=sc.next();char x[] =new char [z.length()];int i=0,a=1;while(i<x.length){x[i]=z.charAt(i);i++;}while(a<=25){System.out.println("");int q=0;System.out.print("key="+a+" ");while(q<x.length){System.out.print(decrypt(x[q], a));q++;}a++;}}}答案: key=19 enigma 翻譯:謎翻譯出處:http://www.bing.com/translator/?MKT=zh-TW
package P1;import java.util.*;public class 密碼學 {static char decrypt(char p, int Key){return (char) (((int)(p-'a')+26-Key)%26+'a');}public static void main(String[] args) {String z;Scanner sc= new Scanner(System.in);System.out.println("輸入密文:");z=sc.next();char x[] =new char [z.length()];int i=0,a=1;while(i<x.length){x[i]=z.charAt(i);i++;}while(a<=25){System.out.println("");int q=0;System.out.print("key="+a+" ");while(q<x.length){System.out.print(decrypt(x[q], a));q++;}a++;}}}
程式碼:function decodeCaesar(input){output=new Array;chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";output_.innerHTML="";for(i=0;i<26;i++){str=new String;for(j=0;j<input.length;j++){str+=chars[(chars.search(input.charAt(j))+i)%26];}output.push(str);}return output;}鑰匙是第 7 把
張貼留言
63 則留言:
明文:enigma
老師,程式碼這樣貼可以嗎?
如果不行或有錯誤,麻煩老師告知,謝謝
程式碼:
package 密碼1;
import java.util.*;
public class 密碼1_2
{
static char T(char p,int key)
{
System.out.print( (char) (((int)(p-'a')+26-key)%26+'a'));
return 0;
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("請輸入密文");
String a=sc.next();
char A[]=new char[a.length()];
for(int i=0 ;i<A.length;i++)
A[i]=a.charAt(i);
for(int K=1;K<26; K++)
{
System.out.print("當KEY="+K+"時");
for(int i=0 ;i<A.length;i++)
{
char ch=A[i];
T(ch,K);
}
System.out.println("");
X=24,G=7,B=2,Z=26,F=6,T=20
各減-1 到第7次得出
ENIGMA
如無意外的話,明文是"ENIGMA"
且鑰匙是第 7 把
此程式碼使用 javascript 撰寫(不是 JAVA )
程式碼:
http://paste.plurk.com/show/1316919/
可操作的網頁版:
http://momijicore.co.cc/test/Caesar.html
package P1;
import java.util.*;
public class 密碼學
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("輸入密文:");
z=sc.next();
char x[] =new char [z.length()];
int i=0,a=1;
while(i<x.length)
{
x[i]=z.charAt(i);
i++;
}
while(a<=25)
{
System.out.println("");
int q=0;
System.out.print("key="+a+" ");
while(q<x.length)
{
System.out.print(decrypt(x[q], a));
q++;
}
a++;
}
}
}
答案: key=19 enigma 翻譯:謎
翻譯出處:http://www.bing.com/translator/?MKT=zh-TW
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("輸入密文");
String a = sc.next();
int s = a.length();
char[] b = a.toCharArray();
for(int j=1;j<=26;j++){
System.out.println("第"+j+"把鑰匙");
for(int i=0;i<s;i++){
System.out.print(decrypt(b[i],j));
}
System.out.println();
}
}
第19把鑰匙:enigma
package tt;
import java.util.*;
public class t1 {
static char decrypt(char p,int key){
return(char) (((int)(p-'a')+26-key)%26+'a');
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("請輸入密文");
String a=sc.next();
char p[]=new char[a.length()];
for(int i=0 ;i<p.length;i++)
p[i]=a.charAt(i);
for(int j=1;j<26; j++){
for(int i=0 ;i<p.length;i++){
char t=p[i];
System.out.print(decrypt(t,j));
}
System.out.println("");
}
}
}
明文:enigma
明文是Enigma
Caesar shift cipher 是以英文字母為數值增加,改變的元單字改寫方法
X=24,G=7,B=2,Z=26,F=6,T=20
以每次-1的方式暴力破解,會在K=7時得到
Enigma
xgbzft
yhcagu
zidbhv
ajeciw
bkfdjx
clgeky
dmhflz
enigma=ENIGMA密碼有意義
明文:enigma
在第19把金鑰得出明文:enigma
原始碼:
package enigma;
import java.util.*;
public class CaesarShiftCipher
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("輸入密文");
String ciphertext =input.next();
char text[]=new char[ciphertext.length()];
int no = 0,
textlenght = ciphertext.length();
while(no != textlenght)
{
text[no] = ciphertext.charAt(no);
no++;
}
//System.out.println(text); xgbzft
for (int i=1;i<=26;i++)
{
System.out.print("第"+i+"把金鑰:");
for (int j=0;j<text.length;j++)
{System.out.print(decrypt(text[j],i));}
System.out.println();
}
}
}
X=23 G=4 B=1 Z=25 F=5 T=19
M-K(MOD26)
K=19
23-19(MOD26)=4=E
4-19(MOD26)=13=N
1-19(MOD26)=8=I
25-19(MOD26)=2=C
5-19(MOD26)=12=M
T-19(MOD26)=0=A
X=23 G=4 B=1 Z=25 F=5 T=19
M(23 4 1 25 5 19)-K(MOD26)
K=1~19
求得:
23-19(MOD26)=4=E
4-19(MOD26)=13=N
1-19(MOD26)=8=I
25-19(MOD26)=2=C
5-19(MOD26)=12=M
T-19(MOD26)=0=A
Ans: enicma
1:YHCAGU
2:ZIDBHV
3:AJECIW
4:BKFDJX
5:CLGEKY
6:DMHFLZ
7:ENIGMA
8:FOJHNB
9:GPKIOC
10:HQLJPD
11:IRMKQE
12:JSNLRF
13:KTOMSG
14:LUPNTH
15:MVQOUI
16:NWRPVJ
17:OXSQWK
18:PYTRXL
19:QZUSYM
20:RAVTZN
21:SBWUAO
22:TCXVBP
23:UDYWCQ
24:VEZXDR
25:WFAYES
由第7把
得出明文"ENIGMA"
ENIGMA
X=24,G=7,B=2,Z=26,F=6,T=20
Xgbzft每次-1的方法暴力破解在第7次時得到明文ENIGMA
package P1;
import java.util.*;
public class 密碼學作業
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("密文輸入:");
z=sc.next();
char y[] =new char [z.length()];
int i=0,u=1;
for(int g=0 ;g<y.length;g++)
{
y[i]=z.charAt(g);
}
while(u<=25)
{
System.out.println("");
int q=0;
System.out.print("第"+u+"把key");
while(q<y.length)
{
System.out.print(decrypt(y[q], u));
q++;
}
u++;
}
}
}
第19把key:enigma
package work1;
import java.util.*;
public class Use035
{
static char 密碼文(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("輸入密文");
String a = sc.next();
int s = a.length();
char[] b = a.toCharArray();
for(int x=1;x<=26;x++)
{
System.out.println("第"+x+"把鑰匙");
for(int i=0;i<s;i++)
{
System.out.print(密碼文(b[i],x));
}
System.out.println();
}
}
}
第19把KEY:enigma
明文 : ENIGMA
X=24,G=7,B=2,Z=26,F=6,T=20
KEY = 7
參考網址:http://web.forret.com/tools/rot13.asp?rot=7&cipher=XGBZFT&clear=xgbzft&dir=encrypt
package P1;
import java.util.*;
public class B10033160
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("輸入密文:");
z=sc.next();
char x[] =new char [z.length()];
int i=0,a=1;
while(i<x.length)
{
x[i]=z.charAt(i);
i++;
}
while(a<=25)
{
System.out.println("");
int q=0;
System.out.print("key="+a+" ");
while(q<x.length)
{
System.out.print(decrypt(x[q], a));
q++;
}
a++;
}
}
}
key=19 enigma
程式碼:
function decodeCaesar(input){
output=new Array;
chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
output_.innerHTML="";
for(i=0;i<26;i++){
str=new String;
for(j=0;j<input.length;j++){
str+=chars[(chars.search(input.charAt(j))+i)%26];
}
output.push(str);
}
return output;
}
鑰匙是第 7 把
可操作的網頁版:
http://momijicore.co.cc/test/Caesar.html
decodeCaesar(input){
output=new Array;
chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
output_.innerHTML="";
for(i=0;i<26;i++){
str=new String;
for(j=0;j<input.length;j++){
str+=chars[(chars.search(input.charAt(j))+i)%26];
}
output.push(str);
}
return output;
}
且鑰匙是第 7 把
可操作的網頁版:
http://momijicore.co.cc/test/Caesar.html
根據解密函數D(c)=c-k k的範圍從1到25
當k=19可解出明文 enigma
明文:ENIGMA
解密的網頁:https://sites.google.com/site/913notebook/nwlahyc-yjcq-rb-odw-pjvn-cx-yujh
XGBZFT
ENIGMA
參考來源
https://sites.google.com/site/913notebook/nwlahyc-yjcq-rb-odw-pjvn-cx-yujh
package P1;
import java.util.*;
public class 密碼學作業
{
static char 密文(char p,int key){
return(char) (((int)(p-'a')+26-key)%26+'a');
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("輸入密文");
String a=sc.next();
char p[]=new char[a.length()];
for(int i=0 ;i<p.length;i++)
p[i]=a.charAt(i);
for(int b=1;b<26; b++)
{
System.out.print("第"+b+"組密碼");
for(int x=0 ;x<p.length;x++)
{
char t=p[x];
System.out.print(密文(t,b));
}
System.out.println("");
}
}
}
第19把鑰匙=enigma
ENIGMA IST NICHT EINFACH ZU BRECHEN
package P1;
import java.util.*;
public class 密碼學作業
{
static char 密文(char p,int key){
return(char) (((int)(p-'a')+26-key)%26+'a');
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("輸入密文");
String a=sc.next();
char p[]=new char[a.length()];
for(int i=0 ;i<p.length;i++)
p[i]=a.charAt(i);
for(int b=1;b<26; b++)
{
System.out.print("第"+b+"組密碼");
for(int x=0 ;x<p.length;x++)
{
char t=p[x];
System.out.print(密文(t,b));
}
System.out.println("");
}
}
}
第19把鑰匙=enigma
X=24,G=7,B=2,Z=26,F=6,T=20
k=1~19
24-19(MOD26
7-19(mod26
2-19(mod26
26-19(mod26
6-19(mod26
20-19(mod26
A:ENIGMA
ENIGMA
X=24,G=7,B=2,Z=26,F=6,T=20
Xgbzft每次-1的方法暴力破解在第7次時得到ENIGMA
decodeCaesar(input){
output=new Array;
chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
output_.innerHTML="";
for(i=0;i<26;i++){
str=new String;
for(j=0;j<input.length;j++){
str+=chars[(chars.search(input.charAt(j))+i)%26];
}
output.push(str);
}
return output;
}
且鑰匙是第 7 把
package P1;
import java.util.*;
public class 密碼學
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("輸入密文:");
z=sc.next();
char x[] =new char [z.length()];
int i=0,a=1;
while(i<x.length)
{
x[i]=z.charAt(i);
i++;
}
while(a<=25)
{
System.out.println("");
int q=0;
System.out.print("key="+a+" ");
while(q<x.length)
{
System.out.print(decrypt(x[q], a));
q++;
}
a++;
}
}
}
資料來源:翻譯出處:http://www.bing.com/translator/?MKT=zh-TW
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("密文");
String x = sc.next();
int str = x.length();
char[] b = x.toCharArray();
for(int i=1;i<=26;i++){
System.out.println("第"+i+"把Key");
for(int j=0;j<str;j++){
System.out.print(decrypt(b[j],i));
}
System.out.println();
}
}
答:enigma
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("輸入密文");
String a = sc.next();
int s = a.length();
char[] b = a.toCharArray();
for(int j=1;j<=26;j++){
System.out.println("第"+j+"把鑰匙");
for(int i=0;i<s;i++){
System.out.print(decrypt(b[i],j));
}
System.out.println();
}
}
第19把鑰匙:enigma
package P1;
import java.util.*;
public class 密碼學
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("輸入密文:");
z=sc.next();
char x[] =new char [z.length()];
int i=0,a=1;
while(i<x.length)
{
x[i]=z.charAt(i);
i++;
}
while(a<=25)
{
System.out.println("");
int q=0;
System.out.print("key="+a+" ");
while(q<x.length)
{
System.out.print(decrypt(x[q], a));
q++;
}
a++;
}
}
}
答案: key=19 enigma 翻譯:謎
翻譯出處:http://www.bing.com/translator/?MKT=zh-TW
明文是Enigma
X=24,G=7,B=2,Z=26,F=6,T=20
Xgbzft每次-1的方法暴力破解在第7次時得到ENIGMA
0:XGBZFT
1:YHCAGU
2:ZIDBHV
3:AJECIW
4:BKFDJX
5:CLGEKY
6:DMHFLZ
7:ENIGMA
8:FOJHNB
9:GPKIOC
10:HQLJPD
11:IRMKQE
12:JSNLRF
13:KTOMSG
14:LUPNTH
15:MVQOUI
16:NWRPVJ
17:OXSQWK
18:PYTRXL
19:QZUSYM
20:RAVTZN
21:SBWUAO
22:TCXVBP
23:UDYWCQ
24:VEZXDR
25:WFAYES
ENIGMA
X=24,G=7,B=2,Z=26,F=6,T=20
0:XGBZFT
1:YHCAGU
2:ZIDBHV
3:AJECIW
4:BKFDJX
5:CLGEKY
6:DMHFLZ
7:ENIGMA(此碼有意義)
package p1;
import java.util.*;
public class B10033156
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("輸入密文:");
z=sc.next();
char x[] =new char [z.length()];
int i=0,a=1;
while(i<x.length)
{
x[i]=z.charAt(i);
i++;
}
while(a<=25)
{
System.out.println("");
int q=0;
System.out.print("key="+a+" ");
while(q<x.length)
{
System.out.print(decrypt(x[q], a));
q++;
}
a++;
}
}
}
答案: enigma
0.xgbzft
1.yhcagu
2.zidbhv
3.ajeciw
4.bkfdjx
5.clgeky
6.dmhflz
7.enigma
8.fojhnb
9.gpkoc
10.hqljpd
11.irmkqe
12.jsnlrf
13.ktomsg
14.lupnth
15.mvqoui
16.nwrpvj
17.oxsqwk
18.pytrxl
19.qzusym
20.ravtzn
21.sbwuao
22.tcxvbp
23.udywcq
24.vezxdr
25.wfayes
明文:enigma
明文 : ENIGMA
X=24,G=7,B=2,Z=26,F=6,T=20
KEY = 7
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("輸入密文");
String a = sc.next();
int s = a.length();
char[] b = a.toCharArray();
for(int j=1;j<=26;j++){
System.out.println("第"+j+"把鑰匙");
for(int i=0;i<s;i++){
System.out.print(decrypt(b[i],j));
}
System.out.println();
}
}
第19把鑰匙:enigma
package P1;
import java.util.*;
public class hello
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("密文輸入:");
z=sc.next();
char y[] =new char [z.length()];
int i=0,u=1;
for(int g=0 ;g<y.length;g++)
{
y[i]=z.charAt(g);
}
while(u<=25)
{
System.out.println("");
int q=0;
System.out.print("第"+u+"把key");
while(q<y.length)
{
System.out.print(decrypt(y[q], u));
q++;
}
u++;
}
}
}
第19把key:enigma
package P1;
import java.util.*;
public class test
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("密文輸入:");
z=sc.next();
char y[] =new char [z.length()];
int i=0,u=1;
for(int g=0 ;g<y.length;g++)
{
y[i]=z.charAt(g);
}
while(u<=25)
{
System.out.println("");
int q=0;
System.out.print("第"+u+"把key");
while(q<y.length)
{
System.out.print(decrypt(y[q], u));
q++;
}
u++;
}
}
}
第19把key:enigma
package P1;
import java.util.*;
public class 密碼學作業
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("密文輸入:");
z=sc.next();
char y[] =new char [z.length()];
int i=0,u=1;
for(int g=0 ;g<y.length;g++)
{
y[i]=z.charAt(g);
}
while(u<=25)
{
System.out.println("");
int q=0;
System.out.print("第"+u+"把key");
while(q<y.length)
{
System.out.print(decrypt(y[q], u));
q++;
}
u++;
}
}
}
第19把key:enigma
package P1;
import java.util.*;
public class b10033128
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("密文輸入:");
z=sc.next();
char y[] =new char [z.length()];
int i=0,u=1;
for(int g=0 ;g<y.length;g++)
{
y[i]=z.charAt(g);
}
while(u<=25)
{
System.out.println("");
int q=0;
System.out.print("第"+u+"把key");
while(q<y.length)
{
System.out.print(decrypt(y[q], u));
q++;
}
u++;
}
}
}
第19把key:enigma
X=24,G=7,B=2,Z=26,F=6,T=20
Key 7
明文:Enigma
0:XGBZFT
1:YHCAGU
2:ZIDBHV
3:AJECIW
4:BKFDJX
5:CLGEKY
6:DMHFLZ
7:ENIGMA
8:FOJHNB
9:GPKIOC
10:HQLJPD
11:IRMKQE
12:JSNLRF
13:KTOMSG
14:LUPNTH
15:MVQOUI
16:NWRPVJ
17:OXSQWK
18:PYTRXL
19:QZUSYM
20:RAVTZN
21:SBWUAO
22:TCXVBP
23:UDYWCQ
24:VEZXDR
25:WFAYES
明文: ENIGMA
k=0,xgbzft
k=1,yhcagu
k=2,zidbhv
k=3,ajeciw
k=4,bkfdjx
k=5,clgeky
k=6,dmhflz
k=7,enigma
明文:enigma
0.xgbzft
1.yhcagu
2.zidbhv
3.ajeciw
4.bkfdjx
5.clgeky
6.dmhflz
7.enigma
8.fojhnb
9.gpkoc
10.hqljpd
11.irmkqe
12.jsnlrf
13.ktomsg
14.lupnth
15.mvqoui
16.nwrpvj
17.oxsqwk
18.pytrxl
19.qzusym
20.ravtzn
21.sbwuao
22.tcxvbp
23.udywcq
24.vezxdr
25.wfayes
7:明文:enigma
package P1;
import java.util.*;
public class B9733002鍾志捷
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("密文輸入:");
z=sc.next();
char y[] =new char [z.length()];
int i=0,u=1;
for(int g=0 ;g<y.length;g++)
{
y[i]=z.charAt(g);
}
while(u<=25)
{
System.out.println("");
int q=0;
System.out.print("第"+u+"把key");
while(q<y.length)
{
System.out.print(decrypt(y[q], u));
q++;
}
u++;
}
}
}
第19把key:enigma
package tt;
import java.util.*;
public class t1 {
static char decrypt(char p,int key){
return(char) (((int)(p-'a')+26-key)%26+'a');
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("請輸入密文");
String a=sc.next();
char p[]=new char[a.length()];
for(int i=0 ;i<p.length;i++)
p[i]=a.charAt(i);
for(int j=1;j<26; j++){
for(int i=0 ;i<p.length;i++){
char t=p[i];
System.out.print(decrypt(t,j));
}
System.out.println("");
}
}
}
明文:enigma
package P1;
import java.util.*;
public class 密碼學作業
{
static char 密文(char p,int key){
return(char) (((int)(p-'a')+26-key)%26+'a');
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("輸入密文");
String a=sc.next();
char p[]=new char[a.length()];
for(int i=0 ;i<p.length;i++)
p[i]=a.charAt(i);
for(int b=1;b<26; b++)
{
System.out.print("第"+b+"組密碼");
for(int x=0 ;x<p.length;x++)
{
char t=p[x];
System.out.print(密文(t,b));
}
System.out.println("");
}
}
}
第19把鑰匙=enigma
package P1;
import java.util.*;
public class 密碼學
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("輸入密文:");
z=sc.next();
char x[] =new char [z.length()];
int i=0,a=1;
while(i<x.length)
{
x[i]=z.charAt(i);
i++;
}
while(a<=25)
{
System.out.println("");
int q=0;
System.out.print("key="+a+" ");
while(q<x.length)
{
System.out.print(decrypt(x[q], a));
q++;
}
a++;
}
}
}
答案: key=19 enigma
k=0,xgbzft
k=1,yhcagu
k=2,zidbhv
k=3,ajeciw
k=4,bkfdjx
k=5,clgeky
k=6,dmhflz
k=7,enigma
明文:enigma
package P1;
import java.util.*;
public class 密碼學
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("輸入密文:");
z=sc.next();
char x[] =new char [z.length()];
int i=0,a=1;
while(i<x.length)
{
x[i]=z.charAt(i);
i++;
}
while(a<=25)
{
System.out.println("");
int q=0;
System.out.print("key="+a+" ");
while(q<x.length)
{
System.out.print(decrypt(x[q], a));
q++;
}
a++;
}
}
}
資料來源:翻譯出處:http://www.bing.com/translator/?MKT=zh-TW
1:YHCAGU
2:ZIDBHV
3:AJECIW
4:BKFDJX
5:CLGEKY
6:DMHFLZ
7:ENIGMA
8:FOJHNB
9:GPKIOC
10:HQLJPD
11:IRMKQE
12:JSNLRF
13:KTOMSG
14:LUPNTH
15:MVQOUI
16:NWRPVJ
17:OXSQWK
18:PYTRXL
19:QZUSYM
20:RAVTZN
21:SBWUAO
22:TCXVBP
23:UDYWCQ
24:VEZXDR
25:WFAYES
由第7把
得出明文"ENIGMA
package P1;
import java.util.*;
public class 密碼學
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("輸入密文:");
z=sc.next();
char x[] =new char [z.length()];
int i=0,a=1;
while(i<x.length)
{
x[i]=z.charAt(i);
i++;
}
while(a<=25)
{
System.out.println("");
int q=0;
System.out.print("key="+a+" ");
while(q<x.length)
{
System.out.print(decrypt(x[q], a));
q++;
}
a++;
}
}
}
答案: key=19 enigma
0.xgbzft
1.yhcagu
2.zidbhv
3.ajeciw
4.bkfdjx
5.clgeky
6.dmhflz
7.enigma
8.fojhnb
9.gpkoc
10.hqljpd
11.irmkqe
12.jsnlrf
13.ktomsg
14.lupnth
15.mvqoui
16.nwrpvj
17.oxsqwk
18.pytrxl
19.qzusym
20.ravtzn
21.sbwuao
22.tcxvbp
23.udywcq
24.vezxdr
25.wfayes
7:明文:enigma
package P1;
import java.util.*;
public class 密碼學
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("輸入密文:");
z=sc.next();
char x[] =new char [z.length()];
int i=0,a=1;
while(i<x.length)
{
x[i]=z.charAt(i);
i++;
}
while(a<=25)
{
System.out.println("");
int q=0;
System.out.print("key="+a+" ");
while(q<x.length)
{
System.out.print(decrypt(x[q], a));
q++;
}
a++;
}
}
}
答案: key=19 enigma 翻譯:謎
翻譯出處:http://www.bing.com/translator/?MKT=zh-TW
package tt;
import java.util.*;
public class t1 {
static char decrypt(char p,int key){
return(char) (((int)(p-'a')+26-key)%26+'a');
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("請輸入密文");
String a=sc.next();
char p[]=new char[a.length()];
for(int i=0 ;i<p.length;i++)
p[i]=a.charAt(i);
for(int j=1;j<26; j++){
for(int i=0 ;i<p.length;i++){
char t=p[i];
System.out.print(decrypt(t,j));
}
System.out.println("");
}
}
}
明文:enigma
package P1;
import java.util.*;
public class 密碼學
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("輸入密文:");
z=sc.next();
char x[] =new char [z.length()];
int i=0,a=1;
while(i<x.length)
{
x[i]=z.charAt(i);
i++;
}
while(a<=25)
{
System.out.println("");
int q=0;
System.out.print("key="+a+" ");
while(q<x.length)
{
System.out.print(decrypt(x[q], a));
q++;
}
a++;
}
}
}
package P1;
import java.util.*;
public class 密碼學
{
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args)
{
String z;
Scanner sc= new Scanner(System.in);
System.out.println("輸入密文:");
z=sc.next();
char x[] =new char [z.length()];
int i=0,a=1;
while(i<x.length)
{
x[i]=z.charAt(i);
i++;
}
while(a<=25)
{
System.out.println("");
int q=0;
System.out.print("key="+a+" ");
while(q<x.length)
{
System.out.print(decrypt(x[q], a));
q++;
}
a++;
}
}
}
X=23 G=4 B=1 Z=25 F=5 T=19
M(23 4 1 25 5 19)-K(MOD26)
K=1~19
求得:
23-19(MOD26)=4=E
4-19(MOD26)=13=N
1-19(MOD26)=8=I
25-19(MOD26)=2=C
5-19(MOD26)=12=M
T-19(MOD26)=0=A
Ans: enicma
程式碼:
function decodeCaesar(input){
output=new Array;
chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
output_.innerHTML="";
for(i=0;i<26;i++){
str=new String;
for(j=0;j<input.length;j++){
str+=chars[(chars.search(input.charAt(j))+i)%26];
}
output.push(str);
}
return output;
}
鑰匙是第 7 把
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("輸入密文");
String a = sc.next();
int s = a.length();
char[] b = a.toCharArray();
for(int j=1;j<=26;j++){
System.out.println("第"+j+"把鑰匙");
for(int i=0;i<s;i++){
System.out.print(decrypt(b[i],j));
}
System.out.println();
}
}
第19把鑰匙:enigma
package tt;
import java.util.*;
public class t1 {
static char decrypt(char p,int key){
return(char) (((int)(p-'a')+26-key)%26+'a');
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("請輸入密文");
String a=sc.next();
char p[]=new char[a.length()];
for(int i=0 ;i<p.length;i++)
p[i]=a.charAt(i);
for(int j=1;j<26; j++){
for(int i=0 ;i<p.length;i++){
char t=p[i];
System.out.print(decrypt(t,j));
}
System.out.println("");
}
}
}
明文:enigma
張貼留言