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并让用户键入密码时,它会编译,但只打印出我输入的内容。它假设置换输入的密码更改索引,然后在解密时更改密码。以上是两个不同的类加密&amp;驱动程序。任何帮助将不胜感激。
答案 0 :(得分:3)
如果您的密码短于10,则encrypt()
会按原样返回。
否则它会迭代您的密码字符并执行以下操作:
passArray[i] = (char) (passArray[i]);
我认为很明显这条线没有效果。
答案 1 :(得分:1)
在您的加密方法中,为什么要这样做?
passArray[i] = (char) (passArray[i]);
你的意图是什么? (提示......暗示..)