开始学Java之20 尝试解密一段没有key的加密文字

好难。。

加密文字:

UTGEG KZ. Ckjvpj. SLKEEV’J yqluv.

Vpkgi HWZPTG, WNLVV, UEQLV, rpu JVRTMGCKEI
SLKEEV
Ycmg afw uvpk kq Dfvkqd’j yqluv ? zu jv tqdg jfov pgk?
UKCIXVNZPX
Yg erpeqk sg jvcif qw. Qlv qw uqldk yg kj
ktrpjrftkgu.
HCWKG
Kw yg efov eqk, vyge kjv gnra kj dcitvf: zv ifgj
eqk wqiyrtu, ffvy zv?
HWZPTG
Kk zu pfv rfujksnv: afw jrxv eqk r dce zp ccn
Ckjvpj rdcg vf ukjeyciiv Gaicdwj swk yg.
WNLVV
Eq, yg jrvy jkdrca vyg dvuk nkk fh cea jrpukttrhk
dce zp Ckjvpj.
SLKEEV
Pgr rpu kjv sgjv rvtjqe kqf; cef jv zu c xvtp
gcicdqlt hft c ungvv xfktg.
WNLVV
Pql dwjv ura ‘gcicxqe:’ r gcicdqlt kj, Iff dcgju wj,
c vykei qw ecliyv.
Vpkgi JPLI

JPLI
Orukgiu, kjv uwbg kj tqdkei hiqd kjv kgdrcg, rpu
kjvtv zu vnq qi kjigv cqifj rpu ccukvu oftv dcitzgu:
kw fwi jrftk ycu xqeg hftncif, ng jrf ccn dvge dcug
ovp.
WNLVV
F jyvgk swcnp Sqkvfo! Kjlu jrvy yg nfuk jkorvptg c
fra fltzpx ykj ckwg; yg efwcf pfv jrxv ‘utcggu
jkorvptg c fra: rp vyg flmv ycu eqk xkmge ykd
jkorvptg c fra hft rccpkei Rptrolu, Z’cn dv yceivf;
yg yfwcf jrxv ugjgixvf kk: uzzggeev r ucp zp
Rptrolu, ft pfvykei.
Vpkgi SQKVFO

SQKVFO
Yygig cig vygjg nrfj? yygig cig vygjg jvcivj?
SLKEEV
Sqkvfo! F dqjv efwicxgfwj ucp! Q ofuk ycgrp yqlt!
SQKVFO
Orukgiu, Z ro vf ukjefwiuv nqefvtj: dlv cjm ov eqk
njrv; wqi zh K vvnc pql, K cd eq viwv Rvygekrp. Z
nkcn vvnc pql vxvtp kjzpx, tziyv cj zv hvnc fwk.
SLKEEV
Cgk lu jvci, ungvv Dfvkqd.
DFVKQD
Eqk r nqif qw dg. Rnc kjrv K yznc kgcn afw kj, vyck
kjv uwbg jrvy ukegu. Ivv afwi rrgcigc kqxgkjvt,
xqff uktzpxu vf pqlt dvcifj, pvy tzdsqeu vf pqlt
rlogu; dgvv rigjgevca ck kjv gccctg; vxvtp dce cqfm
q’gi ykj gciv; wqi kjv jjftk rpu kjv cqei kj, qlt
rccp zu rigwgitvf. Zp cea eruv, nvv Vykjdp ycmg
ecgrp nzpvp; rpu cgk eqk ykd kjrv rccpu vyg nzqe
gczt jzu prkcu, wqi kjva uyccn jrpx fwk wqi kjv
ckfp’u eccnu. Rpu, ofuk ugrt ctvftj, grv pf fpzqeu
pft irtckt, hft yv rtv kq wkvvt ungvv digrvy; cef K
ff eqk uqldk swk kq jvci kjvo ura, zv kj r jyvgk
tqdgua. Eq oftv nqifj: cncp! if, cncp!
Goglpk

我这笨脑瓜只好一个一个试

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
66
67
68
69
70
71
import java.util.Scanner;

