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
Problem Comments
-
3 Comments
I recommend you to add additional test cases where only one key word, either operation or Orthos, appears in your input. Currently, the two words always appear simultaneously (unless they are both absent), and thus, one only needs to check the existence of a single word.
I also noticed that the iteration number qBig currently being used is too small (and your timing result is only in milliseconds, but there are other overheads which can cause very unreliable measurements). You should use larger qBig, at least 10000. Please note that Cody allows for at least 30 seconds for solution evaluations. So the evaluation time should be in the scale of seconds. This way, any solution runs too slow (e.g., in the scale of minutes) won't pass. This way, without modifying Cody's default scoring system, you automatically force people to focus on improving the code performance, rather than just reducing the code size. Also note that your current modification of the scoring function is an outdated hack to Cody's default scoring system, which does not work any more.
Hi, Peng Liu. Thanks for your feedback. TEST CASES: Even though both words always appear simultaneously, only checking for one would engender a high risk of failing Test 4. I do have planned one more decoding problem that would be like what you suggest, though. TIMING: Thanks for the extra information. Actually I'd cut down qBig — somehow I had the idea Cody only allowed a couple of seconds to run, at most. Based on your helpful advice I'll boost qBig. SCORING: Yes, I agree that it's an outdated hack. Hence I revised the wording of the introduction and commented out (almost) all of the size-related code in the Test Suite, compared to the Operation Phoenix problem.
Solution Comments
Show commentsProblem Recent Solvers24
Suggested Problems
-
Renaming a field in a structure array
1515 Solvers
-
193 Solvers
-
Generate N equally spaced intervals between -L and L
856 Solvers
-
5058 Solvers
-
1555 Solvers
More from this Author32
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!