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

 

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

Given a plaintext String and an int modulus, find the ciphertext.


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
You will need to pluck characters out of the plaintext using an algorithm. Remember to loop back to the beginning at appropriate moments.

apcsaEncryptMod("012345678", 3) → "036147258"
apcsaEncryptMod("012345678", 2) → "024681357"
apcsaEncryptMod("0123456789", 4) → "0481592637"

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

public String apcsaEncryptMod(String plaintext, 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