1 Replies - 8341 Views - Last Post: 30 April 2012 - 06:50 AM Rate Topic: -----

#1 ssarp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-April 12

Ceasar Cipher problem

Posted 30 April 2012 - 05:40 AM

Hello! I've got this problem with the algorithm. It's ignoring the shift length from the input and return the very same letters. Can you help me because I can't see where my mistake is and I'm banging my head over this for couple of days.
public class CaeserCipher {

    private char[] CIPHERARRAY = new char[]{'A', 'B', 'C', 'D',
        'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
        'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

    public String encrypt(int shiftLength, String plainText) {
        String output = "";
        char[] plainTextToArray = plainText.toCharArray();

        for (int i = 0; i < plainTextToArray.length; i++) {
            for (int j = CIPHERARRAY.length; j > CIPHERARRAY[0] ; j--) {
                if (plainTextToArray[i] == CIPHERARRAY[j]) {
                 plainTextToArray[i]=CIPHERARRAY[(j+shiftLength)];
                }
            }
        }
        output = new String(plainTextToArray);
        JOptionPane.showMessageDialog(null, output);
        return output;
    }
}


Is This A Good Question/Topic? 0
  • +

Replies To: Ceasar Cipher problem

#2 farrell2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 874
  • View blog
  • Posts: 2,706
  • Joined: 29-July 11

Re: Ceasar Cipher problem

Posted 30 April 2012 - 06:50 AM

The best advice I can give you is to read pbl's tutorial here.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1