id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

orion.a.smith@gmail.com apcsa-encryption > apcsaEncryptHomophonicCipher
prev  |  next  |  chance

Given an input String and an ArrayList of 26 key Strings, encrypt the letters in the plaintext using the 26 keys as substitutions. For each letter, start by finding the corresponding position in the ArrayList ('A' is 0, 'B' is 1, ..., 'Z' is 25) to determine which key to use, and the first time the plaintext letter occurs use the first index of that key. Each successive time the letter is used, go to the next index in that key. Suppose the key string for 'A' is "JKQ". The first time the letter 'A' is found in the plaintext it maps to 'J', then the second 'A' becomes 'K' and the third 'A' becomes 'Q'. The fourth 'A' wraps back around to the beginning of the key and becomes 'J'.


Precondition: The input String will be made of uppercase letters and spaces only - spaces should be preserved in the ciphertext.
HINT
You are going to need to keep track of a large number of index values. Perhaps it would be helpful to keep them organized, somehow?

apcsaEncryptHomophonicCipher("YAAAAAAAAAAAAAS QUEEN", ["0123456789", "b", "c", "d", "AB", "f", "g", "h", "i", "j", "k", "l", "m", "!", "o", "p", "*", "r", "=", "t", "?", "v", "w", "x", "+", "z"]) → "+0123456789012= *?AB!"
apcsaEncryptHomophonicCipher("HEHEHEHEHEHE", ["a", "b", "c", "d", "012345", "f", "g", "6789h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]) → "60718293h465"
apcsaEncryptHomophonicCipher("WHEEEEEEEEEEEEEEE", ["Z.", "+2n", "u}>E", "M", "m!", "{c7:P", "D", "C1|ep", "L_", "$%3w", "Wd)", "o", "&(<", "v", "94YU", "=Bh", "5Ix8", "y", "6", "XaR*", "#jF[", "sAkz", "0b,;", "i", "O", "TJ"]) → "0Cm!m!m!m!m!m!m!m"

...Save, Compile, Run (ctrl-enter)

public String apcsaEncryptHomophonicCipher(String str, ArrayList<String> keys) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 330

Copyright Nick Parlante 2017 - privacy