Class CaesarCipher

java.lang.Object
com.zybooks.dsaj.fundamental.CaesarCipher

public class CaesarCipher extends Object
Class for doing encryption and decryption using the Caesar Cipher.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected char[]
     
    protected char[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    CaesarCipher(int rotation)
    Constructor that initializes the encryption and decryption arrays.
  • Method Summary

    Modifier and Type
    Method
    Description
    decrypt(String secret)
    Returns a decrypted message, given the encrypted secret.
    encrypt(String message)
    Returns an encrypted version of an original message.
    static void
    main(String[] args)
    Simple main method for testing the Caesar cipher

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • encoder

      protected char[] encoder
    • decoder

      protected char[] decoder
  • Constructor Details

    • CaesarCipher

      public CaesarCipher(int rotation)
      Constructor that initializes the encryption and decryption arrays.
      Parameters:
      rotation - the amount of forward shift
  • Method Details

    • encrypt

      public String encrypt(String message)
      Returns an encrypted version of an original message.
      Parameters:
      message - the original message
      Returns:
      the encrypted message
    • decrypt

      public String decrypt(String secret)
      Returns a decrypted message, given the encrypted secret.
      Parameters:
      secret - the encrypted message
      Returns:
      the original (unencrypted) message
    • main

      public static void main(String[] args)
      Simple main method for testing the Caesar cipher