Advertisement
Guest User

Untitled

a guest
Oct 25th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 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. int checkSum1 = bitEnt1Array.length/32;
  48. int checkSum2 = bitEnt2Array.length/32;
  49.  
  50. String bCheckSum1 = Integer.toBinaryString(checkSum1);
  51. String bCheckSum2 = Integer.toBinaryString(checkSum2);
  52.  
  53. String finalCheckSum1 = convertArrayToString(bitEnt1Array) + bCheckSum1;
  54. String finalCheckSum2 = convertArrayToString(bitEnt2Array) + bCheckSum2;
  55. //Methods begin here
  56.  
  57. int bitSize1 = finalCheckSum1.length/12;
  58.  
  59. int bitSize2 = finalCheckSum2.length/22;
  60.  
  61.  
  62.  
  63. // The final step is to take these concatenated bits and split
  64. // them into groups of bits. Each group encodes number
  65. // which is a position in a wordlist. We convert numbers into
  66. // words and use joined words as mnemonic sentence.
  67. // ArrayList<String> OutputWords = getWords(concatBits);
  68.  
  69. // Submit answer
  70. }
  71.  
  72. public static String convertArrayToString(boolean[] arr)
  73. {
  74. String result = "";
  75. for(Boolean b: arr)
  76. {
  77. if(b == true)
  78. result += 1;
  79. else
  80. result += 0;
  81. }
  82. }
  83.  
  84. public static boolean[] byteArray2BitArray(byte[] bytes)
  85. {
  86. boolean[] bits = new boolean[bytes.length * 8];
  87. for (int i = 0; i < bytes.length * 8; i++)
  88. {
  89. if ((bytes[i / 8] & (1 << (7 - (i % 8)))) > 0)
  90. bits[i] = true;
  91. }
  92. return bits;
  93. }
  94.  
  95. public static byte[] hashingEnt(String in) throws NoSuchAlgorithmException
  96. {
  97.  
  98. MessageDigest md = MessageDigest.getInstance("SHA-256");
  99. md.update(in.getBytes());
  100. byte byteData[] = md.digest();
  101. return byteData;
  102. }
  103.  
  104.  
  105.  
  106. public static void loadFiles() throws IOException
  107. {
  108.  
  109. Scanner in;
  110. String line;
  111.  
  112. in = new Scanner(wordListInput);
  113. while(in.hasNext())
  114. {
  115. line = in.nextLine();
  116. if(!(line.isEmpty() || line.equals("")))
  117. wordList.add(line);
  118. }
  119. in.close();
  120. }
  121.  
  122. public static ArrayList<String> getWords(boolean[] concatBits) {
  123. /*
  124. * Guide to get a word from bits, will have to be put in for loop to go
  125. * through whole boolean array:
  126. *
  127. * for (int j = 0; j < groupOfBits; ++j)
  128. *{
  129. * index <<= 1;
  130. * if(concatBits[(i * groupOfBits) + j])
  131. * index |= 0x1
  132. *}
  133. * words.add(wordList.get(index));
  134. *
  135. */
  136.  
  137. // replace null with result object
  138. return null;
  139. }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement