The Test Flight Kata

Hello and welcome to this programming kata.

This kata consists of several parts where you have to solve one part before the next is revealed, kinda like some sort of advent calendar that you might have heard of.

While you could speed through this kata by just solving the problems as quickly as possible, the intention of this kata is to practice Test Driven Development and as such you're recommended to think about this as production code and write proper tests for your implementation.

Where appropriate, an example will be shown to better explain the problem. These examples are perfect for an initial test case. I do recommend that you write more tests than just based on the example though, the aim, after all, is to drive development by passing tests.

Good luck!
/Raniz

Beep, beep, beep.

The autopilot on the StarCruiser X MK. 1b - the latest prototype luxury space yacht you're testing - is requesting your attention. You grudgingly get out of the hot-tub, put on your clothes and walk to the bridge to check out whatever is up with the autopilot.

When you arrive at the helm you see red screens everywhere. Thinking that it might be a good idea to sound more than a few beeps if the entire cockpit is lit up in red you walk over to the closest display to see what's wrong.

ALERT! FATAL SYSTEM CRASH ENTER EMERGENCY UNLOCK CODE TO REBOOT Seed: TWIJSSGPIEESEDZTZBZTDRPWIEDJDVEEZWHB HEMIPMWHJBHWHJIZGDDEHJPHIRVVJJVTREWZ UDERITWRIRPRHHPUHJZIRRPTMIGTRPJHBIEE VVHREWBREBJIRZPGZWHIZTTTGPDTHDHRPEBZ Input:

Ah, the security requirements from the Terran Space Aviation Comission specify that all critical systems must use generated codes for system maintenance. Remembering that the manufacturer mentioned something about a code-generating device you walk back to the hot-tub and start looking through your stuff.

After looking through all your bags and still not finding anything even remotely looking like a code-generating device you start rummaging around the hot tub and when you lift the coaster to look beneath it you see a small display on the underside.

P|*|E|A|%|E|^|S|)|&|N| |S|7|E|D

Oups. It seems the "coaster" was the code-generator, and it doesn't seem to have appreciated the Trappist ale Obviously, Trappist ale refers to the ale brewed by the monks of Trappist-1d in the Trappist-1 system in the Aquarius constellation you spilled on it.

Back to the cockpit it is. You take the manual from the bookshelf and quickly find the page that documents the code generation routine.

Emergency Code Generation

Your CipherSynth 3000 contains everything that is needed to generate emergency codes. Please use the CipherSynth 3000 to generate emergency codes.

The algorithm for generating the emergency codes is a standard Marvin TPA reduction algorithm. A brief explanation follows:

Marvin TPA Algorithm

Disclaimer 1: The Marvin TPA Algorithm uses 1-based positioning - i.e. A has position 1. Disclaimer 2: The Marvin TPA Algorithm considers Y a wovel and W a consonant.

  1. Discarding all whitespace, divide the seed up into groups of 16 characters. If the last group is not of 16 characters, append the alphabet until it is.
  2. For each group:
    1. Reverse the order of characters in the group
    2. Replace every consonant with the character that comes 13 positions after alphabetically, wrapping around to the start of the alphabet.
    3. Iteratively from the second character, swap every vowel with the character in the position before it.
    4. Replace each character with its numerical position in the alphabet.
  3. To combine the groups into the final code:
    1. Position by position, add all numbers at that position from all the groups together.
    2. Replace each number by the character at that position in the alphabet, wrapping around if necessary.

Example

For further explanation here is a sample for reducing the seed ABCDEFGHIJKLMNOPQRSTUVWXYZ:

  1. The seed divides into the groups: ABCDEFGHIJKLMNOP and QRSTUVWXYZ. Since the last group isn't 16 characters long it is padded to: QRSTUVWXYZABCDEF
  2. Apply the transformations to each group, resulting in the new groups:
    • Group 1:
      1. PONMLKJIHGFEDCBA
      2. COAZYXWIUTSEQPOA
      3. OACYZXIUWTESQOAP
      4. 15 1 3 25 26 24 9 21 23 20 5 19 17 15 1 16
    • Group 2:
      1. FEDCBAZYXWVUTSRQ
      2. SEQPOAMYKJIUGFED
      3. ESQOAPYMKIUJGEFD
      4. 5 19 17 15 1 16 25 13 11 9 21 10 7 5 6 4
  3. Position-wise addition and substitution yields:
    1. 20 20 20 40 27 40 34 34 34 29 26 29 24 20 7 20
    2. TTTNANHHHCZCXTGT

Calculate the emergency reboot code with the seed from the console.

Creative Commons License This work is licensed under a Creative Commons Attribution 4.0 International License.