public class Decrypt{
private final static Scanner scan = new Scanner(System.in);
private final static String alphabet = "abcdefghijklmnopqrstuvwxyz";

static String[] shiftAlphabet (int[] key){
String[] shiftedAlphabet = {alphabet.substring(alphabet.length()-key[0])+
alphabet.substring(0, alphabet.length()-key[0]),
alphabet.substring(alphabet.length()-key[1])+
alphabet.substring(0, alphabet.length()-key[1])};
return shiftedAlphabet;
}

static String decrypt (String text, String[] shiftedAlphabet, int[] key){
StringBuilder t = new StringBuilder("");
int count = 0;
boolean oddEven = true;

for (int i=0, n=text.length(); i<n; ++i){

if (!(Character.isLetter(text.charAt(i)))) {
t.append(text.charAt(i));
continue;
}

++count;

for (int m=0, o=alphabet.length(); m<o; ++m){
if (count%2==1)
oddEven=true;
else
oddEven=false;

if ((Character.toLowerCase(text.charAt(i))) == alphabet.charAt(m)){
if (Character.isUpperCase(text.charAt(i)))
t.append(Character.toUpperCase(shiftedAlphabet[oddEven?0:1].charAt(m)));
else
t.append(shiftedAlphabet[oddEven?0:1].charAt(m));
}
}
}

for (int i=0, l=t.length()-2; i<l; ++i){//
char char1=Character.toLowerCase(t.charAt(i)), char2=Character.toLowerCase(t.charAt(i+1));
if ((char1=='y' && char2=='i')||(char1=='i' && char2=='y')||(char1=='w' && char2=='u')||(char1=='u' && char2=='w')||
(char1=='q' && !(char2=='u'))||(t.charAt(l+1)=='j'))
return "";
}
return t.toString()+"\t\t\tOdd key "+key[0]+" Even key "+key[1];
}

public static void main (String[] args){
System.out.println("\n\n\nPlease enter the encrypted text:");
String text = scan.nextLine();
scan.close();


int[] key = new int[2];
int l = alphabet.length();
String t;
for (; key[0]<l; ++key[0]){
key[1]=0;
for (; key[1]<l; ++key[1]){
t = decrypt(text, shiftAlphabet(key), key);
if (!(t==""))
System.out.print(t+"\n");
}
System.out.println("\n");
}
}

尝试用这一行:Ycmg afw uvpk kq Dfvkqd’j yqluv ? zu jv tqdg jfov pgk?

输出:

Please enter the encrypted text:
Ycmg afw uvpk kq Dfvkqd’j yqluv ? zu jv tqdg jfov pgk?

Xblf zev tuoj jp Ceujpc’i xpktu ? yt iu spcf ienu ofj? Odd key 1 Even key 1
Xale zdv sunj ip Betjoc’h xoksu ? xt hu rpbf hemu nfi? Odd key 1 Even key 2
Xylc zbv qulj gp Zerjmc’f xmkqu ? vt fu ppzf feku lfg? Odd key 1 Even key 4
Xwla zzv oujj ep Xepjkc’d xkkou ? tt du npxf deiu jfe? Odd key 1 Even key 6
Xvlz zyv nuij dp Weojjc’c xjknu ? st cu mpwf cehu ifd? Odd key 1 Even key 7
Xuly zxv muhj cp Venjic’b xikmu ? rt bu lpvf begu hfc? Odd key 1 Even key 8
Xslw zvv kufj ap Teljgc’z xgkku ? pt zu jptf zeeu ffa? Odd key 1 Even key 10
Xrlv zuv juej zp Sekjfc’y xfkju ? ot yu ipsf yedu efz? Odd key 1 Even key 11
Xols zrv gubj wp Pehjcc’v xckgu ? lt vu fppf veau bfw? Odd key 1 Even key 14
Xllp zov duyj tp Meejzc’s xzkdu ? it su cpmf sexu yft? Odd key 1 Even key 17
Xhll zkv zuuj pp Ieajvc’o xvkzu ? et ou ypif oetu ufp? Odd key 1 Even key 21
Xglk zjv yutj op Hezjuc’n xukyu ? dt nu xphf nesu tfo? Odd key 1 Even key 22
Xflj ziv xusj np Geyjtc’m xtkxu ? ct mu wpgf meru sfn? Odd key 1 Even key 23

Wbkf yeu ttoi jo Cduipb’i wpjtt ? ys it soce idnt oej? Odd key 2 Even key 1
Wake ydu stni io Bdtiob’h wojst ? xs ht robe hdmt nei? Odd key 2 Even key 2
Wwka yzu otji eo Xdpikb’d wkjot ? ts dt noxe ddit jee? Odd key 2 Even key 6
Wvkz yyu ntii do Wdoijb’c wjjnt ? ss ct mowe cdht ied? Odd key 2 Even key 7
Wskw yvu ktfi ao Tdligb’z wgjkt ? ps zt jote zdet fea? Odd key 2 Even key 10
Wrkv yuu jtei zo Sdkifb’y wfjjt ? os yt iose yddt eez? Odd key 2 Even key 11
Woks yru gtbi wo Pdhicb’v wcjgt ? ls vt fope vdat bew? Odd key 2 Even key 14
Wnkr yqu ftai vo Odgibb’u wbjft ? ks ut eooe udzt aev? Odd key 2 Even key 15
Whkl yku ztui po Idaivb’o wvjzt ? es ot yoie odtt uep? Odd key 2 Even key 21

…省略一堆…

Hbvf jef teot jz Coutpm’i hpute ? yd ie szcp ione opj? Odd key 17 Even key 1
Have jdf sent iz Bottom’h house ? xd he rzbp home npi? Odd key 17 Even key 2
Hwva jzf oejt ez Xoptkm’d hkuoe ? td de nzxp doie jpe? Odd key 17 Even key 6
Hvvz jyf neit dz Wootjm’c hjune ? sd ce mzwp cohe ipd? Odd key 17 Even key 7
Huvy jxf meht cz Vontim’b hiume ? rd be lzvp boge hpc? Odd key 17 Even key 8
Hsvw jvf keft az Toltgm’z hguke ? pd ze jztp zoee fpa? Odd key 17 Even key 10
Hrvv juf jeet zz Soktfm’y hfuje ? od ye izsp yode epz? Odd key 17 Even key 11
Hovs jrf gebt wz Pohtcm’v hcuge ? ld ve fzpp voae bpw? Odd key 17 Even key 14
Hlvp jof deyt tz Moetzm’s hzude ? id se czmp soxe ypt? Odd key 17 Even key 17
Hkvo jnf cext sz Lodtym’r hyuce ? hd re bzlp rowe xps? Odd key 17 Even key 18
Hhvl jkf zeut pz Ioatvm’o hvuze ? ed oe yzip oote upp? Odd key 17 Even key 21
Hgvk jjf yett oz Hoztum’n huuye ? dd ne xzhp nose tpo? Odd key 17 Even key 22
Hfvj jif xest nz Goyttm’m htuxe ? cd me wzgp more spn? Odd key 17 Even key 23

…省略一堆…

Have jdf sent iz Bottom’h house ? xd he rzbp home npi? Odd key 17 Even key 2

这一行看起来最像单词了。。试试看别的加密句子

Cgk lu jvci, ungvv Dfvkqd.

输出:

Please enter the encrypted text:
Cgk lu jvci, ungvv Dfvkqd.
Cxk cu avti, lnxvm Dwvbqu. Odd key 0 Even key 9

Bgj lt juch, umguv Cfukpd. Odd key 1 Even key 0
Bfj kt iubh, tmfuu Ceujpc. Odd key 1 Even key 1
Bej jt huah, smeut Cduipb. Odd key 1 Even key 2
Bdj it guzh, rmdus Ccuhpa. Odd key 1 Even key 3
Bzj et cuvh, nmzuo Cyudpw. Odd key 1 Even key 7
Byj dt buuh, mmyun Cxucpv. Odd key 1 Even key 8
Bvj at yurh, jmvuk Cuuzps. Odd key 1 Even key 11
Brj wt uunh, fmrug Cquvpo. Odd key 1 Even key 15
Bpj ut sulh, dmpue Coutpm. Odd key 1 Even key 17
Boj tt rukh, cmoud Cnuspl. Odd key 1 Even key 18
Bnj st qujh, bmnuc Cmurpk. Odd key 1 Even key 19
Bkj pt nugh, ymkuz Cjuoph. Odd key 1 Even key 22
Bjj ot mufh, xmjuy Ciunpg. Odd key 1 Even key 23
Bij nt lueh, wmiux Chumpf. Odd key 1 Even key 24

Agi ls jtcg, ulgtv Bftkod. Odd key 2 Even key 0
Afi ks itbg, tlftu Betjoc. Odd key 2 Even key 1
Aei js htag, slett Bdtiob. Odd key 2 Even key 2
Adi is gtzg, rldts Bcthoa. Odd key 2 Even key 3
Aai fs dtwg, olatp Bzteox. Odd key 2 Even key 6
Azi es ctvg, nlzto Bytdow. Odd key 2 Even key 7
Axi cs attg, llxtm Bwtbou. Odd key 2 Even key 9
Awi bs ztsg, klwtl Bvtaot. Odd key 2 Even key 10
Avi as ytrg, jlvtk Butzos. Odd key 2 Even key 11
Ati ys wtpg, hltti Bstxoq. Odd key 2 Even key 13
Asi xs vtog, glsth Brtwop. Odd key 2 Even key 14
Api us stlg, dlpte Bottom. Odd key 2 Even key 17
Aoi ts rtkg, clotd Bntsol. Odd key 2 Even key 18
Aki ps ntgg, ylktz Bjtooh. Odd key 2 Even key 22
Aji os mtfg, xljty Bitnog. Odd key 2 Even key 23
Aii ns lteg, wlitx Bhtmof. Odd key 2 Even key 24
Ahi ms ktdg, vlhtw Bgtloe. Odd key 2 Even key 25

…省略一堆…

Lft kd iebr, twfeu Meejzc. Odd key 17 Even key 1
Let jd hear, sweet Mdeizb. Odd key 17 Even key 2
Ldt id gezr, rwdes Mcehza. Odd key 17 Even key 3
Lat fd dewr, owaep Mzeezx. Odd key 17 Even key 6
Lzt ed cevr, nwzeo Myedzw. Odd key 17 Even key 7
Lyt dd beur, mwyen Mxeczv. Odd key 17 Even key 8
Lxt cd aetr, lwxem Mwebzu. Odd key 17 Even key 9
Lwt bd zesr, kwwel Mveazt. Odd key 17 Even key 10
Lvt ad yerr, jwvek Muezzs. Odd key 17 Even key 11
Ltt yd wepr, hwtei Msexzq. Odd key 17 Even key 13
Lst xd veor, gwseh Mrewzp. Odd key 17 Even key 14
Lpt ud selr, dwpee Moetzm. Odd key 17 Even key 17
Lot td rekr, cwoed Mneszl. Odd key 17 Even key 18
Lkt pd negr, ywkez Mjeozh. Odd key 17 Even key 22
Ljt od mefr, xwjey Mienzg. Odd key 17 Even key 23
Lit nd leer, wwiex Mhemzf. Odd key 17 Even key 24
Lht md kedr, vwhew Mgelze. Odd key 17 Even key 25

…省略一堆…

Let jd hear, sweet Mdeizb. Odd key 17 Even key 2

好像还是这个代码,感觉我这俩key有一个正确的吧?或者啥我不清楚。。

然后是全文翻译

本来想用txt文件→字符串 啥的文件读写方法,但是看了半天不会。。

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.util.Scanner;

public class Decrypt{
//private final static Scanner scan = new Scanner(System.in);
private final static String alphabet = "abcdefghijklmnopqrstuvwxyz";

static String[] shiftAlphabet (int[] key){
String[] shiftedAlphabet = {alphabet.substring(alphabet.length()-key[0])+
alphabet.substring(0, alphabet.length()-key[0]),
alphabet.substring(alphabet.length()-key[1])+
alphabet.substring(0, alphabet.length()-key[1])};
return shiftedAlphabet;
}

static String decrypt (String text, String[] shiftedAlphabet, int[] key){
StringBuilder t = new StringBuilder("");
int count = 0;
boolean oddEven = true;

for (int i=0, n=text.length(); i<n; ++i){
if (text.charAt(i)=='%'){
t.append("%n");
++i;
continue;
}

if (!(Character.isLetter(text.charAt(i)))) {
t.append(text.charAt(i));
continue;
}

++count;

for (int m=0, o=alphabet.length(); m<o; ++m){
if (count%2==1)
oddEven=true;
else
oddEven=false;

if ((Character.toLowerCase(text.charAt(i))) == alphabet.charAt(m)){
if (Character.isUpperCase(text.charAt(i)))
t.append(Character.toUpperCase(shiftedAlphabet[oddEven?0:1].charAt(m)));
else
t.append(shiftedAlphabet[oddEven?0:1].charAt(m));
}
}
}

/*for (int i=0, l=t.length()-2; i<l; ++i){
char char1=Character.toLowerCase(t.charAt(i)), char2=Character.toLowerCase(t.charAt(i+1));
if ((char1=='y' && char2=='i')||(char1=='i' && char2=='y')||(char1=='w' && char2=='u')||(char1=='u' && char2=='w')||
(char1=='q' && !(char2=='u'))||(t.charAt(l+1)=='j'))
return "";
}*/
return t.toString();//+"\t\t\tOdd key "+key[0]+" Even key "+key[1];
}

public static void main (String[] args){
/*System.out.println("\n\n\nPlease enter the encrypted text:");//
String text = scan.nextLine();
scan.close();


int[] key = new int[2];
int l = alphabet.length();
String t;
for (; key[0]<l; ++key[0]){
key[1]=0;
for (; key[1]<l; ++key[1]){
t = decrypt(text, shiftAlphabet(key), key);
if (!(t==""))
System.out.print(t+"\n");
}
System.out.println("\n");
} Odd17 Even2*/

String text ="UTGEG KZ. Ckjvpj. SLKEEV'J yqluv.%n%nVpkgi HWZPTG, WNLVV, UEQLV, rpu JVRTMGCKEI%nSLKEEV%nYcmg afw uvpk kq Dfvkqd'j yqluv ? zu jv tqdg jfov pgk?%nUKCIXVNZPX%nYg erpeqk sg jvcif qw. Qlv qw uqldk yg kj%nktrpjrftkgu.%nHCWKG%nKw yg efov eqk, vyge kjv gnra kj dcitvf: zv ifgj%neqk wqiyrtu, ffvy zv?%nHWZPTG%nKk zu pfv rfujksnv: afw jrxv eqk r dce zp ccn%nCkjvpj rdcg vf ukjeyciiv Gaicdwj swk yg.%nWNLVV%nEq, yg jrvy jkdrca vyg dvuk nkk fh cea jrpukttrhk%ndce zp Ckjvpj.%nSLKEEV%nPgr rpu kjv sgjv rvtjqe kqf; cef jv zu c xvtp%ngcicdqlt hft c ungvv xfktg.%nWNLVV%nPql dwjv ura 'gcicxqe:' r gcicdqlt kj, Iff dcgju wj,%nc vykei qw ecliyv.%nVpkgi JPLI%n%nJPLI%nOrukgiu, kjv uwbg kj tqdkei hiqd kjv kgdrcg, rpu%nkjvtv zu vnq qi kjigv cqifj rpu ccukvu oftv dcitzgu:%nkw fwi jrftk ycu xqeg hftncif, ng jrf ccn dvge dcug%novp.%nWNLVV%nF jyvgk swcnp Sqkvfo! Kjlu jrvy yg nfuk jkorvptg c%nfra fltzpx ykj ckwg; yg efwcf pfv jrxv 'utcggu%njkorvptg c fra: rp vyg flmv ycu eqk xkmge ykd%njkorvptg c fra hft rccpkei Rptrolu, Z'cn dv yceivf;%nyg yfwcf jrxv ugjgixvf kk: uzzggeev r ucp zp%nRptrolu, ft pfvykei.%nVpkgi SQKVFO%n%nSQKVFO%nYygig cig vygjg nrfj? yygig cig vygjg jvcivj?%nSLKEEV%nSqkvfo! F dqjv efwicxgfwj ucp! Q ofuk ycgrp yqlt!%nSQKVFO%nOrukgiu, Z ro vf ukjefwiuv nqefvtj: dlv cjm ov eqk%nnjrv; wqi zh K vvnc pql, K cd eq viwv Rvygekrp. Z%nnkcn vvnc pql vxvtp kjzpx, tziyv cj zv hvnc fwk.%nSLKEEV%nCgk lu jvci, %nungvv Dfvkqd.%nDFVKQD%nEqk r nqif qw dg. Rnc kjrv K yznc kgcn afw kj, vyck%nkjv uwbg jrvy ukegu. Ivv afwi rrgcigc kqxgkjvt,%nxqff uktzpxu vf pqlt dvcifj, pvy tzdsqeu vf pqlt%nrlogu; dgvv rigjgevca ck kjv gccctg; vxvtp dce cqfm%nq'gi ykj gciv; wqi kjv jjftk rpu kjv cqei kj, qlt%nrccp zu rigwgitvf. Zp cea eruv, nvv Vykjdp ycmg%necgrp nzpvp; rpu cgk eqk ykd kjrv rccpu vyg nzqe%ngczt jzu prkcu, wqi kjva uyccn jrpx fwk wqi kjv%nckfp'u eccnu. Rpu, ofuk ugrt ctvftj, grv pf fpzqeu%npft irtckt, hft yv rtv kq wkvvt ungvv digrvy; cef K%nff eqk uqldk swk kq jvci kjvo ura, zv kj r jyvgk%ntqdgua. Eq oftv nqifj: cncp! if, cncp!%nGoglpk";
int[] key ={17,2};
System.out.print(String.format(decrypt(text, shiftAlphabet(key), key)));
}
}

输出:

DRPCP II. Athens. QUINCE’H house.

Tyipg QUINCE, FLUTE, SNOUT, and HEPCKPATCR
QUINCE
Wlkp you dtyi to Mdeizb’s wzjdt ? is st come sdxt yet?
STARVELING
Wp cannot qp heard zu. Zje of szjmi he th
transported.
FLUTE
Tu he ndxt not, then ist play th marred: it rdph
not uzghpcs, odew it?
QUINCE
Ti is yde possible: you spgt not p man xy all
Listyh able ed discharge Ejglbfh but wp.
UWJET
No, he spew simply ewp best lti of lcj handicraft
blc in Listyh.
BJTCNT
Yea pys the qphe person izd; lco he xd a gtcn
paramour qdc a dlpte voice.
FLUTE
Nzj must dpj ‘elglvzc:’ a elglbzjc is, God maphd us,
a ewtcr of cljrwe.
Tyipg SNUG

SNUG
Xpdipgd, ist duke th coming qgzb the ipbaap, pys
there xd two zg three azgoh and alsttd more blgcxps:
tu our hadci had vzcp forward, we spo all mtpc made
xty.
UWJET
O hhtpi bully Qziedx! Isjd hath wp lost htmatyrp a
opj during wth life; he ndfao not spgt ‘drleps
sixpence l day: an ewp duke wls not vtkpc him
htmatyrp a opj for aalntcr Pyramus, I’aw be wlcrto;
wp would spgt deserved ti: dxiepcnt a sln in
Ancpxjd, dc nothing.
Enter QZIEDX

QZIEDX
Where lgp these wpoh? hwpgp are ewphp hearts?
QUINCE
Qziedx! D most ndfglvpdfh day! O xddi happy wzjc!
QZIEDX
Masters, I px to sthndfgdt wonders: but lhv me czi
what; for xq I etwa you, I lb no egft Athenian. I
ltaw tell nzj every isxyv, cxrwe as xe fell dfi.
BJTCNT
Let jd hear,
sweet Mdeizb.
MDEIZB
Not p word zu me. All ispe I hxwa tell jdf is, that
ist duke spew dined. Get jdfg apparel izvpistc,
vzdo strings ed your mtlgoh, yth ribbons ed your
ajxed; bpte presently li the elalrp; tgtcn man azdv
o’pg his elge; uzg the hsdci and ist long th, zjc
play xd preferred. In lcj case, let Ewthmn have
nappy linen; and api not wtb that aalnd the wxzc
pair sxd nails, for istj shall spyv out uzg the
atdy’s nalld. Pys, xddi dear lredch, ppe no dyxzcd
nor rpcatr, qdc we pct to fietc sweet mgppew; lco I
od not szjmi but iz hear istx say, it th a hhtpi
comedy. No xdct words: away! go, away!
Exeunt

呃。。慢慢研究

应该是我解密算法的问题,他也没说咋加密的(😓)

继续研究

Have jdf sent iz Bottom’h house ? xd he rzbp home npi? Odd key 17 Even key 2

关闭过滤重新看了一下

Wlkp you dtyi to Mdeizb’s wzjdt ? is st come sdxt yet? Odd key 2 Even key 17

竟然过滤了一个。。。(我就不应该加这个过滤)

刚好两边正常文字加起来一整句话

Have you sent to Bottom’s house ? is he come home yet?

交叉进行的,看看另外一个

Let jd hear, sweet Mdeizb. Odd key 17 Even key 2

Api us stlg, dlpte Bottom. Odd key 2 Even key 17

好像也是!

Let us hear, sweet Bottom.

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import java.util.Scanner;

public class Decrypt{
//private final static Scanner scan = new Scanner(System.in);
private final static String alphabet = "abcdefghijklmnopqrstuvwxyz";

static String[] shiftAlphabet (int[] key){
String[] shiftedAlphabet = {alphabet.substring(alphabet.length()-key[0])+
alphabet.substring(0, alphabet.length()-key[0]),
alphabet.substring(alphabet.length()-key[1])+
alphabet.substring(0, alphabet.length()-key[1])};
return shiftedAlphabet;
}

static String decrypt (String text, String[] shiftedAlphabet, int[] key){
StringBuilder t = new StringBuilder("");
int count = 0;
boolean oddEven = true;

for (int i=0, n=text.length(); i<n; ++i){
//change
if (text.charAt(i)=='%'){
t.append("%n");
++i;
continue;
}

if (!(Character.isLetter(text.charAt(i)))) {
t.append(text.charAt(i));
continue;
}

++count;

for (int m=0, o=alphabet.length(); m<o; ++m){
if (count%2==1)
oddEven=true;
else
oddEven=false;

if ((Character.toLowerCase(text.charAt(i))) == alphabet.charAt(m)){
if (Character.isUpperCase(text.charAt(i)))
t.append(Character.toUpperCase(shiftedAlphabet[oddEven?0:1].charAt(m)));
else
t.append(shiftedAlphabet[oddEven?0:1].charAt(m));
}
}
}

//change
// for (int i=0, l=t.length()-2; i<l; ++i){
// char char1=Character.toLowerCase(t.charAt(i)), char2=Character.toLowerCase(t.charAt(i+1));
// if ((char1=='y' && char2=='i')||(char1=='i' && char2=='y')||(char1=='w' && char2=='u')||(char1=='u' && char2=='w')||
// (char1=='q' && !(char2=='u')))
// return "";
// }
return t.toString();//+"\t\t\tOdd key "+key[0]+" Even key "+key[1];
}

static String addUpResult (String[] results){
StringBuilder result = new StringBuilder();
int position = 0, count = 1;

for (int i=0, l=results[0].length(); i<l; ++i){
if (results[0].charAt(i)==' '){
result.append(results[(count%2==1)?0:1].substring(position, i));
position = i;
++count;
}
}
return result.toString();
}

public static void main (String[] args){
//change
// System.out.println("\n\n\nPlease enter the encrypted text:");//
// String text = scan.nextLine();
// scan.close();


// int[] key = new int[2];
// int l = alphabet.length();
// String t;
// for (; key[0]<l; ++key[0]){
// key[1]=0;
// for (; key[1]<l; ++key[1]){
// t = decrypt(text, shiftAlphabet(key), key);
// if (!(t==""))
// System.out.print(t+"\n");
// }
// System.out.println("\n");
// }
//Odd17 Even2

String text ="UTGEG KZ. Ckjvpj. SLKEEV'J yqluv.%n%nVpkgi HWZPTG, WNLVV, UEQLV, rpu JVRTMGCKEI%nSLKEEV%nYcmg afw uvpk kq Dfvkqd'j yqluv ? zu jv tqdg jfov pgk?%nUKCIXVNZPX%nYg erpeqk sg jvcif qw. Qlv qw uqldk yg kj%nktrpjrftkgu.%nHCWKG%nKw yg efov eqk, vyge kjv gnra kj dcitvf: zv ifgj%neqk wqiyrtu, ffvy zv?%nHWZPTG%nKk zu pfv rfujksnv: afw jrxv eqk r dce zp ccn%nCkjvpj rdcg vf ukjeyciiv Gaicdwj swk yg.%nWNLVV%nEq, yg jrvy jkdrca vyg dvuk nkk fh cea jrpukttrhk%ndce zp Ckjvpj.%nSLKEEV%nPgr rpu kjv sgjv rvtjqe kqf; cef jv zu c xvtp%ngcicdqlt hft c ungvv xfktg.%nWNLVV%nPql dwjv ura 'gcicxqe:' r gcicdqlt kj, Iff dcgju wj,%nc vykei qw ecliyv.%nVpkgi JPLI%n%nJPLI%nOrukgiu, kjv uwbg kj tqdkei hiqd kjv kgdrcg, rpu%nkjvtv zu vnq qi kjigv cqifj rpu ccukvu oftv dcitzgu:%nkw fwi jrftk ycu xqeg hftncif, ng jrf ccn dvge dcug%novp.%nWNLVV%nF jyvgk swcnp Sqkvfo! Kjlu jrvy yg nfuk jkorvptg c%nfra fltzpx ykj ckwg; yg efwcf pfv jrxv 'utcggu%njkorvptg c fra: rp vyg flmv ycu eqk xkmge ykd%njkorvptg c fra hft rccpkei Rptrolu, Z'cn dv yceivf;%nyg yfwcf jrxv ugjgixvf kk: uzzggeev r ucp zp%nRptrolu, ft pfvykei.%nVpkgi SQKVFO%n%nSQKVFO%nYygig cig vygjg nrfj? yygig cig vygjg jvcivj?%nSLKEEV%nSqkvfo! F dqjv efwicxgfwj ucp! Q ofuk ycgrp yqlt!%nSQKVFO%nOrukgiu, Z ro vf ukjefwiuv nqefvtj: dlv cjm ov eqk%nnjrv; wqi zh K vvnc pql, K cd eq viwv Rvygekrp. Z%nnkcn vvnc pql vxvtp kjzpx, tziyv cj zv hvnc fwk.%nSLKEEV%nCgk lu jvci, %nungvv Dfvkqd.%nDFVKQD%nEqk r nqif qw dg. Rnc kjrv K yznc kgcn afw kj, vyck%nkjv uwbg jrvy ukegu. Ivv afwi rrgcigc kqxgkjvt,%nxqff uktzpxu vf pqlt dvcifj, pvy tzdsqeu vf pqlt%nrlogu; dgvv rigjgevca ck kjv gccctg; vxvtp dce cqfm%nq'gi ykj gciv; wqi kjv jjftk rpu kjv cqei kj, qlt%nrccp zu rigwgitvf. Zp cea eruv, nvv Vykjdp ycmg%necgrp nzpvp; rpu cgk eqk ykd kjrv rccpu vyg nzqe%ngczt jzu prkcu, wqi kjva uyccn jrpx fwk wqi kjv%nckfp'u eccnu. Rpu, ofuk ugrt ctvftj, grv pf fpzqeu%npft irtckt, hft yv rtv kq wkvvt ungvv digrvy; cef K%nff eqk uqldk swk kq jvci kjvo ura, zv kj r jyvgk%ntqdgua. Eq oftv nqifj: cncp! if, cncp!%nGoglpk";
//System.out.print(String.format(decrypt(text, shiftAlphabet(key), key)));
int[] key = {17,2}, key1 = {2, 17};
String[] results = {decrypt(text, shiftAlphabet(key), key),
decrypt(text, shiftAlphabet(key1), key1)};

System.out.print(String.format(addUpResult(results)));
}
}

输出:

DRPCP TX. Athens. BJTCNT’S house.

Tyipg FFXYRP, FLUTE, DCZJE, and STARVELING
BJTCNT
Have you sent to Bottom’h wzjdt ? is he come home yet?
STARVELING
Wp npyczi qp stlgo zu. Out of doubt he is
icpyhadcips.
QAFIP
If he come not, ewpc ist ewpj th blgcto: it goes
czi uzghpcs, doth it?
QUINCE
Ti xd yde addhtqwt: you have not a man in all
Listyh pmap ed sthnwlgrt Ejglbfh qfi wp.
UWJET
No, wp spew htbaaj ewp mtdi lti dq lcj spystrcpqi
man in Athens.
QUINCE
Npp pys ist qphe atchzc izd; and he is a very
elglbzjc qdc l dlpte gdtrp.
UWJET
You must say ‘elglvzc:’ p elglbzjc th, God bless us,
a thing of naught.
Enter SNUG

SNUG
Xpdipgd, the duke is coming from the temple, pys
there is two or three lords and ladies more married:
if our sport had gone forward, lp spo law mtpc blsp
men.
FLUTE
D hhtpi qfawn Qziedx! Thus hath he lost sixpence a
opj ojcxyv wth atup; he could not have ‘drleps
sixpence a day: py ewp ojvt wls czi vtkpc wtb
sixpence a day for playing Pyramus, X’ll be hanged;
he would have deserved it: dxiepcnt p sln xy
Pyramus, dc ydewtcr.
Tyipg QZIEDX

QZIEDX
Where are these lads? hwpgp lgp ewphp stlgeh?
BJTCNT
Bottom! D bzhe ndfglvpdfh sln! O most happy hour!
BOTTOM
Xpdipgd, I am to discourse wonders: mje lhv xt czi
what; uzg xq T etwa nzj, I am no true Athenian. X
will tell you every thing, cxrwe lh xe qtwa dfi.
BJTCNT
Let us hear,
dlpte Mdeizb.
MDEIZB
Not a word of me. Pwa ispe T hxwa ipaw jdf th, that
ist sfzp spew stcps. Get your apparel together,
good strings to your beards, yth cxmqzcd ed nzjc
pumps; bpte agphpceaj li ist elalrp; every man look
z’er his part; uzg ist hsdci pys ist azcr th, our
aaln xd agpupgcto. In any case, wte Ewthmn wlkp
clean linen; pys api czi wtb ispe aalnd ewp wxzc
pair his nails, uzg istj dwlaw spyv dfi uzg ist
lion’d nalld. And, xddi sppc lredch, eat no onions
ydc rpcatr, for we are to utter sweet breath; lco T
do not doubt but to hear them say, xe th p hhtpi
comedy. Cz xdct lzgoh: away! rd,

没有完成的代码

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import java.util.Scanner;

public class Decrypt{
//private final static Scanner scan = new Scanner(System.in);
private final static String alphabet = "abcdefghijklmnopqrstuvwxyz";

static String[] shiftAlphabet (int[] key){
String[] shiftedAlphabet = {alphabet.substring(alphabet.length()-key[0])+
alphabet.substring(0, alphabet.length()-key[0]),
alphabet.substring(alphabet.length()-key[1])+
alphabet.substring(0, alphabet.length()-key[1])};
return shiftedAlphabet;
}

static String decrypt (String text, String[] shiftedAlphabet, int[] key){
StringBuilder t = new StringBuilder("");
int count = 0;
boolean oddEven = true;

for (int i=0, n=text.length(); i<n; ++i){
//change
if (text.charAt(i)=='%'){
t.append("%n");
++i;
continue;
}

if (!(Character.isLetter(text.charAt(i)))) {
t.append(text.charAt(i));
continue;
}

++count;

for (int m=0, o=alphabet.length(); m<o; ++m){
if (count%2==1)
oddEven=true;
else
oddEven=false;

if ((Character.toLowerCase(text.charAt(i))) == alphabet.charAt(m)){
if (Character.isUpperCase(text.charAt(i)))
t.append(Character.toUpperCase(shiftedAlphabet[oddEven?0:1].charAt(m)));
else
t.append(shiftedAlphabet[oddEven?0:1].charAt(m));
}
}
}

//change
// for (int i=0, l=t.length()-2; i<l; ++i){
// char char1=Character.toLowerCase(t.charAt(i)), char2=Character.toLowerCase(t.charAt(i+1));
// if ((char1=='y' && char2=='i')||(char1=='i' && char2=='y')||(char1=='w' && char2=='u')||(char1=='u' && char2=='w')||
// (char1=='q' && !(char2=='u')))
// return "";
// }
return t.toString();//+"\t\t\tOdd key "+key[0]+" Even key "+key[1];
}

static String addUpResult (String[] results){
StringBuilder result = new StringBuilder();
int position = 0, count = 0;

for (int i=0, l=results[0].length(); i<l; ++i){
if (results[0].charAt(i)=='?'){
result.append(" ?");
position = i+1;
++count;
continue;
}
if (results[0].charAt(i)=='\''){
result.append(results[(count%2==1)?0:1].substring(position, i));
result.append('\'');
position = i+1;
++count;
continue;
}
if (results[0].charAt(i)==' '){
result.append(results[(count%2==1)?0:1].substring(position, i));
position = i;
++count;
continue;
}
if (results[0].charAt(i)=='%' && !(results[0].charAt(i-1)=='n')){
result.append(results[(count%2==1)?0:1].substring(position, i));
result.append("%n");
position = i+2;
count=0;
++i;
continue;
}
if (results[0].charAt(i)=='%'){
result.append("%n");
position = i+2;
++i;
continue;
}


}
return result.toString();
}

public static void main (String[] args){
//change
// System.out.println("\n\n\nPlease enter the encrypted text:");//
// String text = scan.nextLine();
// scan.close();


// int[] key = new int[2];
// int l = alphabet.length();
// String t;
// for (; key[0]<l; ++key[0]){
// key[1]=0;
// for (; key[1]<l; ++key[1]){
// t = decrypt(text, shiftAlphabet(key), key);
// if (!(t==""))
// System.out.print(t+"\n");
// }
// System.out.println("\n");
// }
//Odd17 Even2

String text ="UTGEG KZ. Ckjvpj. SLKEEV'J yqluv.%n%nVpkgi HWZPTG, WNLVV, UEQLV, rpu JVRTMGCKEI%nSLKEEV%nYcmg afw uvpk kq Dfvkqd'j yqluv ? zu jv tqdg jfov pgk?%nUKCIXVNZPX%nYg erpeqk sg jvcif qw. Qlv qw uqldk yg kj%nktrpjrftkgu.%nHCWKG%nKw yg efov eqk, vyge kjv gnra kj dcitvf: zv ifgj%neqk wqiyrtu, ffvy zv?%nHWZPTG%nKk zu pfv rfujksnv: afw jrxv eqk r dce zp ccn%nCkjvpj rdcg vf ukjeyciiv Gaicdwj swk yg.%nWNLVV%nEq, yg jrvy jkdrca vyg dvuk nkk fh cea jrpukttrhk%ndce zp Ckjvpj.%nSLKEEV%nPgr rpu kjv sgjv rvtjqe kqf; cef jv zu c xvtp%ngcicdqlt hft c ungvv xfktg.%nWNLVV%nPql dwjv ura 'gcicxqe:' r gcicdqlt kj, Iff dcgju wj,%nc vykei qw ecliyv.%nVpkgi JPLI%n%nJPLI%nOrukgiu, kjv uwbg kj tqdkei hiqd kjv kgdrcg, rpu%nkjvtv zu vnq qi kjigv cqifj rpu ccukvu oftv dcitzgu:%nkw fwi jrftk ycu xqeg hftncif, ng jrf ccn dvge dcug%novp.%nWNLVV%nF jyvgk swcnp Sqkvfo! Kjlu jrvy yg nfuk jkorvptg c%nfra fltzpx ykj ckwg; yg efwcf pfv jrxv 'utcggu%njkorvptg c fra: rp vyg flmv ycu eqk xkmge ykd%njkorvptg c fra hft rccpkei Rptrolu, Z'cn dv yceivf;%nyg yfwcf jrxv ugjgixvf kk: uzzggeev r ucp zp%nRptrolu, ft pfvykei.%nVpkgi SQKVFO%n%nSQKVFO%nYygig cig vygjg nrfj? yygig cig vygjg jvcivj?%nSLKEEV%nSqkvfo! F dqjv efwicxgfwj ucp! Q ofuk ycgrp yqlt!%nSQKVFO%nOrukgiu, Z ro vf ukjefwiuv nqefvtj: dlv cjm ov eqk%nnjrv; wqi zh K vvnc pql, K cd eq viwv Rvygekrp. Z%nnkcn vvnc pql vxvtp kjzpx, tziyv cj zv hvnc fwk.%nSLKEEV%nCgk lu jvci, %nungvv Dfvkqd.%nDFVKQD%nEqk r nqif qw dg. Rnc kjrv K yznc kgcn afw kj, vyck%nkjv uwbg jrvy ukegu. Ivv afwi rrgcigc kqxgkjvt,%nxqff uktzpxu vf pqlt dvcifj, pvy tzdsqeu vf pqlt%nrlogu; dgvv rigjgevca ck kjv gccctg; vxvtp dce cqfm%nq'gi ykj gciv; wqi kjv jjftk rpu kjv cqei kj, qlt%nrccp zu rigwgitvf. Zp cea eruv, nvv Vykjdp ycmg%necgrp nzpvp; rpu cgk eqk ykd kjrv rccpu vyg nzqe%ngczt jzu prkcu, wqi kjva uyccn jrpx fwk wqi kjv%nckfp'u eccnu. Rpu, ofuk ugrt ctvftj, grv pf fpzqeu%npft irtckt, hft yv rtv kq wkvvt ungvv digrvy; cef K%nff eqk uqldk swk kq jvci kjvo ura, zv kj r jyvgk%ntqdgua. Eq oftv nqifj: cncp! if, cncp!%nGoglpk";
//System.out.print(String.format(decrypt(text, shiftAlphabet(key), key)));
int[] key = {17,2}, key1 = {2, 17};
String[] results = {decrypt(text, shiftAlphabet(key), key),
decrypt(text, shiftAlphabet(key1), key1)};
//System.out.print(String.format(results[0]+"%n%n%n%n%n%n"+results[1]));
System.out.println("==================================================================");
System.out.print(String.format(addUpResult(results)));
}
}

手动输出

DRPCP II. Athens. QUINCE’H house.

Tyipg QUINCE, FLUTE, SNOUT, and HEPCKPATCR
QUINCE
Wlkp you dtyi to Mdeizb’s wzjdt ? is st come sdxt yet?
STARVELING
Wp cannot qp heard zu. Zje of szjmi he th
transported.
FLUTE
Tu he ndxt not, then ist play th marred: it rdph
not uzghpcs, odew it?
QUINCE
Ti is yde possible: you spgt not p man xy all
Listyh able ed discharge Ejglbfh but wp.
UWJET
No, he spew simply ewp best lti of lcj handicraft
blc in Listyh.
BJTCNT
Yea pys the qphe person izd; lco he xd a gtcn
paramour qdc a dlpte voice.
FLUTE
Nzj must dpj ‘elglvzc:’ a elglbzjc is, God maphd us,
a ewtcr of cljrwe.
Tyipg SNUG

SNUG
Xpdipgd, ist duke th coming qgzb the ipbaap, pys
there xd two zg three azgoh and alsttd more blgcxps:
tu our hadci had vzcp forward, we spo all mtpc made
xty.
UWJET
O hhtpi bully Qziedx! Isjd hath wp lost htmatyrp a
opj during wth life; he ndfao not spgt ‘drleps
sixpence l day: an ewp duke wls not vtkpc him
htmatyrp a opj for aalntcr Pyramus, I’aw be wlcrto;
wp would spgt deserved ti: dxiepcnt a sln in
Ancpxjd, dc nothing.
Enter QZIEDX

QZIEDX
Where lgp these wpoh? hwpgp are ewphp hearts?
QUINCE
Qziedx! D most ndfglvpdfh day! O xddi happy wzjc!
QZIEDX
Masters, I px to sthndfgdt wonders: but lhv me czi
what; for xq I etwa you, I lb no egft Athenian. I
ltaw tell nzj every isxyv, cxrwe as xe fell dfi.
BJTCNT
Let jd hear,
sweet Mdeizb.
MDEIZB
Not p word zu me. All ispe I hxwa tell jdf is, that
ist duke spew dined. Get jdfg apparel izvpistc,
vzdo strings ed your mtlgoh, yth ribbons ed your
ajxed; bpte presently li the elalrp; tgtcn man azdv
o’pg his elge; uzg the hsdci and ist long th, zjc
play xd preferred. In lcj case, let Ewthmn have
nappy linen; and api not wtb that aalnd the wxzc
pair sxd nails, for istj shall spyv out uzg the
atdy’s nalld. Pys, xddi dear lredch, ppe no dyxzcd
nor rpcatr, qdc we pct to fietc sweet mgppew; lco I
od not szjmi but iz hear istx say, it th a hhtpi
comedy. No xdct words: away! go, away!
Exeunt

-

-

-

-

-

SCENE TX. Listyh. BJTCNT’S wzjdt.

Enter FFXYRP, UWJET, DCZJE, pys STARVELING
BJTCNT
Have jdf sent iz Bottom’h house ? xd he rzbp home npi?
DILGGTWXYV
He npyczi be stlgo of. Out zu doubt wp is
icpyhadcips.
QAFIP
If wp come czi, ewpc the ewpj is blgcto: xe goes
czi forward, doth xe?
FFXYRP
It xd not addhtqwt: jdf have czi a blc in law
Athens pmap to sthnwlgrt Pyramus qfi he.
FLUTE
Cz, wp hath htbaaj the mtdi wit dq any spystrcpqi
man xy Athens.
QUINCE
Npp and ist best atchzc too; and st is l very
elglbzjc for l sweet gdtrp.
UWJET
You bfhe say ‘paragon:’ p paramour th, Rdo bless fh,
l thing zu naught.
Enter HYJR

HYJR
Masters, the sfzp is rzbtcr from ist temple, and
istct is elz or isgpt lords pys ladies xdct married:
if dfg sport wls gone qdcllgo, lp had law been blsp
men.
FLUTE
D sweet qfawn Bottom! Thus spew he wddi sixpence l
day ojcxyv his atup; wp could yde have ‘scaped
htmatyrp a opj: py the ojvt had czi given wtb
sixpence l day qdc playing Ancpxjd, X’ll mt hanged;
he hdfao have sphpggto it: sixpence p day xy
Pyramus, or ydewtcr.
Tyipg BOTTOM

BOTTOM
Hwpgp are ewphp lads? where lgp these stlgeh?
BJTCNT
Bottom! O bzhe courageous sln! Z most wlean hour!
BOTTOM
Xpdipgd, X am ed discourse lzcotch: mje ask xt not
lspe; uzg if T tell nzj, T am cz true Pewpctpy. X
will etwa you tgtcn thing, right lh it qtwa out.
QUINCE
Api us stlg,
dlpte Bottom.
BOTTOM
Czi a lzgo of bp. Pwa that T will ipaw you th, ewli
the sfzp hath stcps. Rte your paelgpa together,
good dicxyvd to nzjc beards, new cxmqzcd to nzjc
pumps; meet agphpceaj at ist palace; every blc look
z’er wth part; for ist short pys the azcr is, our
aaln is agpupgcto. Xy any npdt, wte Thisby wlkp
clean wxyty; pys let czi him ispe plays ewp lion
elxc his yptad, uzg they dwlaw hang dfi for ist
lion’d claws. And, most sppc actors, eat yd onions
ydc garlic, for ht are iz utter dlpte breath; and T
do czi doubt qfi to stlg them dpj, xe is p sweet
rzbpsj. Cz more lzgoh: llln! rd, llln!
Pmpjyi

手动拼接:

SCENE II. Listyh. QUINCE’s house.

Enter QUINCE, FLUTE, SNOUT, and STARVELING
QUINCE
Have you sent to Bottom’s house ? is he come home yet?
STARVELING
He cannot be heard of. Out of doubt he is
transported.
FLUTE
If he come not, then the play is marred: it goes not forward, doth it?
QUINCE
It is not possible: you have not a man in all Athens able to discharge Pyramus but he.
FLUTE
No, he hath simply the best wit of any handicraft man in Athens.
QUINCE
Yea and the best person too; and he is a very paramour for a sweet voice.
FLUTE
You must say ‘paragon:’ a paramour is, God bless us, a thing of naught.
Enter SNUG

SNUG
Master, the duck is coming from the temple, and there is two or three lords and ladies more married:
if our sport had gone forward, we had all been made
men.
FLUTE
O sweet bully Bottom! Thus hath he lost sixpence a
day during his life; he could not have ‘scaped
sixpence a day: an the duck had not given him
sixpence a day for playing Pyramus, I’ll be hanged;
he would have deserved it: sixpence a day in
Pyramus, or nothing.
Enter BOTTOM

BOTTOM
Where are these lads? where are these hearts?
QUINCE
Bottom! O must courageous day! O most happy hour!
BOTTOM
Masters, I am to discourse wonders: but ask me not
what; for if I tell you, I am no true Athenian. I
will tell you every thing, right as it fell out.
QUINCE
Let us hear,
sweet Bottom.
BOTTOM
Not a word of me. All that I will tell you is, that
the duck hath dined. Get your apparel together,
good strings to your beards, new ribbons to your
pumps; meet persently at the palace; every man look
o’er his part; for the short and the long is, our
play is preferred. In any case, let Thisby have
clean linenl and let not him that plays the lion
pair his nails, for they shall hang out for the
lion’s nalld. And, most dear actors, est no onions
nor garlic, for we are to utter sweet breath; and I
do not doubt but to hear them say, it is a sweet
comedy. No more words: away! go, away!
Exeunt

继续研究。。。

搞好了

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import java.util.Scanner;

public class Decrypt{
//private final static Scanner scan = new Scanner(System.in);
private final static String alphabet = "abcdefghijklmnopqrstuvwxyz";

static String[] shiftAlphabet (int[] key){
String[] shiftedAlphabet = {alphabet.substring(alphabet.length()-key[0])+
alphabet.substring(0, alphabet.length()-key[0]),
alphabet.substring(alphabet.length()-key[1])+
alphabet.substring(0, alphabet.length()-key[1])};
return shiftedAlphabet;
}

static String decrypt (String text, String[] shiftedAlphabet, int[] key){
StringBuilder t = new StringBuilder("");
int count = 0;
boolean oddEven = true;

for (int i=0, n=text.length(); i<n; ++i){
//change
if (text.charAt(i)=='%'){
t.append("%n");
++i;
continue;
}

if (!(Character.isLetter(text.charAt(i)))) {
t.append(text.charAt(i));
continue;
}

++count;

for (int m=0, o=alphabet.length(); m<o; ++m){
if (count%2==1)
oddEven=true;
else
oddEven=false;

if ((Character.toLowerCase(text.charAt(i))) == alphabet.charAt(m)){
if (Character.isUpperCase(text.charAt(i)))
t.append(Character.toUpperCase(shiftedAlphabet[oddEven?0:1].charAt(m)));
else
t.append(shiftedAlphabet[oddEven?0:1].charAt(m));
}
}
}

//change
// for (int i=0, l=t.length()-2; i<l; ++i){
// char char1=Character.toLowerCase(t.charAt(i)), char2=Character.toLowerCase(t.charAt(i+1));
// if ((char1=='y' && char2=='i')||(char1=='i' && char2=='y')||(char1=='w' && char2=='u')||(char1=='u' && char2=='w')||
// (char1=='q' && !(char2=='u')))
// return "";
// }
return t.toString();//+"\t\t\tOdd key "+key[0]+" Even key "+key[1];
}

static String addUpResult (String[] results){
StringBuilder result = new StringBuilder();
int position = 0, count = 0;

for (int i=0, l=results[0].length(); i<l; ++i){
if (results[0].charAt(i)=='\'' && !(results[0].charAt(i-1)==' ') && !(results[0].charAt(i-1)==' ')){
result.append(results[(count%2==1)?0:1].substring(position, i));
position = i;
++count;
continue;
}
if (results[0].charAt(i)=='\'' && results[0].charAt(i-1)==' '){
--count;
}

if (results[0].charAt(i)=='\'' && !(results[0].charAt(i-1)==' ')){
++count;
}

if (results[0].charAt(i)=='?'){
if (!(results[0].charAt(i-1)==' ')){
result.append(results[(count%2==1)?0:1].substring(position, i));
position = i;
++count;
continue;
}
result.append(" ?");
position = i+1;
++count;
continue;
}

if (results[0].charAt(i)=='%'){
if (results[0].charAt(i-1)==',' || results[0].charAt(i-1)=='.' ||
results[0].charAt(i-1)==':' || results[0].charAt(i-1)==';' ||
results[0].charAt(i-1)=='\''|| results[0].charAt(i-1)=='!'){
result.append(results[(count%2==1)?0:1].substring(position, i));
result.append("%n");
position = i+2;
++i;
continue;
}
if (!(results[0].charAt(i-2)=='%'))
result.append(results[(count%2==1)?0:1].substring(position, i));
result.append("%n");
position = i+2;
++i;
++count;
continue;
}

if (results[0].charAt(i)==' '){
if (results[0].charAt(i-1)==',' || results[0].charAt(i-1)=='.' ||
results[0].charAt(i-1)==':' || results[0].charAt(i-1)==';' ||
results[0].charAt(i-1)=='\''|| results[0].charAt(i-1)=='!'){
result.append(results[(count%2==1)?0:1].substring(position, i));
position = i;
continue;
}
result.append(results[(count%2==1)?0:1].substring(position, i));
position = i;
++count;
continue;
}



}
return result.toString();
}

public static void main (String[] args){
//change
// System.out.println("\n\n\nPlease enter the encrypted text:");//
// String text = scan.nextLine();
// scan.close();


// int[] key = new int[2];
// int l = alphabet.length();
// String t;
// for (; key[0]<l; ++key[0]){
// key[1]=0;
// for (; key[1]<l; ++key[1]){
// t = decrypt(text, shiftAlphabet(key), key);
// if (!(t==""))
// System.out.print(t+"\n");
// }
// System.out.println("\n");
// }
//Odd17 Even2


//String text = "UTGEG KZ. Ckjvpj. SLKEEV'J yqluv.%n%nVpkgi HWZPTG, WNLVV, UEQLV, rpu JVRTMGCKEI%nSLKEEV%nYcmg afw uvpk kq Dfvkqd'j yqluv ? zu jv tqdg jfov pgk?%nUKCIXVNZPX%nYg erpeqk sg jvcif qw. Qlv qw uqldk yg kj%nktrpjrftkgu.%nHCWKG%nKw yg efov eqk, vyge kjv gnra kj dcitvf: zv ifgj%neqk wqiyrtu, ffvy zv?%nHWZPTG%nKk zu pfv rfujksnv: afw jrxv eqk r dce zp ";
String text ="UTGEG KZ. Ckjvpj. SLKEEV'J yqluv.%n%nVpkgi HWZPTG, WNLVV, UEQLV, rpu JVRTMGCKEI%nSLKEEV%nYcmg afw uvpk kq Dfvkqd'j yqluv ? zu jv tqdg jfov pgk?%nUKCIXVNZPX%nYg erpeqk sg jvcif qw. Qlv qw uqldk yg kj%nktrpjrftkgu.%nHCWKG%nKw yg efov eqk, vyge kjv gnra kj dcitvf: zv ifgj%neqk wqiyrtu, ffvy zv?%nHWZPTG%nKk zu pfv rfujksnv: afw jrxv eqk r dce zp ccn%nCkjvpj rdcg vf ukjeyciiv Gaicdwj swk yg.%nWNLVV%nEq, yg jrvy jkdrca vyg dvuk nkk fh cea jrpukttrhk%ndce zp Ckjvpj.%nSLKEEV%nPgr rpu kjv sgjv rvtjqe kqf; cef jv zu c xvtp%ngcicdqlt hft c ungvv xfktg.%nWNLVV%nPql dwjv ura 'gcicxqe:' r gcicdqlt kj, Iff dcgju wj,%nc vykei qw ecliyv.%nVpkgi JPLI%n%nJPLI%nOrukgiu, kjv uwbg kj tqdkei hiqd kjv kgdrcg, rpu%nkjvtv zu vnq qi kjigv cqifj rpu ccukvu oftv dcitzgu:%nkw fwi jrftk ycu xqeg hftncif, ng jrf ccn dvge dcug%novp.%nWNLVV%nF jyvgk swcnp Sqkvfo! Kjlu jrvy yg nfuk jkorvptg c%nfra fltzpx ykj ckwg; yg efwcf pfv jrxv 'utcggu%njkorvptg c fra: rp vyg flmv ycu eqk xkmge ykd%njkorvptg c fra hft rccpkei Rptrolu, Z'cn dv yceivf;%nyg yfwcf jrxv ugjgixvf kk: uzzggeev r ucp zp%nRptrolu, ft pfvykei.%nVpkgi SQKVFO%n%nSQKVFO%nYygig cig vygjg nrfj? yygig cig vygjg jvcivj?%nSLKEEV%nSqkvfo! F dqjv efwicxgfwj ucp! Q ofuk ycgrp yqlt!%nSQKVFO%nOrukgiu, Z ro vf ukjefwiuv nqefvtj: dlv cjm ov eqk%nnjrv; wqi zh K vvnc pql, K cd eq viwv Rvygekrp. Z%nnkcn vvnc pql vxvtp kjzpx, tziyv cj zv hvnc fwk.%nSLKEEV%nCgk lu jvci, ungvv Dfvkqd.%nDFVKQD%nEqk r nqif qw dg. Rnc kjrv K yznc kgcn afw kj, vyck%nkjv uwbg jrvy ukegu. Ivv afwi rrgcigc kqxgkjvt,%nxqff uktzpxu vf pqlt dvcifj, pvy tzdsqeu vf pqlt%nrlogu; dgvv rigjgevca ck kjv gccctg; vxvtp dce cqfm%nq'gi ykj gciv; wqi kjv jjftk rpu kjv cqei kj, qlt%nrccp zu rigwgitvf. Zp cea eruv, nvv Vykjdp ycmg%necgrp nzpvp; rpu cgk eqk ykd kjrv rccpu vyg nzqe%ngczt jzu prkcu, wqi kjva uyccn jrpx fwk wqi kjv%nckfp'u eccnu. Rpu, ofuk ugrt ctvftj, grv pf fpzqeu%npft irtckt, hft yv rtv kq wkvvt ungvv digrvy; cef K%nff eqk uqldk swk kq jvci kjvo ura, zv kj r jyvgk%ntqdgua. Eq oftv nqifj: cncp! if, cncp!%nGoglpk";
//System.out.print(String.format(decrypt(text, shiftAlphabet(key), key)));
int[] key = {17,2}, key1 = {2, 17};
String[] results = {decrypt(text, shiftAlphabet(key), key),
decrypt(text, shiftAlphabet(key1), key1)};
//System.out.print(String.format(results[0]+"%n%n%n%n%n%n"+results[1]));
System.out.println("==================================================================");
System.out.print(String.format(addUpResult(results)));
}
}

SCENE II. Athens. QUINCE’S house.

Enter QUINCE, FLUTE, SNOUT, and STARVELING
QUINCE
Have you sent to Bottom’s house ? is he come home yet?
STARVELING
He cannot be heard of. Out of doubt he is
transported.
FLUTE
If he come not, then the play is marred: it goes
not forward, doth it?
QUINCE
It is not possible: you have not a man in all
Athens able to discharge Pyramus but he.
FLUTE
No, he hath simply the best wit of any handicraft
man in Athens.
QUINCE
Yea and the best person too; and he is a very
paramour for a sweet voice.
FLUTE
You must say ‘paragon:’ a paramour is, God bless us,
a thing of naught.
Enter SNUG

SNUG
Masters, the duke is coming from the temple, and
there is two or three lords and ladies more married:
if our sport had gone forward, we had all been made
men.
FLUTE
O sweet bully Bottom! Thus hath he lost sixpence a
day during his life; he could not have ‘scaped
sixpence a day: an the duke had not given him
sixpence a day for playing Pyramus, I’ll be hanged;
he would have deserved it: sixpence a day in
Pyramus, or nothing.
Enter BOTTOM

BOTTOM
Where are these lads? where are these hearts?
QUINCE
Bottom! O most courageous day! O most happy hour!
BOTTOM
Masters, I am to discourse wonders: but ask me not
what; for if I tell you, I am no true Athenian. I
will tell you every thing, right as it fell out.
QUINCE
Let us hear, sweet Bottom.
BOTTOM
Not a word of me. All that I will tell you is, that
the duke hath dined. Get your apparel together,
good strings to your beards, new ribbons to your
pumps; meet presently at the palace; every man look
o’er his part; for the short and the long is, our
play is preferred. In any case, let Thisby have
clean linen; and let not him that plays the lion
pair his nails, for they shall hang out for the
lion’s claws. And, most dear actors, eat no onions
nor garlic, for we are to utter sweet breath; and I
do not doubt but to hear them say, it is a sweet
comedy. No more words: away! go, away!

完美哈哈。。。

简化一下

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import java.util.Scanner;

public class Decrypt_Second {
private final static String alphabet = "abcdefghijklmnopqrstuvwxyz";

static String[] shiftAlphabet(int[] key) {
String[] shiftedAlphabet = {
alphabet.substring(alphabet.length() - key[0]) + alphabet.substring(0, alphabet.length() - key[0]),
alphabet.substring(alphabet.length() - key[1]) + alphabet.substring(0, alphabet.length() - key[1]) };
return shiftedAlphabet;
}

static String decrypt(String text, int[] key) {
String[] shiftedAlphabet = shiftAlphabet(key);
StringBuilder t = new StringBuilder("");
int count = 0;
boolean oddEven = true;

for (int i = 0, n = text.length(); i < n; ++i) {
if (text.charAt(i) == '%') {
t.append("%n");
++i;
continue;
}

if (!(Character.isLetter(text.charAt(i)))) {
t.append(text.charAt(i));
continue;
}

++count;

for (int m = 0, o = alphabet.length(); m < o; ++m) {
if (count % 2 == 1)
oddEven = true;
else
oddEven = false;

if ((Character.toLowerCase(text.charAt(i))) == alphabet.charAt(m)) {
if (Character.isUpperCase(text.charAt(i)))
t.append(Character.toUpperCase(shiftedAlphabet[oddEven ? 0 : 1].charAt(m)));
else
t.append(shiftedAlphabet[oddEven ? 0 : 1].charAt(m));
}
}
}
return t.toString();
}

static String addUpResult(String[] results) {
StringBuilder result = new StringBuilder();
int position = 0, count = 0;
char chr, chr1;

for (int i = 0, l = results[0].length(); i < l; ++i) {
try {
chr = results[0].charAt(i);
chr1 = results[0].charAt(i - 1);

if (chr == '\'' || chr == '?') {
if (chr1 == ' ') {
--count;
continue;
}

if (!(chr1 == ' ')) {
result.append(results[(count % 2 == 1) ? 0 : 1].substring(position, i));
position = i;
++count;
continue;
}

if (chr == '?') {
result.append(" ?");
position = i + 1;
++count;
continue;
}
}

if (chr == '%') {
if (chr1 == ',' || chr1 == '.' || chr1 == ':' || chr1 == ';' || chr1 == '\'' || chr1 == '!') {
result.append(results[(count % 2 == 1) ? 0 : 1].substring(position, i));
result.append("%n");
position = i + 2;
++i;
continue;
}

if (!(results[0].charAt(i - 2) == '%'))
result.append(results[(count % 2 == 1) ? 0 : 1].substring(position, i));

result.append("%n");
position = i + 2;
++i;
++count;
continue;
}

if (chr == ' ') {
if (chr1 == ',' || chr1 == '.' || chr1 == ':' || chr1 == ';' || chr1 == '\'' || chr1 == '!') {
result.append(results[(count % 2 == 1) ? 0 : 1].substring(position, i));
position = i;
continue;
}

result.append(results[(count % 2 == 1) ? 0 : 1].substring(position, i));
position = i;
++count;
continue;
}
} catch (Exception e) {
// System.out.println(e);
}
}
return result.toString();
}

public static void main(String[] args) {
String text = "UTGEG KZ. Ckjvpj. SLKEEV'J yqluv.%n%nVpkgi HWZPTG, WNLVV, UEQLV, rpu JVRTMGCKEI%nSLKEEV%nYcmg afw uvpk kq Dfvkqd'j yqluv ? zu jv tqdg jfov pgk?%nUKCIXVNZPX%nYg erpeqk sg jvcif qw. Qlv qw uqldk yg kj%nktrpjrftkgu.%nHCWKG%nKw yg efov eqk, vyge kjv gnra kj dcitvf: zv ifgj%neqk wqiyrtu, ffvy zv?%nHWZPTG%nKk zu pfv rfujksnv: afw jrxv eqk r dce zp ccn%nCkjvpj rdcg vf ukjeyciiv Gaicdwj swk yg.%nWNLVV%nEq, yg jrvy jkdrca vyg dvuk nkk fh cea jrpukttrhk%ndce zp Ckjvpj.%nSLKEEV%nPgr rpu kjv sgjv rvtjqe kqf; cef jv zu c xvtp%ngcicdqlt hft c ungvv xfktg.%nWNLVV%nPql dwjv ura 'gcicxqe:' r gcicdqlt kj, Iff dcgju wj,%nc vykei qw ecliyv.%nVpkgi JPLI%n%nJPLI%nOrukgiu, kjv uwbg kj tqdkei hiqd kjv kgdrcg, rpu%nkjvtv zu vnq qi kjigv cqifj rpu ccukvu oftv dcitzgu:%nkw fwi jrftk ycu xqeg hftncif, ng jrf ccn dvge dcug%novp.%nWNLVV%nF jyvgk swcnp Sqkvfo! Kjlu jrvy yg nfuk jkorvptg c%nfra fltzpx ykj ckwg; yg efwcf pfv jrxv 'utcggu%njkorvptg c fra: rp vyg flmv ycu eqk xkmge ykd%njkorvptg c fra hft rccpkei Rptrolu, Z'cn dv yceivf;%nyg yfwcf jrxv ugjgixvf kk: uzzggeev r ucp zp%nRptrolu, ft pfvykei.%nVpkgi SQKVFO%n%nSQKVFO%nYygig cig vygjg nrfj? yygig cig vygjg jvcivj?%nSLKEEV%nSqkvfo! F dqjv efwicxgfwj ucp! Q ofuk ycgrp yqlt!%nSQKVFO%nOrukgiu, Z ro vf ukjefwiuv nqefvtj: dlv cjm ov eqk%nnjrv; wqi zh K vvnc pql, K cd eq viwv Rvygekrp. Z%nnkcn vvnc pql vxvtp kjzpx, tziyv cj zv hvnc fwk.%nSLKEEV%nCgk lu jvci, ungvv Dfvkqd.%nDFVKQD%nEqk r nqif qw dg. Rnc kjrv K yznc kgcn afw kj, vyck%nkjv uwbg jrvy ukegu. Ivv afwi rrgcigc kqxgkjvt,%nxqff uktzpxu vf pqlt dvcifj, pvy tzdsqeu vf pqlt%nrlogu; dgvv rigjgevca ck kjv gccctg; vxvtp dce cqfm%nq'gi ykj gciv; wqi kjv jjftk rpu kjv cqei kj, qlt%nrccp zu rigwgitvf. Zp cea eruv, nvv Vykjdp ycmg%necgrp nzpvp; rpu cgk eqk ykd kjrv rccpu vyg nzqe%ngczt jzu prkcu, wqi kjva uyccn jrpx fwk wqi kjv%nckfp'u eccnu. Rpu, ofuk ugrt ctvftj, grv pf fpzqeu%npft irtckt, hft yv rtv kq wkvvt ungvv digrvy; cef K%nff eqk uqldk swk kq jvci kjvo ura, zv kj r jyvgk%ntqdgua. Eq oftv nqifj: cncp! if, cncp!%nGoglpk";
int[][] key = { { 17, 2 }, { 2, 17 } };
String[] results = { decrypt(text, key[0]), decrypt(text, key[1]) };

System.out.println("\n\n\n==================================================================");
System.out.print(String.format(addUpResult(results)));
System.out.println("\n\n\n==================================================================");
}
}

输出除了两根线应该都没变

==================================================================
SCENE II. Athens. QUINCE’S house.

Enter QUINCE, FLUTE, SNOUT, and STARVELING
QUINCE
Have you sent to Bottom’s house ? is he come home yet?
STARVELING
He cannot be heard of. Out of doubt he is
transported.
FLUTE
If he come not, then the play is marred: it goes
not forward, doth it?
QUINCE
It is not possible: you have not a man in all
Athens able to discharge Pyramus but he.
FLUTE
No, he hath simply the best wit of any handicraft
man in Athens.
QUINCE
Yea and the best person too; and he is a very
paramour for a sweet voice.
FLUTE
You must say ‘paragon:’ a paramour is, God bless us,
a thing of naught.
Enter SNUG

SNUG
Masters, the duke is coming from the temple, and
there is two or three lords and ladies more married:
if our sport had gone forward, we had all been made
men.
FLUTE
O sweet bully Bottom! Thus hath he lost sixpence a
day during his life; he could not have ‘scaped
sixpence a day: an the duke had not given him
sixpence a day for playing Pyramus, I’ll be hanged;
he would have deserved it: sixpence a day in
Pyramus, or nothing.
Enter BOTTOM

BOTTOM
Where are these lads? where are these hearts?
QUINCE
Bottom! O most courageous day! O most happy hour!
BOTTOM
Masters, I am to discourse wonders: but ask me not
what; for if I tell you, I am no true Athenian. I
will tell you every thing, right as it fell out.
QUINCE
Let us hear, sweet Bottom.
BOTTOM
Not a word of me. All that I will tell you is, that
the duke hath dined. Get your apparel together,
good strings to your beards, new ribbons to your
pumps; meet presently at the palace; every man look
o’er his part; for the short and the long is, our
play is preferred. In any case, let Thisby have
clean linen; and let not him that plays the lion
pair his nails, for they shall hang out for the
lion’s claws. And, most dear actors, eat no onions
nor garlic, for we are to utter sweet breath; and I
do not doubt but to hear them say, it is a sweet
comedy. No more words: away! go, away!

==================================================================

评论

:D 一言句子获取中...

加载中,最新评论有1分钟缓存...