Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.aciw.foobar.mnemonic;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import java.util.ArrayList;
- import java.util.*;
- import java.io.*;
- import com.aciw.foobar.utility.RESTClient;
- /**
- *
- * @author Administrator
- *
- */
- public class App {
- private static final String username = "<enter_username_here>";
- private static final String password = "<enter_password_here>";
- // Inputs for set1 (Ent1) and the bonus set (Ent2)
- private static final String Ent1 = "7f7f7f7f7f7f7f7f";
- private static final String Ent2 = "7f7f7f7f7f7f7f7e";
- public static ArrayList<String> wordList = new ArrayList<String>();
- public static File wordListInput = new File("./files/1/Word_List_Input_Set_1.txt");
- // This skeleton is convert a single entropy to a mnemonic sentence.
- // You must modify the code to convert 2 entropys to mnemonic sentences.
- public static void main(String[] args) throws IOException, NoSuchAlgorithmException {
- RESTClient.setUsername(username);
- RESTClient.setPassword(password);
- // Insert Code here...
- byte[] ent1Array = Ent1.getBytes("UTF-8");
- byte[] ent2Array = Ent2.getBytes("UTF-8");
- byte[] hashEnt1Array = hashingEnt(Ent1);
- byte[] hashEnt2Array = hashingEnt(Ent2);
- boolean[] bitEnt1Array = byteArray2BitArray(ent1Array);
- boolean[] bitHashEnt1Array = byteArray2BitArray(hashEnt1Array);
- boolean[] bitEnt2Array = byteArray2BitArray(ent2Array);
- boolean[] bitHashEnt2Array = byteArray2BitArray(hashEnt2Array);
- //Methods begin here
- // The final step is to take these concatenated bits and split
- // them into groups of bits. Each group encodes number
- // which is a position in a wordlist. We convert numbers into
- // words and use joined words as mnemonic sentence.
- // ArrayList<String> OutputWords = getWords(concatBits);
- // Submit answer
- }
- public static boolean[] byteArray2BitArray(byte[] bytes)
- {
- boolean[] bits = new boolean[bytes.length * 8];
- for (int i = 0; i < bytes.length * 8; i++)
- {
- if ((bytes[i / 8] & (1 << (7 - (i % 8)))) > 0)
- bits[i] = true;
- }
- return bits;
- }
- public static byte[] hashingEnt(String in) throws NoSuchAlgorithmException
- {
- MessageDigest md = MessageDigest.getInstance("SHA-256");
- md.update(in.getBytes());
- byte byteData[] = md.digest();
- return byteData;
- }
- public static void loadFiles() throws IOException
- {
- Scanner in;
- String line;
- in = new Scanner(wordListInput);
- while(in.hasNext())
- {
- line = in.nextLine();
- if(!(line.isEmpty() || line.equals("")))
- wordList.add(line);
- }
- in.close();
- }
- public static ArrayList<String> getWords(boolean[] concatBits) {
- /*
- * Guide to get a word from bits, will have to be put in for loop to go
- * through whole boolean array:
- *
- * for (int j = 0; j < groupOfBits; ++j)
- *{
- * index <<= 1;
- * if(concatBits[(i * groupOfBits) + j])
- * index |= 0x1
- *}
- * words.add(wordList.get(index));
- *
- */
- // replace null with result object
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement