mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-23 04:20:16 +08:00
style: enable LocalVariableName
in CheckStyle (#5191)
* style: enable LocalVariableName in checkstyle * Removed minor bug * Resolved Method Name Bug * Changed names according to suggestions
This commit is contained in:
@ -27,7 +27,7 @@ final class AffineCipher {
|
||||
|
||||
static String decryptCipher(String cipher) {
|
||||
String msg = "";
|
||||
int a_inv = 0;
|
||||
int aInv = 0;
|
||||
int flag = 0;
|
||||
|
||||
// Find a^-1 (the multiplicative inverse of a
|
||||
@ -38,7 +38,7 @@ final class AffineCipher {
|
||||
// Check if (a*i)%26 == 1,
|
||||
// then i will be the multiplicative inverse of a
|
||||
if (flag == 1) {
|
||||
a_inv = i;
|
||||
aInv = i;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < cipher.length(); i++) {
|
||||
@ -46,7 +46,7 @@ final class AffineCipher {
|
||||
{here x is cipher[i] and m is 26} and added 'A'
|
||||
to bring it in range of ASCII alphabet[ 65-90 | A-Z ] */
|
||||
if (cipher.charAt(i) != ' ') {
|
||||
msg = msg + (char) (((a_inv * ((cipher.charAt(i) + 'A' - b)) % 26)) + 'A');
|
||||
msg = msg + (char) (((aInv * ((cipher.charAt(i) + 'A' - b)) % 26)) + 'A');
|
||||
} else { // else simply append space character
|
||||
msg += cipher.charAt(i);
|
||||
}
|
||||
|
@ -81,16 +81,16 @@ public class DES {
|
||||
}
|
||||
String[] subKeys = new String[16];
|
||||
String initialPermutedKey = permutedKey.toString();
|
||||
String C0 = initialPermutedKey.substring(0, 28);
|
||||
String D0 = initialPermutedKey.substring(28);
|
||||
String c0 = initialPermutedKey.substring(0, 28);
|
||||
String d0 = initialPermutedKey.substring(28);
|
||||
|
||||
// We will now operate on the left and right halves of the permutedKey
|
||||
for (i = 0; i < 16; i++) {
|
||||
String Cn = C0.substring(KEY_SHIFTS[i]) + C0.substring(0, KEY_SHIFTS[i]);
|
||||
String Dn = D0.substring(KEY_SHIFTS[i]) + D0.substring(0, KEY_SHIFTS[i]);
|
||||
subKeys[i] = Cn + Dn;
|
||||
C0 = Cn; // Re-assign the values to create running permutation
|
||||
D0 = Dn;
|
||||
String cN = c0.substring(KEY_SHIFTS[i]) + c0.substring(0, KEY_SHIFTS[i]);
|
||||
String dN = d0.substring(KEY_SHIFTS[i]) + d0.substring(0, KEY_SHIFTS[i]);
|
||||
subKeys[i] = cN + dN;
|
||||
c0 = cN; // Re-assign the values to create running permutation
|
||||
d0 = dN;
|
||||
}
|
||||
|
||||
// Let us shrink the keys to 48 bits (well, characters here) using pc2
|
||||
@ -169,18 +169,18 @@ public class DES {
|
||||
for (i = 0; i < 64; i++) {
|
||||
permutedMessage.append(message.charAt(IP[i] - 1));
|
||||
}
|
||||
String L0 = permutedMessage.substring(0, 32);
|
||||
String R0 = permutedMessage.substring(32);
|
||||
String e0 = permutedMessage.substring(0, 32);
|
||||
String f0 = permutedMessage.substring(32);
|
||||
|
||||
// Iterate 16 times
|
||||
for (i = 0; i < 16; i++) {
|
||||
String Ln = R0; // Previous Right block
|
||||
String Rn = xOR(L0, feistel(R0, keys[i]));
|
||||
L0 = Ln;
|
||||
R0 = Rn;
|
||||
String eN = f0; // Previous Right block
|
||||
String fN = xOR(e0, feistel(f0, keys[i]));
|
||||
e0 = eN;
|
||||
f0 = fN;
|
||||
}
|
||||
|
||||
String combinedBlock = R0 + L0; // Reverse the 16th block
|
||||
String combinedBlock = f0 + e0; // Reverse the 16th block
|
||||
permutedMessage.setLength(0);
|
||||
for (i = 0; i < 64; i++) {
|
||||
permutedMessage.append(combinedBlock.charAt(IP_INVERSE[i] - 1));
|
||||
|
@ -35,7 +35,7 @@ public final class HillCipher {
|
||||
validateDeterminant(keyMatrix, matrixSize);
|
||||
|
||||
int[][] messageVector = new int[matrixSize][1];
|
||||
String CipherText = "";
|
||||
String cipherText = "";
|
||||
int[][] cipherMatrix = new int[matrixSize][1];
|
||||
int j = 0;
|
||||
while (j < message.length()) {
|
||||
@ -60,10 +60,10 @@ public final class HillCipher {
|
||||
cipherMatrix[i][0] = cipherMatrix[i][0] % 26;
|
||||
}
|
||||
for (i = 0; i < matrixSize; i++) {
|
||||
CipherText += (char) (cipherMatrix[i][0] + 65);
|
||||
cipherText += (char) (cipherMatrix[i][0] + 65);
|
||||
}
|
||||
}
|
||||
System.out.println("Ciphertext: " + CipherText);
|
||||
System.out.println("Ciphertext: " + cipherText);
|
||||
}
|
||||
|
||||
// Following function decrypts a message
|
||||
@ -84,7 +84,7 @@ public final class HillCipher {
|
||||
|
||||
// solving for the required plaintext message
|
||||
int[][] messageVector = new int[n][1];
|
||||
String PlainText = "";
|
||||
String plainText = "";
|
||||
int[][] plainMatrix = new int[n][1];
|
||||
int j = 0;
|
||||
while (j < message.length()) {
|
||||
@ -109,10 +109,10 @@ public final class HillCipher {
|
||||
plainMatrix[i][0] = plainMatrix[i][0] % 26;
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
PlainText += (char) (plainMatrix[i][0] + 65);
|
||||
plainText += (char) (plainMatrix[i][0] + 65);
|
||||
}
|
||||
}
|
||||
System.out.println("Plaintext: " + PlainText);
|
||||
System.out.println("Plaintext: " + plainText);
|
||||
}
|
||||
|
||||
// Determinant calculator
|
||||
|
Reference in New Issue
Block a user