Problem 44356. Code breaker, Part II: Operation Orthos

You have been tasked with decoding several batches of coded messages that have been intercepted.

Based on previous intelligence that has been gathered, you can be confident that the messages were all encoded using a simple Caesar cipher (a type of substitution cipher), an example of which is the ROT13 cipher (discussed in Cody Challenge Problem 78). As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation & numbers) are unchanged. Unlike the Cody Challenge Problem, here the number of letters to shift is not known in advance, and may vary between batches of messages — although it will be the same for all messages in a batch (also, here you need to decode, not encode).

You can also assume that the original batch of messages will relate to an activity that is referred to by those involved as "Operation Orthos". However, in their secret internal communications they might not use this exact phrase at all, nor this exact capitalisation. Therefore you should seek simultaneous occurrence of the separate words "Operation" and "Orthos" (with any capitalisation) in messages within the given batch.

Your task is to crack the codes and report back in a structure array: (1) the shifting parameter that had been used in the encoding [as uint8]; (2) the decoded messages [as a cell array (containing character arrays)]. The name of the structure array shall be "s", with respective fields "shift" and "message".

EXAMPLE

Suppose the batch contained two encoded messages — "qspdffe x/ pqfsbujpo" and "Psuipt jt HP!" (provided as character arrays within a cell array) — and a (right-shifting) ROT1 cipher had been applied. In that case A→B, B→C, ..., Y→Z, and Z→A; similarly, a→b, b→c, ..., y→z, and z→a. (Note that the shifting 'wraps' back around.) Thus the original messages would have been: "proceed w/ operation" and "Orthos is GO!" .

The correct answer would comprise:

s.shift = uint8(1)  
s.message = {'proceed w/ operation', 'Orthos is GO!'}

If the batch of messages cannot be decoded when following the above assumptions, then simply return 'scalar' NaN in both fields (no need for a cell array).

Note: Many Cody solutions are hard to read and not necessarily computationally efficient. To direct attention toward efficient runtime speed of execution, timings are measured in the Test Suite, and reported back (if the submission is runnable). Although the timings are not perfectly reproducible, they do provide an indication of computational resource demand. (Try resubmitting on another day if your code runs slowly, in case it is caused by a server issue.)

To provide some extra motivation for you to get your code to run efficiently, it will fail the Test Suite if it is deemed "too slow".

----------

Previous problem: Operation Phoenix. Next problem: Operation Xiangliu.

Solution Stats

19.62% Correct | 80.38% Incorrect
Last Solution submitted on Nov 10, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers25

Suggested Problems

More from this Author32

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!