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[] passArray = password.toCharArray();
for (int i = 0; i < encrypt.length; i++) {
passArray[i] = (char) (passArray[i]);
}
return String.valueOf(passArray);
}
}
String decrypt (String password) {
if (password.length()<minLength) {
return password;
} else {
char[] arrayDecrypted = password.toCharArray();
for (int i = 0; i < arrayDecrypted.length; i++) {
arrayDecrypted[i] = (char) (arrayDecrypted[i]);
}
return String.valueOf(arrayDecrypted);
}
}
//------------------------------------------------ --------------------------
import csci130.*;
public class Driver {
public static void main(String args[]){
Encryption pass = new Encryption();
System.out.println("Please enter a password");
String name = KeyboardReader.readLine();
System.out.println("Encrypted Password: " + pass.encrypt(name));
System.out.println("Decrypted Password: " + pass.decrypt(name));
}
}
当我尝试调用我的方法 Encrypt and Decrypt 并让用户输入密码时,它会编译,但只打印出我输入的内容。它假设改变输入的密码以更改索引,而不是在解密时将其更改回来。以上是两个不同的类加密和驱动程序。任何帮助将不胜感激。