public class Decryption { public static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789"; private int shift; public Decryption(int shift) { this.shift = shift; } public String decrypt(String ciphertext) { String plaintext = ""; for (int i = 0; i < ciphertext.length(); i++) { char c = ciphertext.charAt(i); if (Character.isLetter(c) || Character.isDigit(c)) { // decrypt character c int index = ALPHABET.indexOf(c); int shiftedIndex = ((index - this.shift) % ALPHABET.length() + ALPHABET.length()) % ALPHABET.length(); c = ALPHABET.charAt(shiftedIndex); } plaintext += c updateShift(ciphertext.charAt(i)); } return plaintext; } private void updateShift(char c) { String previousCipher = "" + c + this.shift; int hash = previousCipher.hashCode(); this.shift = Math.abs(hash) % ALPHABET.length(); } }