public class Encryption {
private static final int[] encrypt = {2, 9, 3, 4, 6, 8, 1, 0};
private static final int[] decrypt = new int[8];
private static final int minLength = 10;
String encrypt (String password) {
if(password.length()<minLength) {
return password;
} else {
char[] encrypt = password.toCharArray();
for (int i = 0; i < encrypt.length; i++) {
encrypt[i] = (char) (encrypt[i]);
}
return String.valueOf(encrypt);
}
}
String decrypt (String password) {
if (password.length()<minLength) {
return password;
} else {
char[] decrypt = password.toCharArray();
for (int i = 0; i < decrypt.length; i++) {
decrypt[i] = (char) (decrypt[i]);
}
return String.valueOf(decrypt);
}
}
boolean isValidLength (String password) {
if (password.length()<minLength) {
return true;
} else {
return false;
}
}
int getMinLength(){
return minLength;
}
}
Suppose to encrypt my password (Driver hasn’t been made yet), but not sure if I used my variables (encrypt and decrypt) correctly. The Encrypt and Decrypt variables are so that the password changes index’s to whatever the user types in, and also don’t know, but am suppose to use the inverse purmutation method somewhere, but not sure where? Any help? Need someone to tell me if my program is way off, or is close.
The warning — which is a good warning — is because of shadowing
The line:
Causes the [static] member variable [which is also] called
encryptto be shadowed within that method. Thus the “permutation values” are never used and the algorithm used will horribly break. (It will break horribly because the “permutation values” are not the same on encrypt and decrypt. There is another issue with the decrypt algorithm, as it doest even use the [same] “permutation values”, but that’s another thing to work through.)Solutions:
encryptionKeyfor the permutations).Encryption.encryptto refer to the [static] member variable.And, of course, review the algorithm. There is no need for
Encryption.decryptand keeping it there will allow other errors to be introduced.Happy coding.