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

 

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

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).
HINT
Here, 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)

public String apcsaDecryptMod(String ciphertext, int modulus) { }

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: 220

Copyright Nick Parlante 2017 - privacy