资讯详情

凯撒密码暴力解码方法Java实现

凯撒密码最简单、最粗糙的解码方法:遍历所有可能的移位方法,然后输出。在本实验中,确保输入字符仅包括大写和空格.

public class question {     public static void main(String[] args) {         System.out.println("输入:");         Scanner scan = new Scanner(System.in);         String s = scan.nextLine();         for(int k = 1; k < 26; k    ) {             StringBuilder sb = new StringBuilder();             for (int i = 0; i < s.length(); i  ) {                 if (s.charAt(i) == ' ') {                     sb.append(' ');                     continue;                 } else {                     if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') {                         if ((int) (s.charAt(i))   k > 90) {                             sb.append((char) (s.charAt(i)   k - 90   64));                         } else {                             sb.append((char) (s.charAt(i)   k));                         }                     } else {                         if ((int) (s.charAt(i))   k > 122) {                             sb.append((char) (s.charAt(i)   k - 122   96));                         } else {                             sb.append((char) (s.charAt(i)   k));                         }                     }                 }             }             System.out.println("k = "   k    " Result : "   sb.toString());         }     } } 

测试案例:Rjjy rj ts ymj xfggfym bj bnqq inxhzxx ymj uqfs

结果:

输入: Rjjy rj ts ymj xfggfym bj bnqq inxhzxx ymj uqfs k = 1 Result : Skkz sk ut znk yghhgzn ck corr joyiayy znk vrgt k = 2 Result : Tlla tl vu aol zhiihao dl dpss kpzjbzz aol wshu k = 3 Result : Ummb um wv bpm aijjibp em eqtt lqakcaa bpm xtiv k = 4 Result : Vnnc vn xw cqn bjkkjcq fn fruu mrbldbb cqn yujw k = 5 Result : Wood wo yx dro ckllkdr go gsvv nscmecc dro zvkx k = 6 Result : Xppe xp zy esp dlmmles hp htww otdnfdd esp awly k = 7 Result : Yqqf yq az ftq emnnmft iq iuxx pueogee ftq bxmz k = 8 Result : Zrrg zr ba gur fnoongu jr jvyy qvfphff gur cyna k = 9 Result : Assh as cb hvs goppohv ks kwzz rwgqigg hvs dzob k = 10 Result : Btti bt dc iwt hpqqpiw lt lxaa sxhrjhh iwt eapc k = 11 Result : Cuuj cu ed jxu iqrrqjx mu mybb tyiskii jxu fbqd k = 12 Result : Dvvk dv fe kyv jrssrky nv nzcc uzjtljj kyv gcre k = 13 Result : Ewwl ew gf lzw ksttslz ow oadd vakumkk lzw hdsf k = 14 Result : Fxxm fx hg max ltuutma px pbee wblvnll max ietg k = 15 Result : Gyyn gy ih nby muvvunb qy qcff xcmwomm nby jfuh k = 16 Result : Hzzo hz ji ocz nvwwvoc rz rdgg ydnxpnn ocz kgvi k = 17 Result : Iaap ia kj pda owxxwpd sa sehh zeoyqoo pda lhwj k = 18 Result : Jbbq jb lk qeb pxyyxqe tb tfii afpzrpp qeb mixk k = 19 Result : Kccr kc ml rfc qyzzyrf uc ugjj bgqasqq rfc njyl k = 20 Result : Ldds ld nm sgd rzaazsg vd vhkk chrbtrr sgd okzm k = 21 Result : Meet me on the sabbath we will discuss the plan k = 22 Result : Nffu nf po uif tbccbui xf xjmm ejtdvtt uif qmbo k = 23 Result : Oggv og qp vjg ucddcvj yg yknn fkuewuu vjg rncp k = 24 Result : Phhw ph rq wkh vdeedwk zh zloo glvfxvv wkh sodq k = 25 Result : Qiix qi sr xli weffexl ai ampp hmwgyww xli tper  

所以答案很明显k = 21出现。 Meet me on the sabbath we will discuss the plan.

这个问题也可以根据词频和英语用法习惯来猜测。ymj两次出现。英语可以想到the,代入检验即可。

或者从两个词的地方入手,猜测:at/on/or…

标签: 控制电缆kyv绝缘电阻500m

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台