https://github.com/bronzdoc/crypto-square
Solution for the crypto-square exercism
https://github.com/bronzdoc/crypto-square
Last synced: 7 months ago
JSON representation
Solution for the crypto-square exercism
- Host: GitHub
- URL: https://github.com/bronzdoc/crypto-square
- Owner: bronzdoc
- Created: 2016-05-08T00:54:54.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-08T03:46:13.000Z (about 10 years ago)
- Last Synced: 2025-02-18T06:42:41.662Z (over 1 year ago)
- Language: Ruby
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Crypto Square
Implement the classic method for composing secret messages called a square code.
The input is first 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
is 54 characters long.
Broken into 8-character columns, it yields 7 rows.
Those 7 rows produce this rectangle when printed one per line:
```plain
ifmanwas
meanttos
tayonthe
groundgo
dwouldha
vegivenu
sroots
```
The coded message is obtained by reading down the columns going left to
right.
For example, the message above is coded as:
```plain
imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau
```
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.
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.
For example:
- "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…"
* * * *
For installation and learning resources, refer to the
[exercism help page](http://exercism.io/languages/ruby).
For running the tests provided, you will need the Minitest gem. Open a
terminal window and run the following command to install minitest:
gem install minitest
If you would like color output, you can `require 'minitest/pride'` in
the test file, or note the alternative instruction, below, for running
the test file.
In order to run the test, you can run the test file from the exercise
directory. For example, if the test suite is called
`hello_world_test.rb`, you can run the following command:
ruby hello_world_test.rb
To include color from the command line:
ruby -rminitest/pride hello_world_test.rb
The test files may have the execution bit set so you may also be able to
run it like this:
./hello_world_test.rb
## Source
J Dalbey's Programming Practice problems [http://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html](http://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html)