概率算法/重合指数法 破解凯撒偏移密码

//作者-生化,用于密码学基础作业- -
package Algorithms;

import java.util.ArrayList;
import java.util.List;
import java.lang.Math;;

public class ShiftCiper {

	public static void satitisticalAnalysis() {
		String cipherText = "OVDTHUFWVZZPISLRLFZHYLAOLYLWSLHZLMPUKAOLHUZDLY";
		List probList = new ArrayList();
		addprob(probList);
		List cipherList = new ArrayList();
		addprob(cipherList);
		for(int i=0;i'Z'){
						s-=26;
					}else if(s<'A'){
						s+=26;
					}
					s+='a'-'A';
					plainText+=s;
				}
				System.out.println("原文为:"+plainText);
			}
		}
	}
	
	public static void main(String[] args) {
		satitisticalAnalysis();
	}

    static class prob {
		String key;
		double prob;
		
		public prob(String key, double prob) {
			super();
			this.key = key;
			this.prob = prob/100;
		}
		
		public void addProb(){
			prob = prob+1;
		}

		public String getKey() {
			return key;
		}

		public void setKey(String key) {
			this.key = key;
		}

		public double getProb() {
			return prob;
		}

		public void setProb(double prob) {
			this.prob = prob;
		}
		
	}

	private static void addprob(List problist) {
		// TODO Auto-generated method stub
		prob a = new prob("a", 8.2);
		prob b = new prob("b", 1.5);
		prob c = new prob("c", 2.8);
		prob d = new prob("d", 4.3d);
		prob e = new prob("e", 12.7);
		prob f = new prob("f", 2.2d);
		prob g = new prob("g", 2.0d);
		prob h = new prob("h", 6.1d);
		prob i = new prob("i", 7.0d);
		prob j = new prob("j", 0.2d);
		prob k = new prob("k", 0.8d);
		prob l = new prob("l", 4.0d);
		prob m = new prob("m", 2.4d);
		prob n = new prob("n", 6.7d);
		prob o = new prob("o", 1.5d);
		prob p = new prob("p", 1.9d);
		prob q = new prob("q", 0.1d);
		prob r = new prob("r", 6.0d);
		prob s = new prob("s", 6.3d);
		prob t = new prob("t", 9.1d);
		prob u = new prob("u", 2.8d);
		prob v = new prob("v", 1.0d);
		prob w = new prob("w", 2.4d);
		prob x = new prob("x", 0.2d);
		prob y = new prob("y", 2.0d);
		prob z = new prob("z", 0.1d);
		problist.add(a);
		problist.add(b);
		problist.add(c);
		problist.add(d);
		problist.add(e);
		problist.add(f);
		problist.add(g);
		problist.add(h);
		problist.add(i);
		problist.add(j);
		problist.add(k);
		problist.add(l);
		problist.add(m);
		problist.add(n);
		problist.add(o);
		problist.add(p);
		problist.add(q);
		problist.add(r);
		problist.add(s);
		problist.add(t);
		problist.add(u);
		problist.add(v);
		problist.add(w);
		problist.add(x);
		problist.add(y);
		problist.add(z);
	}
}

作者-生化,用于密码学基础作业- -

你可能感兴趣的:(密码学)