Advertisement
Guest User

Untitled

a guest
Oct 25th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.90 KB | None | 0 0
  1.  
  2. import java.security.MessageDigest;
  3. import java.security.NoSuchAlgorithmException;
  4. import java.util.*;
  5. import java.io.*;
  6.  
  7. //import com.aciw.foobar.utility.RESTClient;
  8.  
  9. /**
  10. *
  11. * @author Administrator
  12. *
  13. */
  14. public class test {
  15. private static final String username = "Team Break";
  16. private static final String password = "E7WBVI3";
  17.  
  18. // Inputs for set1 (Ent1) and the bonus set (Ent2)
  19. private static final String Ent1 = "7f7f7f7f7f7f7f7f";
  20. private static final String Ent2 = "7f7f7f7f7f7f7f7e";
  21.  
  22.  
  23. public static ArrayList<String> wordList = new ArrayList<String>();
  24.  
  25. //public static File wordListInput = new File("./files/1/Word_List_Input_Set_1.txt");
  26.  
  27. // This skeleton is convert a single entropy to a mnemonic sentence.
  28. // You must modify the code to convert 2 entropys to mnemonic sentences.
  29. public static void main(String[] args) throws IOException, NoSuchAlgorithmException {
  30.  
  31. //RESTClient.setUsername(username);
  32. //RESTClient.setPassword(password);
  33.  
  34. // Insert Code here...
  35. //loadFiles();
  36.  
  37. byte[] ent1Array = Ent1.getBytes("UTF-8");
  38. byte[] ent2Array = Ent2.getBytes("UTF-8");
  39. byte[] hashEnt1Array = hashingEnt(Ent1);
  40. byte[] hashEnt2Array = hashingEnt(Ent2);
  41. boolean[] bitEnt1Array = byteArray2BitArray(ent1Array);
  42. boolean[] bitHashEnt1Array = byteArray2BitArray(hashEnt1Array);
  43. boolean[] bitEnt2Array = byteArray2BitArray(ent2Array);
  44. boolean[] bitHashEnt2Array = byteArray2BitArray(hashEnt2Array);
  45.  
  46. int checkSum1 = bitEnt1Array.length/32;
  47. int checkSum2 = bitEnt2Array.length/32;
  48.  
  49. String bCheckSum1 = Integer.toBinaryString(checkSum1);
  50. String bCheckSum2 = Integer.toBinaryString(checkSum2);
  51.  
  52. String finalCheckSum1 = convertArrayToString(bitEnt1Array) + bCheckSum1;
  53. String finalCheckSum2 = convertArrayToString(bitEnt2Array) + bCheckSum2;
  54. //Methods begin here
  55.  
  56. System.out.println("length1: " +finalCheckSum1.length());
  57. System.out.println("length2: " +finalCheckSum2.length());
  58.  
  59. int bitSize1 = (finalCheckSum1.length())/12;
  60.  
  61. int bitSize2 = (finalCheckSum2.length())/22;
  62.  
  63. System.out.println("bitsize1: " +bitSize1);
  64. System.out.println("bitsize2: " +bitSize2);
  65.  
  66. ArrayList<Integer> indeces1 = new ArrayList<Integer>();
  67. ArrayList<Integer> indeces2 = new ArrayList<Integer>();
  68.  
  69. ArrayList<String> output1 = new ArrayList<String>();
  70. ArrayList<String> output2 = new ArrayList<String>();
  71.  
  72. for(int i = 0, j = bitSize2; i < finalCheckSum2.length()-1;)
  73. {
  74. indeces2.add(convertThing(finalCheckSum2.substring(i, j)));
  75. i = j;
  76. j += bitSize2;
  77. }
  78.  
  79. for(int i = 0, j = bitSize1; i < finalCheckSum1.length()-1;)
  80. {
  81.  
  82. indeces1.add(convertThing(finalCheckSum1.substring(i, j)));
  83. i = j;
  84. j += bitSize1;
  85. }
  86.  
  87. System.out.println(indeces1);
  88. System.out.println(indeces2);
  89.  
  90. for(Integer index : indeces1)
  91. output1.add(wordList.get(index));
  92. for(Integer index : indeces2)
  93. output2.add(wordList.get(index));
  94.  
  95.  
  96.  
  97. // The final step is to take these concatenated bits and split
  98. // them into groups of bits. Each group encodes number
  99. // which is a position in a wordlist. We convert numbers into
  100. // words and use joined words as mnemonic sentence.
  101. // ArrayList<String> OutputWords = getWords(concatBits);
  102.  
  103. // Submit answer
  104. //RESTClient.sendOutput(output1,1);
  105. //RESTClient.sendOutput(output2,2);
  106. }
  107.  
  108. public static int convertThing(String s)
  109. {
  110. int sum = 0;
  111.  
  112. for(int x = 0; x < s.length(); x++)
  113. {
  114. sum += Math.pow(2 * Integer.parseInt(s.charAt(x) + "") , x);
  115. }
  116. System.out.println(sum);
  117.  
  118. return sum;
  119. }
  120.  
  121. public static String convertArrayToString(boolean[] arr)
  122. {
  123. String result = "";
  124. for(Boolean b: arr)
  125. {
  126. if(b == true)
  127. result += 1;
  128. else
  129. result += 0;
  130. }
  131.  
  132. return result;
  133. }
  134.  
  135. public static boolean[] byteArray2BitArray(byte[] bytes)
  136. {
  137. boolean[] bits = new boolean[bytes.length * 8];
  138. for (int i = 0; i < bytes.length * 8; i++)
  139. {
  140. if ((bytes[i / 8] & (1 << (7 - (i % 8)))) > 0)
  141. bits[i] = true;
  142. else
  143. bits[i] = false;
  144.  
  145. }
  146. return bits;
  147. }
  148.  
  149. public static byte[] hashingEnt(String in) throws NoSuchAlgorithmException
  150. {
  151.  
  152. MessageDigest md = MessageDigest.getInstance("SHA-256");
  153. md.update(in.getBytes());
  154. byte byteData[] = md.digest();
  155. return byteData;
  156. }
  157.  
  158.  
  159.  
  160. /*public static void loadFiles() throws IOException
  161. {
  162.  
  163. Scanner in;
  164. String line;
  165.  
  166. in = new Scanner(wordListInput);
  167. while(in.hasNext())
  168. {
  169. line = in.nextLine();
  170. if(!(line.isEmpty() || line.equals("")))
  171. wordList.add(line);
  172. }
  173. in.close();
  174. }*/
  175.  
  176. public static ArrayList<String> getWords(boolean[] concatBits) {
  177. /*
  178. * Guide to get a word from bits, will have to be put in for loop to go
  179. * through whole boolean array:
  180. *
  181. * for (int j = 0; j < groupOfBits; ++j)
  182. *{
  183. * index <<= 1;
  184. * if(concatBits[(i * groupOfBits) + j])
  185. * index |= 0x1
  186. *}
  187. * words.add(wordList.get(index));
  188. *
  189. */
  190.  
  191. // replace null with result object
  192. return null;
  193. }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement