style: format code (#4212)

close #4204
This commit is contained in:
acbin
2023-06-09 18:52:05 +08:00
committed by GitHub
parent ad03086f54
commit 00282efd8b
521 changed files with 5233 additions and 7309 deletions

View File

@@ -6,7 +6,8 @@ import java.util.BitSet;
public class A5Cipher {
private final A5KeyStreamGenerator keyStreamGenerator;
private static final int KEY_STREAM_LENGTH = 228; // 28.5 bytes so we need to pad bytes or something
private static final int KEY_STREAM_LENGTH
= 228; // 28.5 bytes so we need to pad bytes or something
public A5Cipher(BitSet sessionKey, BitSet frameCounter) {
keyStreamGenerator = new A5KeyStreamGenerator();

View File

@@ -9,7 +9,8 @@ public class A5KeyStreamGenerator extends CompositeLFSR {
private BitSet frameCounter;
private BitSet sessionKey;
private static final int INITIAL_CLOCKING_CYCLES = 100;
private static final int KEY_STREAM_LENGTH = 228; // 28.5 bytes so we need to pad bytes or something
private static final int KEY_STREAM_LENGTH
= 228; // 28.5 bytes so we need to pad bytes or something
@Override
public void initialize(BitSet sessionKey, BitSet frameCounter) {
@@ -17,9 +18,9 @@ public class A5KeyStreamGenerator extends CompositeLFSR {
this.frameCounter = (BitSet) frameCounter.clone();
this.initialFrameCounter = (BitSet) frameCounter.clone();
registers.clear();
LFSR lfsr1 = new LFSR(19, 8, new int[] { 13, 16, 17, 18 });
LFSR lfsr2 = new LFSR(22, 10, new int[] { 20, 21 });
LFSR lfsr3 = new LFSR(23, 10, new int[] { 7, 20, 21, 22 });
LFSR lfsr1 = new LFSR(19, 8, new int[] {13, 16, 17, 18});
LFSR lfsr2 = new LFSR(22, 10, new int[] {20, 21});
LFSR lfsr3 = new LFSR(23, 10, new int[] {7, 20, 21, 22});
registers.add(lfsr1);
registers.add(lfsr2);
registers.add(lfsr3);
@@ -31,11 +32,7 @@ public class A5KeyStreamGenerator extends CompositeLFSR {
}
public BitSet getNextKeyStream() {
for (
int cycle = 1;
cycle <= INITIAL_CLOCKING_CYCLES;
++cycle
) this.clock();
for (int cycle = 1; cycle <= INITIAL_CLOCKING_CYCLES; ++cycle) this.clock();
BitSet result = new BitSet(KEY_STREAM_LENGTH);
for (int cycle = 1; cycle <= KEY_STREAM_LENGTH; ++cycle) {

View File

@@ -29,12 +29,8 @@ public abstract class CompositeLFSR implements BaseLFSR {
bitCount.put(false, 0);
bitCount.put(true, 0);
registers.forEach(lfsr ->
bitCount.put(
lfsr.getClockBit(),
bitCount.get(lfsr.getClockBit()) + 1
)
);
registers.forEach(
lfsr -> bitCount.put(lfsr.getClockBit(), bitCount.get(lfsr.getClockBit()) + 1));
return bitCount.get(false) <= bitCount.get(true);
}
}

View File

@@ -1,8 +1,9 @@
package com.thealgorithms.ciphers.a5;
// Source http://www.java2s.com/example/java-utility-method/bitset/increment-bitset-bits-int-size-9fd84.html
//package com.java2s;
//License from project: Open Source License
// Source
// http://www.java2s.com/example/java-utility-method/bitset/increment-bitset-bits-int-size-9fd84.html
// package com.java2s;
// License from project: Open Source License
import java.util.BitSet;
@@ -11,7 +12,7 @@ public class Utils {
public static boolean increment(BitSet bits, int size) {
int i = size - 1;
while (i >= 0 && bits.get(i)) {
bits.set(i--, false);/*from w w w . j a v a 2s .c o m*/
bits.set(i--, false); /*from w w w . j a v a 2s .c o m*/
}
if (i < 0) {
return false;