5
5
import java .util .Map ;
6
6
import java .util .TreeMap ;
7
7
8
+ /**
9
+ * The CompositeLFSR class represents a composite implementation of
10
+ * Linear Feedback Shift Registers (LFSRs) for cryptographic purposes.
11
+ *
12
+ * <p>
13
+ * This abstract class manages a collection of LFSR instances and
14
+ * provides a mechanism for irregular clocking based on the
15
+ * majority bit among the registers. It implements the BaseLFSR
16
+ * interface, requiring subclasses to define specific LFSR behaviors.
17
+ * </p>
18
+ */
8
19
public abstract class CompositeLFSR implements BaseLFSR {
9
20
10
21
protected final List <LFSR > registers = new ArrayList <>();
11
22
12
23
/**
13
- * Implements irregular clocking using the clock bit for each register
14
- * @return the registers discarded bit xored value
24
+ * Performs a clocking operation on the composite LFSR.
25
+ *
26
+ * <p>
27
+ * This method determines the majority bit across all registers and
28
+ * clocks each register based on its clock bit. If a register's
29
+ * clock bit matches the majority bit, it is clocked (shifted).
30
+ * The method also computes and returns the XOR of the last bits
31
+ * of all registers.
32
+ * </p>
33
+ *
34
+ * @return the XOR value of the last bits of all registers.
15
35
*/
16
36
@ Override
17
37
public boolean clock () {
@@ -26,6 +46,18 @@ public boolean clock() {
26
46
return result ;
27
47
}
28
48
49
+ /**
50
+ * Calculates the majority bit among all registers.
51
+ *
52
+ * <p>
53
+ * This private method counts the number of true and false clock bits
54
+ * across all LFSR registers. It returns true if the count of true
55
+ * bits is greater than or equal to the count of false bits; otherwise,
56
+ * it returns false.
57
+ * </p>
58
+ *
59
+ * @return true if the majority clock bits are true; false otherwise.
60
+ */
29
61
private boolean getMajorityBit () {
30
62
Map <Boolean , Integer > bitCount = new TreeMap <>();
31
63
bitCount .put (Boolean .FALSE , 0 );
0 commit comments