Problem 44351. Code breaker, Part I: Operation Phoenix
You have been tasked with decoding a set of coded messages that have been intercepted.
Based on previous intelligence that has been gathered, you can be confident that the messages were 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 messages (also, here you need to decode, not encode).
You can also assume that the original message will relate to an activity that is referred to by those involved as "Operation Phoenix". Therefore the phrase "Operation Phoenix" (with that capitalisation) would have appeared at least once in the original message.
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 message [as character array]. The name of the structure array shall be "s", with respective fields "shift" and "message".
EXAMPLE
Suppose the original message was "Cancel Operation Phoenix immediately & escape." 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 encoded message would be: "Dbodfm Pqfsbujpo Qipfojy jnnfejbufmz & ftdbqf."
The correct answer would comprise:
s.shift = uint8(1) s.message = 'Cancel Operation Phoenix immediately & escape.'
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 and doesn't generate excessive text output). Although the timings are not perfectly reproducible, they do provide an indication of computational resource demand.
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".
----------
Next problem: Operation Orthos.
----------
Statistics on solutions submitted as at 15 October 2017:
- Fastest wall time to decode 5000 messages = 93 milliseconds , for Solution 1279303, with a size-based score of 40.
- Smallest size-based score = 38 , for Solution 1278780, for which wall time to decode 5000 messages = 515 milliseconds.
- Best combined score = 49, for Solution 1279303.
Solution Stats
Problem Comments
-
1 Comment
FYI: The fastest solution mentioned at the problem description uses a lookup-table. Don't beat yourself too much.
Solution Comments
Show commentsProblem Recent Solvers37
Suggested Problems
-
1401 Solvers
-
Piecewise linear interpolation
553 Solvers
-
Golomb's self-describing sequence (based on Euler 341)
160 Solvers
-
818 Solvers
-
5162 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!