xgbzft
有用程式碼者請PO源碼
Hint:
static char decrypt(char p, int Key)
{
return (char) (((int)(p-'a')+26-Key)%26+'a');
}
herrDeng網內搜尋
自訂搜尋
Ads
訂閱:
張貼留言 (Atom)
熱門文章
-
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
-
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
-
先說明一下這是後知後覺的解答,所謂後知就是股票價格已知存在陣列(清單),當然就要用迴圈練習,雙迴圈暴力解需時O(n**2),當然不用,採python單一迴圈解答「最佳股票的買賣時機#LeetCode 121 Best Time to Buy and Sell Stock」,解...
-
你會用C的算子sizeof?
-
XOR prefixsum CPP python解Leetcode 1829 Maximum XOR for Each Query 其實這裡考慮的是元素個數為2^maximumBit的交換群,運算子為XOR。 [Python code請進]
-
Python C++使用字串find迴圈速解Leetcode 2490 Circular Sentence C++ & Python都有字串的find,用法都類似 split=s.find(' ', split+1)能找到s從index=split+1開...
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
張貼留言