1
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 并让用户输入密码时,它会编译,但只打印出我输入的内容。它假设改变输入的密码以更改索引,而不是在解密时将其更改回来。以上是两个不同的类加密和驱动程序。任何帮助将不胜感激。

4

2 回答 2

3

如果您的密码短于 10,您encrypt()将按原样返回。

否则,它会遍历您的密码字符并执行以下操作:

passArray[i] = (char) (passArray[i]);

我认为很明显这条线没有效果。

于 2012-05-10T16:15:53.740 回答
1

在您的加密方法中,您为什么要这样做?

passArray[i] = (char) (passArray[i]);

你的意图是什么?(提示提示..)

于 2012-05-10T16:15:23.810 回答