Skip to content

Edit README to clarify exercise instructions (crypto-square) #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 34 additions & 38 deletions crypto-square.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
The input is first normalized: The spaces and punctuation are removed
Write a program that, given an English text, outputs the encoded version
of that text.

First, the input is normalized: the spaces and punctuation are removed
from the English text and the message is downcased.

Then, the normalized characters are broken into rows. These rows can be
regarded as forming a rectangle when printed with intervening newlines.

For example, the sentence

> If man was meant to stay on the ground god would have given us roots
> If man was meant to stay on the ground, god would have given us roots.

is 54 characters long.
is normalized to:

Broken into 8-character columns, it yields 7 rows.
> ifmanwasmeanttostayonthegroundgodwouldhavegivenusroots

Those 7 rows produce this rectangle when printed one per line:
The plaintext should be organized in to a rectangle. The size of the
rectangle (`r x c`) should be decided by the length of the message,
such that `c >= r` and `c - r <= 1`, where `c` is the number of columns
and `r` is the number of rows.

Our normalized text is 54 characters long, dictating a rectangle with
`c = 8` and `r = 7`:

```plain
ifmanwas
Expand All @@ -27,43 +36,30 @@ sroots
The coded message is obtained by reading down the columns going left to
right.

For example, the message above is coded as:
The message above is coded as:

```plain
imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau
imtgdvsfearwermayoogoanouuiontnnlvtwttddesaohghnsseoau
```

Write a program that, given an English text, outputs the encoded version
of that text.

The size of the square (number of columns) should be decided by the
length of the message.

If the message is a length that creates a perfect square (e.g. 4, 9, 16,
25, 36, etc), use that number of columns.
Output the encoded text in chunks. Phrases that fill perfect squares
`(r X r)` should be output in `r`-length chunks separated by spaces.
Imperfect squares will have `n` empty spaces. Those spaces should be distributed evenly across the last `n` rows.

If the message doesn't fit neatly into a square, choose the number of
columns that corresponds to the smallest square that is larger than the
number of characters in the message.

For example, a message 4 characters long should use a 2 x 2 square. A
message that is 81 characters long would use a square that is 9 columns
wide.

A message between 5 and 8 characters long should use a rectangle 3
characters wide.

Output the encoded text grouped by column.
```plain
imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau
```

For example:
Notice that were we to stack these, we could visually decode the
cyphertext back in to the original message:

- "Have a nice day. Feed the dog & chill out!"
- Normalizes to: "haveanicedayfeedthedogchillout"
- Which has length: 30
- And splits into 5 6-character rows:
- "havean"
- "iceday"
- "feedth"
- "edogch"
- "illout"
- Which yields a ciphertext beginning: "hifei acedl v…"
```plain
imtgdvs
fearwer
mayoogo
anouuio
ntnnlvt
wttddes
aohghn
sseoau
```