Advertisement
Guest User

Untitled

a guest
May 28th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.49 KB | None | 0 0
  1. package cr;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9.  
  10. /**
  11. *
  12. * @author axel myrberg
  13. */
  14. public class PasswordCrack {
  15.  
  16. public static void main(String[] args) throws IOException {
  17. // Fill lists from files
  18. Dictionary dict = new Dictionary(args[0]);
  19. List<User> users = LoadUsers(args[1]);
  20. AddNamesToDict(dict, users);
  21. String pass[] = null;
  22. RoundOne(users, dict, pass);
  23. RoundTwo(users, dict, pass);
  24. RoundThree(users, dict, pass);
  25. }
  26.  
  27. private static void RoundThree(List<User> users, Dictionary dict, String[] pass) {
  28. for (int x = 48; x <= 122; x++) {
  29. // System.out.println("Round three x: " + (char) x);
  30. if (x == 58) {
  31. x = 65;
  32. }
  33. if (x == 90) {
  34. x = 97;
  35. }
  36. for (int i = 0; i <= 14; i++) {
  37. //System.out.println("Round three i: " + i);
  38. ResetDict(dict);
  39. RunFunc(users, dict, pass, i, x);
  40. SaveMangle(dict);
  41. for (int k = 0; k <= 14; k++) {
  42. RunFunc(users, dict, pass, k, x);
  43. ResetMangle(dict);
  44. }
  45. }
  46. }
  47. }
  48.  
  49. private static void RunFunc(List<User> users, Dictionary dict, String[] pass, int col, int k) {
  50. switch (col) {
  51. case 0:
  52. DeleteLast(users, dict, pass);
  53. break;
  54. case 1:
  55. DeleteFirst(users, dict, pass);
  56. break;
  57. case 2:
  58. Reverse(users, dict, pass);
  59. break;
  60. case 3:
  61. Duplicate(users, dict, pass);
  62. break;
  63. case 4:
  64. ReflectForward(users, dict, pass);
  65. break;
  66. case 5:
  67. ReflectBackward(users, dict, pass);
  68. break;
  69. case 6:
  70. Duplicate(users, dict, pass);
  71. break;
  72. case 7:
  73. Uppercase(users, dict, pass);
  74. break;
  75. case 8:
  76. Lowercase(users, dict, pass);
  77. break;
  78. case 9:
  79. Capitalize(users, dict, pass);
  80. break;
  81. case 10:
  82. NCapitalize(users, dict, pass);
  83. break;
  84. case 11:
  85. ToggleCaseEven(users, dict, pass);
  86. break;
  87. case 12:
  88. ToggleCaseOdd(users, dict, pass);
  89. break;
  90. case 13:
  91. Append(users, dict, pass, k);
  92. break;
  93. case 14:
  94. Prepend(users, dict, pass, k);
  95. break;
  96.  
  97. /*
  98. case 15:
  99. for (int x = 48; x <= 122; x++) {
  100. if (x == 58) {
  101. x = 65;
  102. }
  103. if (x == 90) {
  104. x = 97;
  105. }
  106. Append(users, dict, pass, k);
  107. ResetDict(dict);
  108. }
  109. break;
  110. case 16:
  111. for (int x = 48; x <= 122; x++) {
  112. if (x == 58) {
  113. x = 65;
  114. }
  115. if (x == 90) {
  116. x = 97;
  117. }
  118. Prepend(users, dict, pass, k);
  119. ResetDict(dict);
  120. }
  121. break;
  122. */
  123. }
  124. }
  125.  
  126. private static void RoundOne(List<User> users, Dictionary dict, String[] pass) {
  127. CompareCrypt(users, dict, pass);
  128. ResetDict(dict);
  129. //System.out.println("--------- Round One Complete ---------");
  130. }
  131.  
  132. private static void RoundTwo(List<User> users, Dictionary dict, String[] pass) {
  133. /*
  134. for (int i = 48; i <= 122; i++) {
  135. if (i == 58) {
  136. i = 65;
  137. }
  138. if (i == 90) {
  139. i = 97;
  140. }
  141. Prepend(users, dict, pass, i);
  142. System.out.println("Prepend compared");
  143. ResetDict(dict);
  144. Append(users, dict, pass, i);
  145. System.out.println("Append compared");
  146. ResetDict(dict);
  147. }
  148. */
  149. DeleteLast(users, dict, pass);
  150. ResetDict(dict);
  151. // System.out.println("DeleteLast compared");
  152. DeleteFirst(users, dict, pass);
  153. ResetDict(dict);
  154. //System.out.println("DeleteFirst compared");
  155. Reverse(users, dict, pass);
  156. ResetDict(dict);
  157. //System.out.println("Reverse compared");
  158. Duplicate(users, dict, pass);
  159. ResetDict(dict);
  160. //System.out.println("Duplicate compared");
  161. ReflectForward(users, dict, pass);
  162. ResetDict(dict);
  163. //System.out.println("ReflectForward compared");
  164. ReflectBackward(users, dict, pass);
  165. ResetDict(dict);
  166. //System.out.println("ReflectBackward compared");
  167. Uppercase(users, dict, pass);
  168. ResetDict(dict);
  169. //System.out.println("Uppercase compared");
  170. Lowercase(users, dict, pass);
  171. ResetDict(dict);
  172. //System.out.println("Lowercase compared");
  173. Capitalize(users, dict, pass);
  174. ResetDict(dict);
  175. //System.out.println("Capitalize compared");
  176. NCapitalize(users, dict, pass);
  177. ResetDict(dict);
  178. //System.out.println("NCapitalize compared");
  179. ToggleCaseEven(users, dict, pass);
  180. ResetDict(dict);
  181. //System.out.println("ToggleCaseEven compared");
  182. ToggleCaseOdd(users, dict, pass);
  183. ResetDict(dict);
  184. //System.out.println("ToggleCaseOdd compared");
  185. //System.out.println("--------- Round Two Complete ---------");
  186. }
  187.  
  188. static void AddNamesToDict(Dictionary dict, List<User> users) {
  189. Cell prev = dict.start;
  190. for (int i = 0; i < users.size(); i++) {
  191. Cell temp = prev;
  192. prev = new Cell(users.get(i).firstName);
  193. prev.next = temp;
  194. temp = prev;
  195. prev = new Cell(users.get(i).lastName);
  196. prev.next = temp;
  197. }
  198. dict.start = prev;
  199. }
  200.  
  201. public static List<User> LoadUsers(String file) throws FileNotFoundException, IOException {
  202. BufferedReader in = new BufferedReader(new FileReader(file));
  203. String str;
  204. List<User> list = new ArrayList<User>();
  205. while ((str = in.readLine()) != null) {
  206. User user = new User(str);
  207. list.add(user);
  208. }
  209.  
  210. return list;
  211. }
  212.  
  213. private static void CompareCrypt(List<User> users, Dictionary dict, String[] pass) {
  214. for (int i = 0; i < users.size(); i++) {
  215. Cell curr = dict.start;
  216. while (curr.next != null) {
  217. String crypt = jcrypt.crypt(users.get(i).salt, curr.mangled.toString());
  218. if (crypt.equals(users.get(i).hash)) {
  219. users.get(i).password = curr.mangled.toString();
  220. System.out.println(users.get(i).password);
  221. users.remove(users.get(i));
  222. CompareCrypt(users, dict, pass);
  223. break;
  224. }
  225. curr = curr.next;
  226. }
  227. }
  228. }
  229.  
  230. private static void Compare(User[] users, Dictionary dict, String[] pass) {
  231. for (int i = 0; i < users.length; i++) {
  232. Cell curr = dict.start;
  233. while (curr.next != null) {
  234. if (pass[i].equals(curr.mangled.toString())) {
  235. users[i].password = pass[i];
  236. }
  237. curr = curr.next;
  238. }
  239. }
  240. }
  241.  
  242. private static String[] LoadPasswords(String file) throws IOException {
  243. BufferedReader in = new BufferedReader(new FileReader(file));
  244. String str;
  245. List<String> list = new ArrayList<String>();
  246. while ((str = in.readLine()) != null) {
  247. String user = new String(str);
  248. list.add(user);
  249. }
  250. String[] userArray = list.toArray(new String[0]);
  251. return userArray;
  252. }
  253.  
  254. private static void ResetDict(Dictionary dict) {
  255. Cell curr = dict.start;
  256. while (curr != null) {
  257. curr.mangled.setLength(0);
  258. curr.mangled.append(curr.original);
  259. curr = curr.next;
  260. }
  261. }
  262.  
  263. private static void Prepend(List<User> users, Dictionary dict, String[] pass, int i) {
  264. Cell curr = dict.start;
  265. while (curr != null) {
  266. curr.mangled.reverse().append((char) i);
  267. curr.mangled.reverse();
  268. curr = curr.next;
  269. }
  270. CompareCrypt(users, dict, pass);
  271. }
  272.  
  273. private static void Append(List<User> users, Dictionary dict, String[] pass, int i) {
  274. if (i == 58) {
  275. i = 65;
  276. }
  277. if (i == 90) {
  278. i = 97;
  279. }
  280. Cell curr = dict.start;
  281. while (curr != null) {
  282. curr.mangled.append((char) i);
  283. curr = curr.next;
  284. }
  285. CompareCrypt(users, dict, pass);
  286. }
  287.  
  288. private static void DeleteLast(List<User> users, Dictionary dict, String[] pass) {
  289. Cell curr = dict.start;
  290. while (curr != null) {
  291. if (curr.mangled.length() <= 1) {
  292. curr = curr.next;
  293. continue;
  294. }
  295. curr.mangled.setLength(curr.mangled.length() - 1);
  296. curr = curr.next;
  297. }
  298. CompareCrypt(users, dict, pass);
  299. }
  300.  
  301. private static void DeleteFirst(List<User> users, Dictionary dict, String[] pass) {
  302. Cell curr = dict.start;
  303. while (curr != null) {
  304. if (curr.mangled.length() <= 1) {
  305. curr = curr.next;
  306. continue;
  307. }
  308. curr.mangled.reverse();
  309. curr.mangled.setLength(curr.mangled.length() - 1);
  310. curr.mangled.reverse();
  311. curr = curr.next;
  312. }
  313. CompareCrypt(users, dict, pass);
  314. }
  315.  
  316. private static void Reverse(List<User> users, Dictionary dict, String[] pass) {
  317. Cell curr = dict.start;
  318. while (curr != null) {
  319. curr.mangled.reverse();
  320. curr = curr.next;
  321. }
  322. CompareCrypt(users, dict, pass);
  323. }
  324.  
  325. private static void Duplicate(List<User> users, Dictionary dict, String[] pass) {
  326. Cell curr = dict.start;
  327. while (curr != null) {
  328. curr.mangled.append(curr.mangled.toString());
  329. curr = curr.next;
  330. }
  331. CompareCrypt(users, dict, pass);
  332. }
  333.  
  334. private static void ReflectForward(List<User> users, Dictionary dict, String[] pass) {
  335. Cell curr = dict.start;
  336. while (curr != null) {
  337. curr.mangled.reverse();
  338. String temp = curr.mangled.toString();
  339. curr.mangled.reverse();
  340. curr.mangled.append(temp);
  341. curr = curr.next;
  342. }
  343. CompareCrypt(users, dict, pass);
  344. }
  345.  
  346. private static void ReflectBackward(List<User> users, Dictionary dict, String[] pass) {
  347. Cell curr = dict.start;
  348. while (curr != null) {
  349. String temp = curr.mangled.toString();
  350. curr.mangled.reverse();
  351. curr.mangled.append(temp);
  352. curr = curr.next;
  353. }
  354. CompareCrypt(users, dict, pass);
  355. }
  356.  
  357. private static void Uppercase(List<User> users, Dictionary dict, String[] pass) {
  358. Cell curr = dict.start;
  359. while (curr != null) {
  360. String temp = curr.mangled.toString().toUpperCase();
  361. curr.mangled.setLength(0);
  362. curr.mangled.append(temp);
  363. curr = curr.next;
  364. }
  365. CompareCrypt(users, dict, pass);
  366. }
  367.  
  368. private static void Lowercase(List<User> users, Dictionary dict, String[] pass) {
  369. Cell curr = dict.start;
  370. while (curr != null) {
  371. String temp = curr.mangled.toString().toLowerCase();
  372. curr.mangled.setLength(0);
  373. curr.mangled.append(temp);
  374. curr = curr.next;
  375. }
  376. CompareCrypt(users, dict, pass);
  377. }
  378.  
  379. private static void Capitalize(List<User> users, Dictionary dict, String[] pass) {
  380. Cell curr = dict.start;
  381. while (curr != null) {
  382. if (curr.mangled.charAt(0) < 58) {
  383.  
  384. } else if ((curr.mangled.charAt(0) >= 65) && (curr.mangled.charAt(0) <= 90)) {
  385. curr.mangled.setCharAt(0, (char) (curr.mangled.charAt(0) + 32));
  386. } else if ((curr.mangled.charAt(0) >= 97) && (curr.mangled.charAt(0) <= 122)) {
  387. curr.mangled.setCharAt(0, (char) (curr.mangled.charAt(0) - 32));
  388. }
  389. curr = curr.next;
  390.  
  391. }
  392. CompareCrypt(users, dict, pass);
  393. }
  394.  
  395. private static void NCapitalize(List<User> users, Dictionary dict, String[] pass) {
  396. Cell curr = dict.start;
  397. while (curr != null) {
  398. char tempChar = curr.mangled.charAt(0);
  399. curr.mangled.reverse();
  400. curr.mangled.setLength(curr.mangled.length() - 1);
  401. String temp = curr.mangled.toString().toUpperCase();
  402. curr.mangled.setLength(0);
  403. curr.mangled.append(temp);
  404. curr.mangled.append(tempChar);
  405. curr.mangled.reverse();
  406. curr = curr.next;
  407. }
  408. CompareCrypt(users, dict, pass);
  409. }
  410.  
  411. private static void ToggleCaseEven(List<User> users, Dictionary dict, String[] pass) {
  412. Cell curr = dict.start;
  413. while (curr != null) {
  414. for (int i = 0; i < curr.mangled.length(); i++) {
  415. if (i % 2 == 0) {
  416. if (curr.mangled.charAt(0) < 58) {
  417. } else if ((curr.mangled.charAt(i) >= 65) && (curr.mangled.charAt(i) <= 90)) {
  418. curr.mangled.setCharAt(i, (char) (curr.mangled.charAt(i) + 32));
  419. } else if ((curr.mangled.charAt(i) >= 97) && (curr.mangled.charAt(i) <= 122)) {
  420. curr.mangled.setCharAt(i, (char) (curr.mangled.charAt(i) - 32));
  421. }
  422. }
  423. }
  424. curr = curr.next;
  425. }
  426. CompareCrypt(users, dict, pass);
  427. }
  428.  
  429. private static void ToggleCaseOdd(List<User> users, Dictionary dict, String[] pass) {
  430. Cell curr = dict.start;
  431. while (curr != null) {
  432. for (int i = 0; i < curr.mangled.length(); i++) {
  433. if (i % 2 != 0) {
  434. if (curr.mangled.charAt(0) < 58) {
  435. } else if ((curr.mangled.charAt(i) >= 65) && (curr.mangled.charAt(i) <= 90)) {
  436. curr.mangled.setCharAt(i, (char) (curr.mangled.charAt(i) + 32));
  437. } else if ((curr.mangled.charAt(i) >= 97) && (curr.mangled.charAt(i) <= 122)) {
  438. curr.mangled.setCharAt(i, (char) (curr.mangled.charAt(i) - 32));
  439. }
  440. }
  441. }
  442. curr = curr.next;
  443. }
  444. CompareCrypt(users, dict, pass);
  445. }
  446.  
  447. private static void ResetMangle(Dictionary dict) {
  448. Cell curr = dict.start;
  449. while (curr != null) {
  450. curr.mangled.setLength(0);
  451. curr.mangled.append(curr.tempMangled);
  452. curr = curr.next;
  453. }
  454. }
  455.  
  456. private static void SaveMangle(Dictionary dict) {
  457. Cell curr = dict.start;
  458. while (curr != null) {
  459. curr.tempMangled = curr.mangled.toString();
  460. curr = curr.next;
  461.  
  462. }
  463. }
  464. }
  465.  
  466. class Cell {
  467.  
  468. Cell next;
  469. StringBuilder mangled;
  470. String original;
  471. String tempMangled;
  472.  
  473. public Cell() {
  474. }
  475.  
  476. public Cell(String original) {
  477. original = original.replaceAll("[-+.^:,]", "");
  478. this.mangled = new StringBuilder(original);
  479. this.original = original;
  480. }
  481.  
  482. @Override
  483. public String toString() {
  484. return "Cell{" + "mangled=" + mangled + ", original=" + original + '}';
  485. }
  486.  
  487. }
  488.  
  489. class Dictionary {
  490.  
  491. Cell start;
  492. Cell last;
  493.  
  494. public Dictionary(String line) throws IOException {
  495. FillCells(line);
  496. //System.out.println("dictionary done");
  497.  
  498. }
  499.  
  500. public Cell getStart() {
  501. return start;
  502. }
  503.  
  504. public void fillTempMangled() {
  505. Cell curr = this.start;
  506. while (curr != null) {
  507. curr.tempMangled = curr.mangled.toString();
  508. curr = curr.next;
  509. }
  510.  
  511. }
  512.  
  513. public void AddToStart(String v) {
  514. if (start == null) {
  515. start = new Cell(v);
  516. } else {
  517. Cell n = new Cell(v);
  518. n.next = start;
  519. start = n;
  520. }
  521.  
  522. }
  523.  
  524. public void FillCells(String file) throws IOException {
  525. int k = 1;
  526. try (BufferedReader br = new BufferedReader(new FileReader(file))) {
  527. String line;
  528. Cell next = null;
  529. Cell curr = new Cell(br.readLine());
  530. this.start = curr;
  531. while ((line = br.readLine()) != null) {
  532. curr.next = new Cell(line);
  533. curr = curr.next;
  534. }
  535. this.last = curr;
  536. }
  537. }
  538. }
  539.  
  540. class User {
  541.  
  542. String user;
  543. String salt;
  544. String firstName;
  545. String lastName;
  546. String middleName;
  547. String password;
  548. String hash;
  549.  
  550. public User(String arg) throws IOException {
  551. LoadAttributes(arg);
  552. }
  553.  
  554. public void LoadAttributes(String arg) {
  555. String userAttributes[] = arg.split(":");
  556. this.user = userAttributes[0];
  557. this.hash = userAttributes[1];
  558. String name[] = userAttributes[4].split(" ");
  559. if (name.length == 2) {
  560. this.firstName = name[0];
  561. this.lastName = name[1];
  562. }
  563. if (name.length == 3) {
  564. this.firstName = name[0];
  565. this.middleName = name[1];
  566. this.lastName = name[2];
  567. }
  568. this.salt = this.hash.charAt(0) + "" + this.hash.charAt(1);
  569. }
  570.  
  571. @Override
  572. public String toString() {
  573. return "User{" + "user=" + user + ", salt=" + salt + ", firstName=" + firstName + ", lastName=" + lastName + ", middleName=" + middleName + ", password=" + password + ", hash=" + hash + '}';
  574. }
  575.  
  576. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement