Advertisement
Guest User

Untitled

a guest
Oct 25th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. package com.aciw.foobar.mnemonic;
  2.  
  3. import java.security.MessageDigest;
  4. import java.security.NoSuchAlgorithmException;
  5. import java.util.ArrayList;
  6. import java.util.*;
  7. import java.io.*;
  8.  
  9. import com.aciw.foobar.utility.RESTClient;
  10.  
  11. /**
  12. *
  13. * @author Administrator
  14. *
  15. */
  16. public class App {
  17. private static final String username = "<enter_username_here>";
  18. private static final String password = "<enter_password_here>";
  19.  
  20. // Inputs for set1 (Ent1) and the bonus set (Ent2)
  21. private static final String Ent1 = "7f7f7f7f7f7f7f7f";
  22. private static final String Ent2 = "7f7f7f7f7f7f7f7e";
  23.  
  24.  
  25. public static ArrayList<String> wordList = new ArrayList<String>();
  26.  
  27. public static File wordListInput = new File("./files/1/Word_List_Input_Set_1.txt");
  28.  
  29. // This skeleton is convert a single entropy to a mnemonic sentence.
  30. // You must modify the code to convert 2 entropys to mnemonic sentences.
  31. public static void main(String[] args) throws IOException, NoSuchAlgorithmException {
  32.  
  33. RESTClient.setUsername(username);
  34. RESTClient.setPassword(password);
  35.  
  36. // Insert Code here...
  37.  
  38. byte[] ent1Array = Ent1.getBytes("UTF-8");
  39. byte[] ent2Array = Ent2.getBytes("UTF-8");
  40. byte[] hashEnt1Array = hashingEnt(Ent1);
  41. byte[] hashEnt2Array = hashingEnt(Ent2);
  42. boolean[] bitEnt1Array = byteArray2BitArray(ent1Array);
  43. boolean[] bitHashEnt1Array = byteArray2BitArray(hashEnt1Array);
  44. boolean[] bitEnt2Array = byteArray2BitArray(ent2Array);
  45. boolean[] bitHashEnt2Array = byteArray2BitArray(hashEnt2Array);
  46.  
  47. //Methods begin here
  48.  
  49.  
  50.  
  51.  
  52. // The final step is to take these concatenated bits and split
  53. // them into groups of bits. Each group encodes number
  54. // which is a position in a wordlist. We convert numbers into
  55. // words and use joined words as mnemonic sentence.
  56. // ArrayList<String> OutputWords = getWords(concatBits);
  57.  
  58. // Submit answer
  59. }
  60.  
  61. public static boolean[] byteArray2BitArray(byte[] bytes)
  62. {
  63. boolean[] bits = new boolean[bytes.length * 8];
  64. for (int i = 0; i < bytes.length * 8; i++)
  65. {
  66. if ((bytes[i / 8] & (1 << (7 - (i % 8)))) > 0)
  67. bits[i] = true;
  68. }
  69. return bits;
  70. }
  71.  
  72. public static byte[] hashingEnt(String in) throws NoSuchAlgorithmException
  73. {
  74.  
  75. MessageDigest md = MessageDigest.getInstance("SHA-256");
  76. md.update(in.getBytes());
  77. byte byteData[] = md.digest();
  78. return byteData;
  79. }
  80.  
  81.  
  82.  
  83. public static void loadFiles() throws IOException
  84. {
  85.  
  86. Scanner in;
  87. String line;
  88.  
  89. in = new Scanner(wordListInput);
  90. while(in.hasNext())
  91. {
  92. line = in.nextLine();
  93. if(!(line.isEmpty() || line.equals("")))
  94. wordList.add(line);
  95. }
  96. in.close();
  97. }
  98.  
  99. public static ArrayList<String> getWords(boolean[] concatBits) {
  100. /*
  101. * Guide to get a word from bits, will have to be put in for loop to go
  102. * through whole boolean array:
  103. *
  104. * for (int j = 0; j < groupOfBits; ++j)
  105. *{
  106. * index <<= 1;
  107. * if(concatBits[(i * groupOfBits) + j])
  108. * index |= 0x1
  109. *}
  110. * words.add(wordList.get(index));
  111. *
  112. */
  113.  
  114. // replace null with result object
  115. return null;
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement