about | help | code help+videos | done | prefs |
(MEDIUM) Given a ciphertext String and an int modulus, recover the original plaintext. The modulus transposition scheme is described as follows: Re-arrange the characters in the String so that all the index positions with the same remainder are clustered together in sequence. For example, the plaintext "012345678" with modulus 3 becomes "036147258" - 0, 3 and 6 all have remainder 0 when divided by 3 but 0 comes before 3. 1 , 4 and 7 all have remainder 1 and so on. If the plaintext input does not have a length evenly divided by the modulus, use the available characters in the same sequence but do not add any garbage characters to the end, when you have run out of plaintext characters to reposition. Thus, the plaintext "01234" with modulus 3 is transformed into "03142" (same length as the original).HINTHere, you have to build your output out of sequence. Really you are just reversing the direction of a position-mapping algorithm (position in plaintext becomes a new position in the ciphertext) from the encryption method. What would be a good data structure to use to build a String out of sequence, given that you already know how long it needs to be? apcsaDecryptMod("036147258", 3) → "012345678" apcsaDecryptMod("024681357", 2) → "012345678" apcsaDecryptMod("0481592637", 4) → "0123456789" ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 220
Copyright Nick Parlante 2017 - privacy