58 lines
1.9 KiB
Java
58 lines
1.9 KiB
Java
package io.rudefox.burrow;
|
|
|
|
import java.util.Scanner;
|
|
import java.util.regex.Pattern;
|
|
|
|
public class InteractiveBinaryEntropyGenerator extends InteractiveEntropyGenerator {
|
|
|
|
public InteractiveBinaryEntropyGenerator(int targetBitsOfEntropy, Scanner inputScanner, boolean ansiColorOutput) {
|
|
super(inputScanner, ansiColorOutput, targetBitsOfEntropy, 1);
|
|
}
|
|
|
|
@Override
|
|
protected String readNextEventSetString() {
|
|
|
|
String eventSetString = "";
|
|
Pattern eventSetPattern = Pattern.compile(String.format("[0-1]{%d}", eventsPerEventSet));
|
|
|
|
while (!eventSetPattern.matcher(eventSetString).matches()) {
|
|
System.out.print("Input 33 coin tosses [0-1]: ");
|
|
eventSetString = inputScanner.next();
|
|
}
|
|
|
|
return eventSetString;
|
|
}
|
|
|
|
@Override
|
|
protected String getEventValueFormatString(int eventIndexWithinSet) {
|
|
return "";
|
|
}
|
|
|
|
@Override
|
|
protected int toZeroBasedInteger(int eventDecimalValue) {
|
|
return eventDecimalValue;
|
|
}
|
|
|
|
@Override
|
|
protected void outputEventValuesLine(StringBuilder eventValuesLine) { }
|
|
|
|
@Override
|
|
protected StringBuilder getInitialBitsLine() {
|
|
return new StringBuilder("| ");
|
|
}
|
|
|
|
@Override
|
|
protected void padBitsLine(StringBuilder eventSetBitsLine, int bitIndexWithinEventSet, int bitIndexWithinEntropy) {
|
|
if (bitIndexWithinEventSet == BITS_PER_EVENT_SET - 1)
|
|
eventSetBitsLine.append(" |");
|
|
else if (bitIndexWithinEventSet % BITS_PER_WORD == 0 || bitIndexWithinEventSet % BITS_PER_WORD == 6)
|
|
eventSetBitsLine.append(styleBit(" ", bitIndexWithinEntropy, bitIndexWithinEventSet));
|
|
else if (bitIndexWithinEventSet % BITS_PER_WORD == BITS_PER_WORD - 1)
|
|
eventSetBitsLine.append(" | ");
|
|
}
|
|
|
|
@Override
|
|
protected String getSeedWordLineFormatString() {
|
|
return "|%-15s|%-15s|%-15s|";
|
|
}
|
|
} |