Skip to content

Commit ee6cd64

Browse files
Hardvanalxkm
andauthored
Strengthen class & function documentation in CompositeLFSR.java (TheAlgorithms#5596)
Co-authored-by: Alex Klymenko <alexanderklmn@gmail.com>
1 parent afc06d5 commit ee6cd64

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/main/java/com/thealgorithms/ciphers/a5/CompositeLFSR.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,33 @@
55
import java.util.Map;
66
import java.util.TreeMap;
77

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+
*/
819
public abstract class CompositeLFSR implements BaseLFSR {
920

1021
protected final List<LFSR> registers = new ArrayList<>();
1122

1223
/**
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.
1535
*/
1636
@Override
1737
public boolean clock() {
@@ -26,6 +46,18 @@ public boolean clock() {
2646
return result;
2747
}
2848

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+
*/
2961
private boolean getMajorityBit() {
3062
Map<Boolean, Integer> bitCount = new TreeMap<>();
3163
bitCount.put(Boolean.FALSE, 0);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy