替换密码

时间:2012-12-04 00:11:30

标签: java substitution encryption

我正在开发一个替换密码的程序,它希望我向用户询问包含密码文本和纯文本的密钥的文件,并向用户询问包含他们想要使用的消息的文本文件在询问他们是否想要加密或解密之前。

我已经完成了很多程序,但是我无法将关键文本文件读入ArrayList。

我的测试密钥的文本文件是: ZA YB XC WD VE UF TG SH RI QJ PK OL NM MN LO KP JQ IR HS GT FU EV DW CX 通过 AZ

我的流程代码是:

public class Process{

public static void main(String[] args){

   ArrayList<Key> key = new ArrayList<Key>();
   String choice;
   String cipher;
   String plain;


   Scanner scan = new Scanner(System.in);


   //asks user for file name with cipher key
   System.out.print("Enter a file name containing your key: ");
   String fileName = scan.next();



   // ask user to encrypt or decrypt using the key
   System.out.print("Would you like to encrypt or decrypt? ");
   choice = scan.next();

   // ask for name of file containing message
   System.out.println("Enter a file name containing your message: ");  
   String fileName2 = scan.next();

   //perform the appropriate substitution on the message
   if (choice.equals("encrypt"))
   {

   }

   else if (choice.equals("decrypt"))
   {

   }

   //display both text and cipher
   for(Key ke : key)
   System.out.println(ke.getCipher() + "\n" + ke.getPlain());

   }
}

关键课程:

public class Key {
  //instance variables
   String cipher;
   String plain;



public Key(String cipher, String plain) {
 this.cipher = cipher;
 this.plain = plain;
}
 /**
 * getCipher - returns cipher
 * 
 * @return     cipher
 */

  public String getCipher() {
     return cipher;
 }
 /**
 * setCipher - updates cipher name
 * 
 * @param  newCipher   new value of cipher 
 */

  public void setCipher(String newCipher) {
      cipher = cipher;
  }
  /**
 * getPlain - returns plain
 * 
 * @return     plain
 */

  public String getPlain(){
      return plain;
  }
  /**
 * setPlain - updates plain name
 * 
 * @param  newPlain   new value of plain 
 */

  public void setPlain(String newPlain){
      plain = plain;
  }
  /**
 * toString - returns contents of object
 * 
 * @return    result
 */

  public String toString() {
      String result;
      result ="Ciphered text = " + cipher;
      result +="Plain text = " + plain;
      return result;
    }}

0 个答案:

没有答案