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

 

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

Given a String plaintext and a keyword of length n, arrange the plaintext into rows of length n. Then, the plaintext columns are re-arranged into the alphabetical order of the letters in the key. The output is created by going down the resequenced columns, one character at a time. Read a far more complete description on this page:


https://en.wikipedia.org/wiki/Transposition_cipher#Columnar_transposition

Note that this is the irregular version with no "filler" letters to complete the rectangle if it is not completely filled.  It is quite possible that the last row of plaintext, therefore, will be a different length than the other rows.  Having unequal length rows also makes for an additional challenge writing the columns into the output.

The first test case uses only letters for plaintext and key, but actually, in theory, this cipher can function with any visible characters.

apcsaEncryptColumnarCipher("WEAREDISCOVEREDFLEEATONCE", "ZEBRAS") → "EVLNACDTESEAROFODEECWIREE"
apcsaEncryptColumnarCipher("WEAREDISCOVEREDFLEEATONCE", "FCBDAE") → "EVLNACDTESEAROFODEECWIREE"
apcsaEncryptColumnarCipher("WEAREDISCOVEREDFLEEATONCE", "521304") → "EVLNACDTESEAROFODEECWIREE"

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

public String apcsaEncryptColumnarCipher(String plaintext, String key) { }

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