Wangagat
Wangagat

Reputation: 95

Java Transposition cipher encrypt/decrypt

I'm trying to get my transposition cipher to work.

Whenever I input the resulting cipher text of the encryption method into the decryption method, I should get back the original plain text... but that is not the case...

what am I doing wrong?

thanks for the help!

public String EncryptTranspositionCipher(){
    String outputstring = "";


    for(int j=0;j<key;j++){
       for(int i=j;i<plainText.length();i+=key){
           outputstring += plainText.charAt(i);
       }
    }
    return outputstring;
 }
 public String DecryptTranspositionCipher(){
      String outputstring = "";
      int stepforDec=0;
      stepforDec= plainText.length() / key;
      for(int j=0;j<stepforDec;j++){
         for(int i=j;i<plainText.length();i+=stepforDec){
             outputstring += plainText.charAt(i);
         }
      }
      return output string; }

Upvotes: 1

Views: 7083

Answers (1)

rossum
rossum

Reputation: 15693

Look at your DecryptTranspositionCipher() method. Where does it find the cyphertext you want it to decode? Perhaps you might do better with something like:

 public String DecryptTranspositionCipher(String cyphertext){ ... }

Upvotes: 1

Related Questions