Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Vector<Integer> solveVignereII(String cipherText) {
- Vector<Integer> ret = new Vector<Integer>();
- Map<String, Integer> tlas = new HashMap<String, Integer>();
- // find frequency of TLAs
- for (int i : new Range(cipherText.length() - 3)) {
- String tla = cipherText.substring(i, i + 3);
- if (tlas.containsKey(tla)) {
- tlas.put(tla, tlas.get(tla) + 1);
- } else {
- tlas.put(tla, 1);
- }
- }
- puts(tlas);
- Map<Integer, Integer> dists = new HashMap<Integer, Integer>();
- for (String k : tlas.keySet()) {
- if (tlas.get(k) < 2) {
- // tlas.remove(k);
- } else {
- int i = cipherText.indexOf(k);
- for (int n = cipherText.indexOf(k, i + 1);
- n > 0;
- i = n, n = cipherText.indexOf(k, n + 1)) {
- int dist = n - i;
- if (dists.containsKey(dist)) {
- dists.put(dist, dists.get(dist) + 1);
- } else {
- dists.put(dist, 1);
- }
- }
- }
- }
- puts(dists);
- for (int i : new Range(4, 21)) {
- int matchrate = 0;
- int total = 0;
- for (int d : dists.keySet()) {
- if (d % i == 0) {
- matchrate += dists.get(d);
- }
- total += dists.get(d);
- }
- puts("" + i + " " + matchrate + "/" + dists.size());
- if (matchrate > total * .9) {
- ret.add(i);
- }
- }
- puts(ret);
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement