Advertisement
doranchak

Untitled

Mar 18th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.66 KB | None | 0 0
  1. package com.zodiackillerciphers.tests;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. import com.zodiackillerciphers.io.FileUtil;
  7.  
  8. public class NickPelling {
  9. /** http://ciphermysteries.com/2017/03/15/might-z408-zodiac-killer-cipher-clue-book */
  10. static Map<String, int[]> preMap = new HashMap<String, int[]>();
  11. static {
  12. preMap.put("E", new int[] {7,7});
  13. preMap.put("TAOINS", new int[] {4,4});
  14. preMap.put("LR", new int[] {3,3});
  15. preMap.put("DFH", new int[] {2,2});
  16. preMap.put("BCGKMPUVWYJQZ", new int[] {0,1});
  17. preMap.put("X", new int[] {0,3});
  18. }
  19.  
  20. /** map letter to accepted range of counts */
  21. static Map<Character, int[]> map = new HashMap<Character, int[]>();
  22. static {
  23. for (String key : preMap.keySet()) {
  24. for (int i=0; i<key.length(); i++) {
  25. char ch = key.charAt(i);
  26. map.put(ch, preMap.get(key));
  27. }
  28. }
  29.  
  30. }
  31.  
  32. public static void filterTest(String path) {
  33.  
  34. StringBuffer text = FileUtil.loadSBFrom(path);
  35. text = FileUtil.convert(text.toString());
  36.  
  37. /** scan given text to look for segments that satisfy the filter */
  38. for (int i=0; i<text.length(); i++) {
  39. String sub = "";
  40. Map<Character, Integer> counts = new HashMap<Character, Integer>();
  41. for (int j=i; j<text.length(); j++) {
  42. char ch = text.charAt(j);
  43. sub += ch;
  44. Integer val = counts.get(ch);
  45. if (val == null) val = 0;
  46. val++;
  47. counts.put(ch ,val);
  48. int result = check(counts);
  49. if (result == -1) {
  50. break;
  51. }
  52. if (result == 1) {
  53. System.out.println(i + ": " + sub);
  54. break;
  55. }
  56. }
  57. }
  58. }
  59.  
  60. /** return -1 if ranges violated, 0 if not, 1 if all ranges are exact */
  61. static int check(Map<Character, Integer> counts) {
  62. boolean exact = true;
  63. for (Character ch : map.keySet()) {
  64. int min = map.get(ch)[0];
  65. int max = map.get(ch)[1];
  66. Integer val = counts.get(ch);
  67. if (val == null) val = 0;
  68. if (val > max) return -1;
  69. if (val < min) exact = false;
  70. }
  71. if (exact) return 1;
  72. return 0;
  73. }
  74. public static void testZodiacLetters() {
  75. String[] files = new String[] {
  76. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1966-11-29-the-confession.txt",
  77. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1966-12-desk.txt",
  78. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1967-04-30-bates.txt",
  79. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-07-31-cipher.txt",
  80. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-07-31-letter-envelope.txt",
  81. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-07-31-letter-sf-examiner-envelope.txt",
  82. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-07-31-letter-sf-examiner.txt",
  83. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-07-31-letter-vallejo-times-herald-envelope.txt",
  84. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-07-31-letter-vallejo-times-herald.txt",
  85. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-07-31-letter.txt",
  86. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-08-04-examiner.txt",
  87. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-09-27-car-door.txt",
  88. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-10-13-examiner-envelope.txt",
  89. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-10-13-examiner.txt",
  90. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-11-08-340-cipher-envelope.txt",
  91. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-11-08-340-cipher.txt",
  92. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-11-09-chronicle-envelope.txt",
  93. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-11-09-chronicle.txt",
  94. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-12-20-melvin-envelope.txt",
  95. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1969-12-20-melvin.txt",
  96. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1970-04-20-my-name-is-envelope.txt",
  97. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1970-04-20-my-name-is.txt",
  98. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1970-04-28-chronicle.txt",
  99. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1970-06-26-chronicle-cipher-envelope.txt",
  100. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1970-06-26-chronicle-cipher.txt",
  101. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1970-07-24-chronicle-envelope.txt",
  102. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1970-07-24-chronicle.txt",
  103. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1970-07-26-chronicle-envelope.txt",
  104. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1970-07-26-chronicle.txt",
  105. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1970-10-05.txt",
  106. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1970-10-27-avery-envelope.txt",
  107. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1970-10-27-avery.txt",
  108. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1971-03-13-times-envelope.txt",
  109. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1971-03-13-times.txt",
  110. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1971-03-22-lake-tahoe-card-back.txt",
  111. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1971-03-22-lake-tahoe-card.txt",
  112. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1974-01-29-exorcist-envelope.txt",
  113. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1974-01-29-exorcist.txt",
  114. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1974-02-14-sla-envelope.txt",
  115. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1974-02-14-sla.txt",
  116. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1974-05-08-badlands-envelope.txt",
  117. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1974-05-08-badlands.txt",
  118. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1974-07-08-count-marco-red-phantom-envelope.txt",
  119. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1974-07-08-count-marco-red-phantom.txt",
  120. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/letters/1978-04-24-chronicle.txt"
  121. };
  122. for (String file : files) {
  123. System.out.println(file);
  124. filterTest(file);
  125. }
  126. }
  127.  
  128. public static void testBooks() {
  129. String[] files = new String[] {
  130. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg10462.txt",
  131. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg10799.txt",
  132. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg11364.txt",
  133. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg11889.txt",
  134. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg12180.txt",
  135. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg1322.txt",
  136. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg1342.txt",
  137. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg135.txt",
  138. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg1661.txt",
  139. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg2591.txt",
  140. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg30601.txt",
  141. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg4300.txt",
  142. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg5200.txt",
  143. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg76.txt",
  144. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg9296.txt",
  145. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg9798.txt",
  146. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/pg9881.txt",
  147. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/docs/gutenberg/tale.txt",
  148. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/generator/corpus-for-cipher-generator-with-others/pg1184.txt",
  149. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/generator/corpus-for-cipher-generator-with-others/pg135.txt",
  150. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/generator/corpus-for-cipher-generator-with-others/pg14833.txt",
  151. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/generator/corpus-for-cipher-generator-with-others/pg25880.txt",
  152. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/generator/corpus-for-cipher-generator-with-others/pg2600.txt",
  153. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/generator/corpus-for-cipher-generator-with-others/pg2701.txt",
  154. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/generator/corpus-for-cipher-generator-with-others/pg505.txt",
  155. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/generator/corpus-for-cipher-generator-with-others/pg747.txt",
  156. "/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/generator/corpus-for-cipher-generator-with-others/pg808.txt"
  157. };
  158. for (String file : files) {
  159. System.out.println(file);
  160. filterTest(file);
  161. }
  162. }
  163. public static void main(String[] args) {
  164. //filterTest("/Users/doranchak/projects/zodiac/zodiac-killer-ciphers/generator/corpus-for-cipher-generator-with-others/pg2701.txt");
  165. //filterTest("/Users/doranchak/Downloads/test.txt");
  166. testZodiacLetters();
  167. }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement