5 kyu

Coding with Squared Strings

71 of 2,129g964

Description:

A squared string has n lines, each substring being n characters long: For example:

s = "abcd\nefgh\nijkl\nmnop" is a squared string of size 4.

We will use squared strings to code and decode texts. To make things easier we suppose that our original text doesn't include the character '\n'.

Coding

Input:

  • a text t of length l.
  • Consider the smallest integer n such that n * n be greater or equal to l.
  • Complete t with the char of ascii code 11 (we suppose that this char is not in our original text) until the length of t is n * n.
  • From now on we can transform the new t in a squared string s of size n by inserting '\n' where needed.
  • Apply a clockwise rotation of 90 degrees to s: that's it for the coding part.

Decoding

Input:

  • a squared string s resulting from the coding
  • Apply a counter-clockwise rotation of 90 degrees to s
  • Do some cleaning to have the original text t

You can see clockwise rotation of 90 degrees: http://www.codewars.com/kata/56dbeec613c2f63be4000be6 You can see counter-clockwise rotation of 90 degrees: http://www.codewars.com/kata/56dbf59b0a10feb08c000227

Example:

t = "I.was.going.fishing.that.morning.at.ten.o'clock"

code(t) -> "c.nhsoI\nltiahi.\noentinw\ncng.nga\nk..mg.s\n\voao.f.\n\v'trtig"

decode(code(t)) == "I.was.going.fishing.that.morning.at.ten.o'clock"

(Dots indicate spaces since they are quite invisible).

Notes:

  • Swift : character 11 is replaced by "\u{F7}" (ie "÷" - alt 246 -)

  • Ocaml : character 11 is replaced by '&'

  • Perl : character 11 is replaced by '&'

  • Fortran: Your returned string for both functions are not permitted to contain redundant leading/trailing whitespace. In return, you may safely assume that all input strings passed into your function(s) will not contain redundant leading/trailing whitespace, i.e. you do not and should not trim the input string before operating on it

  • Don't use this coding to keep your secrets:-)

Fundamentals
Strings
Ciphers
Cryptography

Stats:

CreatedMar 31, 2016
PublishedMar 31, 2016
Warriors Trained16725
Total Skips6336
Total Code Submissions13986
Total Times Completed2129
Ruby Completions71
Python Completions575
JavaScript Completions301
Haskell Completions73
Clojure Completions33
Java Completions209
C# Completions140
CoffeeScript Completions10
PHP Completions84
C++ Completions224
Crystal Completions9
C Completions120
TypeScript Completions98
Swift Completions48
F# Completions22
OCaml Completions17
Fortran Completions5
Scala Completions34
Julia Completions18
R Completions24
Go Completions83
Nim Completions5
Racket Completions7
Rust Completions61
Perl Completions8
Erlang Completions6
Prolog Completions7
Total Stars302
% of votes with a positive feedback rating89% of 410
Total "Very Satisfied" Votes330
Total "Somewhat Satisfied" Votes69
Total "Not Satisfied" Votes11
Total Rank Assessments8
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • g964 Avatar
  • jhoffner Avatar
  • suic Avatar
  • donaldsebleung Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • Voile Avatar
  • monadius Avatar
  • hobovsky Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad