{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":751,"title":"Implement simple rotation cypher","description":"If given a letter from the set:\r\n\r\n  [abc...xyz]\r\n\r\nand a shift, implement a shift cypher.\r\n\r\nExample:\r\n\r\n  'abc' \r\n\r\nwith a shift of -1 yields\r\n\r\n  'zab'\r\n\r\n\r\n\r\n\r\n","description_html":"\u003cp\u003eIf given a letter from the set:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[abc...xyz]\r\n\u003c/pre\u003e\u003cp\u003eand a shift, implement a shift cypher.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e'abc' \r\n\u003c/pre\u003e\u003cp\u003ewith a shift of -1 yields\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e'zab'\r\n\u003c/pre\u003e","function_template":"function outStr = cypher(inStr, shift)\r\n  outStr = inStr;\r\nend","test_suite":"%%\r\ninStr = 'doug';\r\nshift = 10;\r\noutStr = 'nyeq';\r\n\r\nassert(isequal(cypher(inStr, shift),outStr))\r\n\r\n%%\r\ninStr = 'thequickbrownfox';\r\nshift = 5;\r\noutStr = 'ymjvznhpgwtbsktc';\r\n\r\nassert(isequal(cypher(inStr, shift),outStr))\r\n\r\n%%\r\ninStr = 'thecrowfliesatmidnight';\r\nshift = 22;\r\noutStr = 'pdaynksbheaowpiezjecdp';\r\n\r\nassert(isequal(cypher(inStr, shift),outStr))","published":true,"deleted":false,"likes_count":13,"comments_count":2,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1096,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":6,"created_at":"2012-06-06T15:38:43.000Z","updated_at":"2026-02-19T13:12:57.000Z","published_at":"2012-06-08T19:08:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf given a letter from the set:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[[abc...xyz]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eand a shift, implement a shift cypher.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA['abc']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ewith a shift of -1 yields\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA['zab']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44351,"title":"Code breaker, Part I:  Operation Phoenix","description":"You have been tasked with decoding a set of coded messages that have been intercepted.  \r\n\r\nBased on previous intelligence that has been gathered, you can be confident that the messages were encoded using a simple \u003chttps://en.wikipedia.org/wiki/Caesar_cipher Caesar cipher\u003e (a type of \u003chttps://en.wikipedia.org/wiki/Substitution_cipher substitution cipher\u003e), an example of which is the \u003chttps://en.wikipedia.org/wiki/ROT13 ROT13 cipher\u003e (discussed in \u003chttps://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher Cody Challenge Problem 78\u003e).  As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation \u0026 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).  \r\n\r\nYou 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.  \r\n\r\nYour task is to crack the codes and report back in a \u003chttp://au.mathworks.com/help/matlab/ref/struct.html structure array\u003e:  (1) the shifting parameter that had been used in the encoding [as \u003chttp://au.mathworks.com/help/matlab/ref/uint8.html uint8\u003e];  (2)  the decoded message [as \u003chttp://au.mathworks.com/help/matlab/ref/char.html character array\u003e].  \r\nThe name of the structure array shall be \"s\", with respective fields \"shift\" and \"message\".  \r\n\r\nEXAMPLE\r\n\r\nSuppose the original message was _\"Cancel Operation Phoenix immediately \u0026 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.)  \r\nThus the encoded message would be:  _\"Dbodfm Pqfsbujpo Qipfojy jnnfejbufmz \u0026 ftdbqf.\"_\r\n\r\nThe correct answer would comprise:  \r\n\r\n  s.shift = uint8(1)  \r\n  s.message = 'Cancel Operation Phoenix immediately \u0026 escape.'\r\n\r\n|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.|  \r\n\r\nTo 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\".\r\n\r\n----------\r\n\r\nNext problem:  \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44356 Operation Orthos\u003e.\r\n\r\n----------\r\n\r\nStatistics on solutions submitted as at 15 October 2017:\r\n\r\n* *Fastest wall time to decode 5000 messages = 93 milliseconds* , for \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1279303 Solution 1279303\u003e, with a size-based score of 40. \r\n* *Smallest size-based score = 38* , for \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1278780 Solution 1278780\u003e, for which wall time to decode 5000 messages = 515 milliseconds.  \r\n* Best combined score = 49, for \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1279303 Solution 1279303\u003e. ","description_html":"\u003cp\u003eYou have been tasked with decoding a set of coded messages that have been intercepted.\u003c/p\u003e\u003cp\u003eBased on previous intelligence that has been gathered, you can be confident that the messages were encoded using a simple \u003ca href = \"https://en.wikipedia.org/wiki/Caesar_cipher\"\u003eCaesar cipher\u003c/a\u003e (a type of \u003ca href = \"https://en.wikipedia.org/wiki/Substitution_cipher\"\u003esubstitution cipher\u003c/a\u003e), an example of which is the \u003ca href = \"https://en.wikipedia.org/wiki/ROT13\"\u003eROT13 cipher\u003c/a\u003e (discussed in \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher\"\u003eCody Challenge Problem 78\u003c/a\u003e).  As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation \u0026 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).\u003c/p\u003e\u003cp\u003eYou 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.\u003c/p\u003e\u003cp\u003eYour task is to crack the codes and report back in a \u003ca href = \"http://au.mathworks.com/help/matlab/ref/struct.html\"\u003estructure array\u003c/a\u003e:  (1) the shifting parameter that had been used in the encoding [as \u003ca href = \"http://au.mathworks.com/help/matlab/ref/uint8.html\"\u003euint8\u003c/a\u003e];  (2)  the decoded message [as \u003ca href = \"http://au.mathworks.com/help/matlab/ref/char.html\"\u003echaracter array\u003c/a\u003e].  \r\nThe name of the structure array shall be \"s\", with respective fields \"shift\" and \"message\".\u003c/p\u003e\u003cp\u003eEXAMPLE\u003c/p\u003e\u003cp\u003eSuppose the original message was \u003ci\u003e\"Cancel Operation Phoenix immediately \u0026 escape.\"\u003c/i\u003e 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.)  \r\nThus the encoded message would be:  \u003ci\u003e\"Dbodfm Pqfsbujpo Qipfojy jnnfejbufmz \u0026 ftdbqf.\"\u003c/i\u003e\u003c/p\u003e\u003cp\u003eThe correct answer would comprise:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003es.shift = uint8(1)  \r\ns.message = 'Cancel Operation Phoenix immediately \u0026 escape.'\r\n\u003c/pre\u003e\u003cp\u003e\u003ctt\u003eNote: 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.\u003c/tt\u003e\u003c/p\u003e\u003cp\u003eTo 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\".\u003c/p\u003e\u003cp\u003e----------\u003c/p\u003e\u003cp\u003eNext problem:  \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44356\"\u003eOperation Orthos\u003c/a\u003e.\u003c/p\u003e\u003cp\u003e----------\u003c/p\u003e\u003cp\u003eStatistics on solutions submitted as at 15 October 2017:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003eFastest wall time to decode 5000 messages = 93 milliseconds\u003c/b\u003e , for \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1279303\"\u003eSolution 1279303\u003c/a\u003e, with a size-based score of 40.\u003c/li\u003e\u003cli\u003e\u003cb\u003eSmallest size-based score = 38\u003c/b\u003e , for \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1278780\"\u003eSolution 1278780\u003c/a\u003e, for which wall time to decode 5000 messages = 515 milliseconds.\u003c/li\u003e\u003cli\u003eBest combined score = 49, for \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1279303\"\u003eSolution 1279303\u003c/a\u003e.\u003c/li\u003e\u003c/ul\u003e","function_template":"function s = decode(x)\r\n  s = x;\r\nend","test_suite":"%% NOTE:  \r\n% This test suite can be updated if inappropriate 'hacks' \r\n% are discovered in any submitted solutions, \r\n% so your score/size may therefore change over time.  \r\n\r\n\r\n%% Test 1\r\nx = 'Dbodfm Pqfsbujpo Qipfojy jnnfejbufmz \u0026 ftdbqf.';\r\ns_correct.shift = 1;\r\ns_correct.message = 'Cancel Operation Phoenix immediately \u0026 escape.';\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\nassert( isequal(class(s.shift), 'uint8') )\r\nassert( isequal(class(s.message), 'char') )\r\n\r\n\r\n%% Test 2\r\nx = 'Vwlyhapvu Wovlupe ilnpuz Ablzkhf!  Vwlyhapvu Wovlupe pz vby avw wypvypaf.';\r\ns_correct.shift = 7;\r\ns_correct.message = 'Operation Phoenix begins Tuesday!  Operation Phoenix is our top priority.';\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\nassert( isequal(class(s.shift), 'uint8') )\r\nassert( isequal(class(s.message), 'char') )\r\n\r\n\r\n%% Test 3\r\nx = 'Eatpht cdit iwpi iwt ephhldgs wph qttc rwpcvts ugdb \"Fxeudyn\" id \"Dvcsbwl\".  Diwtglxht Detgpixdc Ewdtcxm xh egdrttsxcv prrdgsxcv id eapc.';\r\ns_correct.shift = 15;\r\ns_correct.message = 'Please note that the password has been changed from \"Qipfojy\" to \"Ogndmhw\".  Otherwise Operation Phoenix is proceeding according to plan.';\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\nassert( isequal(class(s.shift), 'uint8') )\r\nassert( isequal(class(s.message), 'char') )\r\n\r\n\r\n%% Test 4\r\nx = 'Mncpyrgml Nfmclgv qryprcb rfpcc bywq yem.  Yjj ncpqmllcj ypc rm pckygl ml bsrw slrgj Mncpyrgml Nfmclgv gq amknjcrcb.';\r\ns_correct.shift = 24;\r\ns_correct.message = 'Operation Phoenix started three days ago.  All personnel are to remain on duty until Operation Phoenix is completed.';\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\nassert( isequal(class(s.shift), 'uint8') )\r\nassert( isequal(class(s.message), 'char') )\r\n\r\n\r\n%% Rescoring \r\n% Acknowledgements \r\n% Portions of this timing test code were inspired by:\r\n% (1) Problem 937. \"Rubik's Mini Cube: Solve Randomized Cube in 11 Moves or Less; Score is by Time (msec)\" by Richard Zapor.\r\n% (2) Problem 2733. \"Evil Number\" by Jan Orwat.\r\n% (3) Feedback in comments from Peng Liu.\r\n% (4) Problem Problem 1237. \"It's race time! Write a faster function than the test suite call of unique().\" by Jeremy.\r\n\r\n% Note:  The Time Trial section does not check accuracy; that is done above.\r\n\r\n% Initialise\r\nx = 'Dbodfm Pqfsbujpo Qipfojy jnnfejbufmz \u0026 ftdbqf.';\r\ncutoffTimeBig = 1000; % Maximum allowable walltime (in milliseconds) to run function in a loop with qBig iterations.\r\n\r\nfor dummy = 1 : 20,  disp(' . ');  end;\r\n\r\n% Run once, untimed?\r\nincludeOverheads = false;\r\nif includeOverheads, \r\n    solution = decode( x );\r\nend;\r\n\r\n% *** PRELIMINARY TIMING ***\r\n% In case the submitted function has a lot of text output, \r\n% get an estimate based on just a few iterations\r\n% Initialise\r\nqSmall = 50;\r\nqBig = 5000;\r\nt0 = clock;\r\n\r\n% Loop\r\nfor i = 1 : qSmall\r\n    solution = decode( x );\r\nend;\r\n\r\n% Compute and display elapsed time.\r\ndt = etime(clock, t0) * 1000;\r\ndisp('     -----=====-----     ')\r\nfprintf('Your wall time to decode %u messages = %i msec.\\n\\r', qSmall, floor(dt))\r\nfprintf('Your APPROXIMATE wall time to decode %u messages would be ~ %i msec.\\n\\r', qBig, ceil(dt * qBig / qSmall))\r\ndisp('     -----=====-----     ')\r\nfor dummy = 1 : 20,  disp(' . ');  end;\r\n\r\n% *** 'OFFICIAL' TIMING ***\r\n% Re-initialise timer\r\nt0 = clock;\r\nt0_cpu = cputime;\r\n\r\n% Loop\r\nfor i = 1 : qBig\r\n    solution = decode( x );\r\nend;\r\n\r\n% Compute and display elapsed time.\r\nfor dummy = 1 : 20,  disp(' . ');  end;\r\ndisp('     -----=====|||||=====-----     ')\r\ndt = etime(clock, t0) * 1000;\r\nfprintf('Your wall time to decode %u messages = %i msec.\\n\\r', qBig, floor(dt))\r\n\r\ndt_cpu = (cputime - t0_cpu) * 1000;\r\nfprintf(' ( Your CPU time for this = %i msec. ) \\n\\r', floor(dt_cpu))\r\n\r\nfDecode = @()   decode(x);\r\ndt_timeit = timeit( fDecode ) * 1000;\r\nfprintf(' [ Your ''timeit'' time to decode %u messages = %i msec. ] \\n\\r', qBig, ceil(dt_timeit * qBig))\r\n\r\n% Display a size-based score.\r\nall_nodes = mtree('decode.m', '-file');        % This is the default in Cody.\r\nstr_nodes = mtfind(all_nodes, 'Kind', 'STRING');\r\neq_nodes = mtfind(all_nodes, 'Kind', 'EQUALS');\r\nprint_nodes = mtfind(all_nodes, 'Kind', 'PRINT');\r\nexpr_nodes = mtfind(all_nodes, 'Kind', 'EXPR');\r\n\r\nsize_score = count(all_nodes) ...\r\n +sum(str_nodes.nodesize-1) ...\r\n +2*(count(expr_nodes) ...\r\n +count(print_nodes) ...\r\n -count(eq_nodes));\r\n\r\nfprintf('Your size-based score = %i.\\n\\r', size_score)\r\n\r\n% Report revised performance score.\r\ncombinedScore = size_score  +  min( 200, floor(dt*(500/qBig)) );\r\nfprintf('Your combined score = %i.\\n\\r', combinedScore)\r\ndisp('     -----=====|||||=====-----     ')\r\n\r\n% Now disallow any candidate solutions that are TOO SLOW!\r\nif dt \u003e cutoffTimeBig, \r\n    fprintf('Sorry, your submission is TOO SLOW. It must be able to finish within %u milliseconds.\\n\\r', cutoffTimeBig)\r\nend;\r\n\r\nassert( dt \u003c= cutoffTimeBig, 'Exceeded time limit specified in Test Suite.' )","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":45,"test_suite_updated_at":"2017-10-15T10:19:08.000Z","rescore_all_solutions":false,"group_id":40,"created_at":"2017-09-29T09:20:59.000Z","updated_at":"2026-04-02T08:27:57.000Z","published_at":"2017-09-29T13:45:26.000Z","restored_at":"2017-10-04T19:25:07.000Z","restored_by":null,"spam":false,"simulink":false,"admin_reviewed":true,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have been tasked with decoding a set of coded messages that have been intercepted.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBased on previous intelligence that has been gathered, you can be confident that the messages were encoded using a simple\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Caesar_cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCaesar cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (a type of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Substitution_cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esubstitution cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e), an example of which is the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/ROT13\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eROT13 cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (discussed in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody Challenge Problem 78\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e). As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation \u0026amp; 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).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou 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.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour task is to crack the codes and report back in a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/struct.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003estructure array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e: (1) the shifting parameter that had been used in the encoding [as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/uint8.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003euint8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e]; (2) the decoded message [as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/char.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003echaracter array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e]. The name of the structure array shall be \\\"s\\\", with respective fields \\\"shift\\\" and \\\"message\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEXAMPLE\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose the original message was\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Cancel Operation Phoenix immediately \u0026amp; escape.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Dbodfm Pqfsbujpo Qipfojy jnnfejbufmz \u0026amp; ftdbqf.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe correct answer would comprise:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[s.shift = uint8(1)  \\ns.message = 'Cancel Operation Phoenix immediately \u0026 escape.']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNote: 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.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo 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\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e----------\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNext problem: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44356\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOperation Orthos\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e----------\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eStatistics on solutions submitted as at 15 October 2017:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFastest wall time to decode 5000 messages = 93 milliseconds\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1279303\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSolution 1279303\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, with a size-based score of 40.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSmallest size-based score = 38\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1278780\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSolution 1278780\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, for which wall time to decode 5000 messages = 515 milliseconds.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBest combined score = 49, for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1279303\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSolution 1279303\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1219,"title":"Mystery problem","description":"Given integer x between 1 and 50, return integer y=mystery(x), where \r\n\r\n   mystery(1) =  111   mystery(6)  =  809  ...  mystery(46) = 1809\r\n   mystery(2) =  301   mystery(7)  = 2120  ...  mystery(47) = 1319\r\n   mystery(3) =  315   mystery(8)  = 1413  ...  mystery(48) = 1201\r\n   mystery(4) = 2301   mystery(9)  = 1422  ...  mystery(49) =  405\r\n   mystery(5) = 2325   mystery(10) = 1320  ...  mystery(50) =  612 \r\n\r\nThe rest are for you to determine. Your function should allow a row vector as input and produce a row vector as a result, e.g.,\r\n\r\n   mystery(1:3)=[111 301 315].\r\n\r\nHint: this is not really a mathematical problem--the answer will be just a lookup table.","description_html":"\u003cp\u003eGiven integer x between 1 and 50, return integer y=mystery(x), where\u003c/p\u003e\u003cpre\u003e   mystery(1) =  111   mystery(6)  =  809  ...  mystery(46) = 1809\r\n   mystery(2) =  301   mystery(7)  = 2120  ...  mystery(47) = 1319\r\n   mystery(3) =  315   mystery(8)  = 1413  ...  mystery(48) = 1201\r\n   mystery(4) = 2301   mystery(9)  = 1422  ...  mystery(49) =  405\r\n   mystery(5) = 2325   mystery(10) = 1320  ...  mystery(50) =  612 \u003c/pre\u003e\u003cp\u003eThe rest are for you to determine. Your function should allow a row vector as input and produce a row vector as a result, e.g.,\u003c/p\u003e\u003cpre\u003e   mystery(1:3)=[111 301 315].\u003c/pre\u003e\u003cp\u003eHint: this is not really a mathematical problem--the answer will be just a lookup table.\u003c/p\u003e","function_template":"function y=mystery(x)\r\ny=0;\r\n","test_suite":"%%\r\nassert(isequal(mystery(1:5),[111 301 315 2301 2325]))\r\n%%\r\nassert(isequal(mystery(6:10),[809 2120 1413 1422 1320]))\r\n%%\r\nassert(isequal(mystery(46:50),[1809 1319 1201 405 612]))\r\n%%\r\nx=1:50;\r\nm=mystery(x);\r\nassert(all(m==round(m)))\r\ny=spline(x,m,[12.5 37.5]);\r\nassert(all(y==[704.84846527373202 1283.5708406360138]))","published":true,"deleted":false,"likes_count":3,"comments_count":12,"created_by":245,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":14,"test_suite_updated_at":"2013-01-28T15:31:56.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-01-22T15:48:02.000Z","updated_at":"2013-02-26T06:36:07.000Z","published_at":"2013-01-22T15:51:00.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven integer x between 1 and 50, return integer y=mystery(x), where\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   mystery(1) =  111   mystery(6)  =  809  ...  mystery(46) = 1809\\n   mystery(2) =  301   mystery(7)  = 2120  ...  mystery(47) = 1319\\n   mystery(3) =  315   mystery(8)  = 1413  ...  mystery(48) = 1201\\n   mystery(4) = 2301   mystery(9)  = 1422  ...  mystery(49) =  405\\n   mystery(5) = 2325   mystery(10) = 1320  ...  mystery(50) =  612]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe rest are for you to determine. Your function should allow a row vector as input and produce a row vector as a result, e.g.,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   mystery(1:3)=[111 301 315].]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHint: this is not really a mathematical problem--the answer will be just a lookup table.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44356,"title":"Code breaker, Part II:  Operation Orthos","description":"You have been tasked with decoding several batches of coded messages that have been intercepted.  \r\n\r\nBased on previous intelligence that has been gathered, you can be confident that the messages were all encoded using a simple \u003chttps://en.wikipedia.org/wiki/Caesar_cipher Caesar cipher\u003e (a type of \u003chttps://en.wikipedia.org/wiki/Substitution_cipher substitution cipher\u003e), an example of which is the \u003chttps://en.wikipedia.org/wiki/ROT13 ROT13 cipher\u003e (discussed in \u003chttps://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher Cody Challenge Problem 78\u003e).  As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation \u0026 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).  \r\n\r\nYou 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.  \r\n\r\nYour task is to crack the codes and report back in a \u003chttp://au.mathworks.com/help/matlab/ref/struct.html structure array\u003e:  (1) the shifting parameter that had been used in the encoding [as \u003chttp://au.mathworks.com/help/matlab/ref/uint8.html uint8\u003e];  (2)  the decoded messages [as a \u003chttp://au.mathworks.com/help/matlab/ref/cell.html?s_tid=doc_ta cell array\u003e (containing \u003chttp://au.mathworks.com/help/matlab/ref/char.html character arrays\u003e)].  \r\nThe name of the structure array shall be \"s\", with respective fields \"shift\" and \"message\".  \r\n\r\nEXAMPLE\r\n\r\nSuppose 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.)  \r\nThus the original messages would have been:  _\"proceed w/ operation\"_ and _\"Orthos is GO!\"_ .\r\n\r\nThe correct answer would comprise:  \r\n\r\n  s.shift = uint8(1)  \r\n  s.message = {'proceed w/ operation', 'Orthos is GO!'}\r\n\r\nIf the batch of messages cannot be decoded when following the above assumptions, then simply return 'scalar' \u003chttp://au.mathworks.com/help/matlab/ref/nan.html NaN\u003e in both fields (no need for a cell array).  \r\n\r\n|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.)|  \r\n\r\nTo 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\".  \r\n\r\n----------\r\n\r\nPrevious problem:  \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44351 Operation Phoenix\u003e.  Next problem:  \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44383 Operation Xiangliu\u003e.","description_html":"\u003cp\u003eYou have been tasked with decoding several batches of coded messages that have been intercepted.\u003c/p\u003e\u003cp\u003eBased on previous intelligence that has been gathered, you can be confident that the messages were all encoded using a simple \u003ca href = \"https://en.wikipedia.org/wiki/Caesar_cipher\"\u003eCaesar cipher\u003c/a\u003e (a type of \u003ca href = \"https://en.wikipedia.org/wiki/Substitution_cipher\"\u003esubstitution cipher\u003c/a\u003e), an example of which is the \u003ca href = \"https://en.wikipedia.org/wiki/ROT13\"\u003eROT13 cipher\u003c/a\u003e (discussed in \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher\"\u003eCody Challenge Problem 78\u003c/a\u003e).  As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation \u0026 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).\u003c/p\u003e\u003cp\u003eYou 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 \u003ci\u003esimultaneous\u003c/i\u003e occurrence of the separate words \"Operation\" and \"Orthos\" (with any capitalisation) in messages within the given batch.\u003c/p\u003e\u003cp\u003eYour task is to crack the codes and report back in a \u003ca href = \"http://au.mathworks.com/help/matlab/ref/struct.html\"\u003estructure array\u003c/a\u003e:  (1) the shifting parameter that had been used in the encoding [as \u003ca href = \"http://au.mathworks.com/help/matlab/ref/uint8.html\"\u003euint8\u003c/a\u003e];  (2)  the decoded messages [as a \u003ca href = \"http://au.mathworks.com/help/matlab/ref/cell.html?s_tid=doc_ta\"\u003ecell array\u003c/a\u003e (containing \u003ca href = \"http://au.mathworks.com/help/matlab/ref/char.html\"\u003echaracter arrays\u003c/a\u003e)].  \r\nThe name of the structure array shall be \"s\", with respective fields \"shift\" and \"message\".\u003c/p\u003e\u003cp\u003eEXAMPLE\u003c/p\u003e\u003cp\u003eSuppose the batch contained two encoded messages — \u003ci\u003e\"qspdffe x/ pqfsbujpo\"\u003c/i\u003e and \u003ci\u003e\"Psuipt jt HP!\"\u003c/i\u003e (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.)  \r\nThus the original messages would have been:  \u003ci\u003e\"proceed w/ operation\"\u003c/i\u003e and \u003ci\u003e\"Orthos is GO!\"\u003c/i\u003e .\u003c/p\u003e\u003cp\u003eThe correct answer would comprise:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003es.shift = uint8(1)  \r\ns.message = {'proceed w/ operation', 'Orthos is GO!'}\r\n\u003c/pre\u003e\u003cp\u003eIf the batch of messages cannot be decoded when following the above assumptions, then simply return 'scalar' \u003ca href = \"http://au.mathworks.com/help/matlab/ref/nan.html\"\u003eNaN\u003c/a\u003e in both fields (no need for a cell array).\u003c/p\u003e\u003cp\u003e\u003ctt\u003eNote:  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.)\u003c/tt\u003e\u003c/p\u003e\u003cp\u003eTo 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\".\u003c/p\u003e\u003cp\u003e----------\u003c/p\u003e\u003cp\u003ePrevious problem:  \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44351\"\u003eOperation Phoenix\u003c/a\u003e.  Next problem:  \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44383\"\u003eOperation Xiangliu\u003c/a\u003e.\u003c/p\u003e","function_template":"function s = decode(x)\r\n  s = x;\r\nend","test_suite":"%% NOTE:  \r\n% This test suite can be updated if inappropriate 'hacks' \r\n% are discovered in any submitted solutions, \r\n% so the assessment of your submission may therefore change over time.  \r\nRE = regexp(fileread('decode.m'), '\\w+', 'match');\r\ntabooWords = {'ans', 'assert', 'freepass', 'tic'};\r\ntestResult = cellfun( @(z) ismember(z, tabooWords), RE );\r\nmsg = ['Please do not do that in your code!' char([10 13]) ...\r\n    'Found: ' strjoin(RE(testResult)) '.' char([10 13]) ...\r\n    'Banned word.' char([10 13])];\r\nassert(~any(  cellfun( @(z) ismember(z, tabooWords), RE )  ), msg)\r\n\r\n\r\n%% Test 1\r\nx =                 {'qspdffe x/ pqfsbujpo', 'Psuipt jt HP!'};\r\ns_correct.shift = uint8(1);\r\ns_correct.message = {'proceed w/ operation', 'Orthos is GO!'};\r\ns = decode(x);\r\n%disp(' *** ');  disp(s.message);  disp(' *** ')\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message{1}, s_correct.message{1}) )\r\nassert( isequal(s.message{2}, s_correct.message{2}) )\r\nassert( isequal(s.message, s_correct.message) )\r\nassert( isequal(s, s_correct) )\r\nassert( isequal(class(s.shift), 'uint8') )\r\nassert( isequal(class(s.message), 'cell') )\r\nassert( isequal(class(s.message{1}), 'char') )\r\n\r\n\r\n%% Test 2\r\nx =                 {'Hfqq Ons ts 555-7839 FXFU.', 'twymtx nx ts mtqi', 'bfnynsl ktw dtzw fianhj', 'TUJWFYNTS UTXYUTSJI'};\r\ns_correct.shift = uint8(5);\r\ns_correct.message = {'Call Jin on 555-7839 ASAP.', 'orthos is on hold', 'waiting for your advice', 'OPERATION POSTPONED'};\r\ns = decode(x);\r\n%disp(' *** ');  disp(s.message);  disp(' *** ')\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\n\r\n\r\n%% Test 3\r\nx =                 {'Ocz kvnnrjmy rvn xcvibzy: \"Knpdko\" oj \"Gjlzgk\".', 'Jkzmvodji Kcjzids rvn npxxznnapg. Izso rdgg wz Jmocjn.', 'Edi Uvkxgzout rdgg wz gzvydib Ozvh V'};\r\ns_correct.shift = uint8(21);\r\ns_correct.message = {'The password was changed: \"Psuipt\" to \"Loqelp\".', 'Operation Phoenix was successful. Next will be Orthos.', 'Jin Zapcletzy will be leading Team A'};\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\n\r\n\r\n%% Test 4\r\nx =                 {'bxmzzuzs r/ adftae az fdmow', 'adftae etxp oaybxqfq uz 2 iwe', 'abqdmfuaz pmfq eturfqp nmow 2 p.', 'naawe dqoquhqp. fwe Vuz' };\r\ns_correct.shift = uint8(12);\r\ns_correct.message = {'planning f/ orthos on track', 'orthos shld complete in 2 wks', 'operation date shifted back 2 d.', 'books received. tks Jin'};\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\n\r\n\r\n%% Test 5\r\nx =                 {'Hdsffafy xgj Ghwjslagf Gjlzgk zsk gxxauasddq ugeewfuwv.  Lzak oadd tw dwv tq Lwse S, kmhhgjlwv tq Lwse T sk fwwvwv.'};\r\ns_correct.shift = uint8(18);\r\ns_correct.message = {'Planning for Operation Orthos has officially commenced.  This will be led by Team A, supported by Team B as needed.'};\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\n\r\n\r\n%% Test 6\r\nx = {'Mncpyrgml Nfmclgv qryprcb rfpcc bywq yem.  Yjj ncpqmllcj ypc rm pckygl ml bsrw slrgj Mncpyrgml Nfmclgv gq amknjcrcb.'};\r\ns_correct.shift = nan;\r\ns_correct.message = nan;\r\ns = decode(x);\r\nassert( isnan(s.shift) )\r\nassert( isnan(s.message) )\r\n\r\n\r\n%% Test 7\r\nx =                 {'Iutloxskj vgyycuxj oy tuc \"Ruwkrv\".', 'Vrgt lux uxznuy ruuqy UQ, haz tkkj suxk $$$', 'Ksgor Pot Fgvirkzfe ut xacqxb@sgzncuxqy.ius xk. Zakyjge', 'Zgrqkj zu Zkgs H.  Ngvve zu yavvuxz uvkxgzout....', 'Xk. latjy, vry zxgtylkx zu giiuatz \"YZOBKDSYX\" - ZDY', 'jUT''Z cUXXE'};\r\ns_correct.shift = uint8(6);\r\ns_correct.message = {'Confirmed password is now \"Loqelp\".', 'Plan for orthos looks OK, but need more $$$', 'Email Jin Zapcletzy on ruwkrv@mathworks.com re. Tuesday', 'Talked to Team B.  Happy to support operation....', 'Re. funds, pls transfer to account \"STIVEXMSR\" - TXS', 'dON''T wORRY'};\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\n\r\n\r\n%% TIMING \r\n% Note:  The Time Trial section does not check accuracy; that is done above.\r\n\r\n% Acknowledgements  \r\n% Portions of this timing test code were inspired by:\r\n% (1) Problem 937. \"Rubik's Mini Cube: Solve Randomized Cube in 11 Moves or Less; Score is by Time (msec)\" by Richard Zapor.\r\n% (2) Problem 2733. \"Evil Number\" by Jan Orwat.\r\n% (3) Feedback in comments from Peng Liu.\r\n% (4) Problem Problem 1237. \"It's race time! Write a faster function than the test suite call of unique().\" by Jeremy.\r\n\r\n% INITIALISE\r\nx = {'qspdffe x/ pqfsbujpo', 'Psuipt jt HP!'};\r\nqSmall = 50;\r\nqBig = 10000;\r\n%cutoffTimeBig = 10;\r\n\r\n% EDIT (2018-06-17).  Reduced time to pose reasonable challenge.\r\n% Accounted for improving Cody server speed per Problem 44655.\r\ncutoffTimeBig = 3;    % Maximum allowable walltime (in seconds) to run function in a loop with qBig iterations.\r\ntRef = datetime('2018-06-17', 'InputFormat','yyyy-MM-dd');\r\ntNow = datetime('now');\r\nyearsElapsed = (datenum(tNow) - datenum(tRef)) / 365.24;\r\nfprintf('\\r\\n\\r\\n\\r\\nSubmission evaluated for speed on %s.\\r\\n', datestr(tNow, 'dd mmmm yyyy'))\r\nrInf = 0.2;   delta = cutoffTimeBig - rInf;  tau = 3.6;  % Data from Problem 44655, based on Problem 963.\r\nqBig = floor( qBig * (cutoffTimeBig - rInf) * exp(yearsElapsed/tau) / delta );\r\nfprintf('\\r\\n\\r\\n\\r\\nTo account for computational power increases over time, number of iterations increased to %u.\\r\\n', qBig)\r\n% END EDIT (2018-06-17)\r\n\r\nfor dummy = 1 : 10,  disp(' . ');  end;\r\n\r\n% *** PRELIMINARY TIMING WITH timeit ***\r\nfDecode = @()   decode(x);\r\ndt_timeit = timeit( fDecode );\r\nfprintf('APPROXIMATE time to decode %u message batches ~ %2.2f seconds, according to ''timeit''.\\n\\r', qBig, dt_timeit * qBig)\r\n\r\n% *** PRELIMINARY TIMING WITH SHORT LOOP ***\r\n% In case the submitted function has a lot of text output, \r\n% get an estimate based on just a few iterations\r\n% Initialise\r\nt0 = clock;\r\n\r\n% Loop\r\nfor i = 1 : qSmall\r\n    solution = decode( x );\r\nend;\r\n\r\n% Compute and display elapsed time.\r\ndt = etime(clock, t0);\r\ndisp('     -----=====-----     ')\r\n%fprintf('Your wall time to decode %u message batches = %i seconds.\\n\\r', qSmall, floor(dt))\r\nfprintf('APPROXIMATE wall time to decode %u message batches ~ %2.2f seconds, by extrapolating from %u batches.\\n\\r', qBig, dt * qBig / qSmall, qSmall)\r\ndisp('     -----=====-----     ')\r\n\r\n% *** 'OFFICIAL' TIMING ***\r\n% Re-initialise timer\r\nt0 = clock;\r\nt0_cpu = cputime;\r\n\r\n% Loop\r\nfor i = 1 : qBig\r\n    solution = decode( x );\r\nend;\r\n\r\n% Compute and display elapsed time.\r\nfor dummy = 1 : 10,  disp(' . ');  end;\r\ndisp('     -----=====|||||=====-----     ')\r\ndt = etime(clock, t0);\r\nfprintf('Your wall time to decode %u message batches = %2.2f seconds.\\n\\r', qBig, dt)\r\n\r\ndt_cpu = (cputime - t0_cpu);\r\nfprintf(' ( Your CPU time for this = %2.2f seconds. ) \\n\\r', dt_cpu)\r\n\r\n% Display (default) Cody size-based score.\r\nall_nodes = mtree('decode.m', '-file');\r\nsize_score = count(all_nodes);\r\nfprintf('Your Cody-standard size-based score = %i.\\n\\r', size_score)\r\n\r\n% Report revised performance score\r\ncombinedScore = size_score + round(dt * 10);\r\nfprintf('Your combined score = %i.\\n\\r', combinedScore)\r\ndisp('     -----=====|||||=====-----     ')\r\n\r\n% Now disallow any candidate solutions that are TOO SLOW!\r\nif dt \u003e cutoffTimeBig, \r\n    fprintf('Sorry, your submission is TOO SLOW.  It must be able to finish within %u seconds.\\n\\r', cutoffTimeBig)\r\nend;\r\n\r\nassert( dt \u003c= cutoffTimeBig )","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":"2018-06-17T14:03:55.000Z","rescore_all_solutions":false,"group_id":40,"created_at":"2017-10-03T06:52:32.000Z","updated_at":"2026-04-02T18:15:25.000Z","published_at":"2017-10-03T11:50:21.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have been tasked with decoding several batches of coded messages that have been intercepted.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBased on previous intelligence that has been gathered, you can be confident that the messages were all encoded using a simple\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Caesar_cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCaesar cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (a type of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Substitution_cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esubstitution cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e), an example of which is the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/ROT13\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eROT13 cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (discussed in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody Challenge Problem 78\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e). As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation \u0026amp; 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).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou 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\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esimultaneous\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e occurrence of the separate words \\\"Operation\\\" and \\\"Orthos\\\" (with any capitalisation) in messages within the given batch.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour task is to crack the codes and report back in a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/struct.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003estructure array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e: (1) the shifting parameter that had been used in the encoding [as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/uint8.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003euint8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e]; (2) the decoded messages [as a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/cell.html?s_tid=doc_ta\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ecell array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (containing\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/char.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003echaracter arrays\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e)]. The name of the structure array shall be \\\"s\\\", with respective fields \\\"shift\\\" and \\\"message\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEXAMPLE\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose the batch contained two encoded messages —\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"qspdffe x/ pqfsbujpo\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Psuipt jt HP!\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (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: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"proceed w/ operation\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Orthos is GO!\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e .\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe correct answer would comprise:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[s.shift = uint8(1)  \\ns.message = {'proceed w/ operation', 'Orthos is GO!'}]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf the batch of messages cannot be decoded when following the above assumptions, then simply return 'scalar'\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/nan.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eNaN\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in both fields (no need for a cell array).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNote: 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.)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo 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\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e----------\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44351\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOperation Phoenix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44383\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOperation Xiangliu\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":78,"title":"Implement a ROT13 cipher","description":"Replace each character in string s1 with the character that is shifted 13 positions from it (wrap back to the beginning if necessary). So A ? N, B ? O, and so on until Y ? L and Z ? M. Case of the output should match the case of the input, so a ? n. Non-alphabetic characters are left in place and untouched.\n\nIf\n\n s1 = 'I love MATLAB'\n\nthen\n\n s2 = 'V ybir ZNGYNO'\n\nSee the \u003chttp://en.wikipedia.org/wiki/ROT13 Wikipedia article\u003e for more info.","description_html":"\u003cp\u003eReplace each character in string s1 with the character that is shifted 13 positions from it (wrap back to the beginning if necessary). So A ? N, B ? O, and so on until Y ? L and Z ? M. Case of the output should match the case of the input, so a ? n. Non-alphabetic characters are left in place and untouched.\u003c/p\u003e\u003cp\u003eIf\u003c/p\u003e\u003cpre\u003e s1 = 'I love MATLAB'\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre\u003e s2 = 'V ybir ZNGYNO'\u003c/pre\u003e\u003cp\u003eSee the \u003ca href=\"http://en.wikipedia.org/wiki/ROT13\"\u003eWikipedia article\u003c/a\u003e for more info.\u003c/p\u003e","function_template":"function s2 = rot13(s1)\n  s2 = s1;\nend","test_suite":"%% Test #1\n\ns1 = 'I love MATLAB';\ns2_correct = 'V ybir ZNGYNO';\nassert(isequal(rot13(s1),s2_correct))\n\n%% Test #2\n\ns1 = 'I \u003c3 MATLAB!!';\ns2_correct = 'V \u003c3 ZNGYNO!!';\nassert(isequal(rot13(s1),s2_correct))\n\n%% Test #3\n\ns1 = 'The quick fox stumbled over the confusing instructions.';\ns2_correct = 'Gur dhvpx sbk fghzoyrq bire gur pbashfvat vafgehpgvbaf.';\nassert(isequal(rot13(s1),s2_correct))\n\n%% Test #4\n\ns1 = 'Snape kills Dumbledore on page 606. Also, there is no Santa.';\ns2_correct = 'Fancr xvyyf Qhzoyrqber ba cntr 606. Nyfb, gurer vf ab Fnagn.';\nassert(isequal(rot13(s1),s2_correct))\n\n","published":true,"deleted":false,"likes_count":13,"comments_count":3,"created_by":1,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1713,"test_suite_updated_at":"2012-01-18T01:00:28.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:28.000Z","updated_at":"2026-01-06T04:39:32.000Z","published_at":"2012-01-18T01:00:28.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReplace each character in string s1 with the character that is shifted 13 positions from it (wrap back to the beginning if necessary). So A ? N, B ? O, and so on until Y ? L and Z ? M. Case of the output should match the case of the input, so a ? n. Non-alphabetic characters are left in place and untouched.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ s1 = 'I love MATLAB']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ s2 = 'V ybir ZNGYNO']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/ROT13\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eWikipedia article\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e for more info.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44383,"title":"Code breaker, Part III:  Operation Xiangliu","description":"You have been tasked with decoding several batches of coded messages that have been intercepted.  \r\n\r\nBased on previous intelligence that has been gathered, you can be confident that the messages were all encoded using a simple \u003chttps://en.wikipedia.org/wiki/Caesar_cipher Caesar cipher\u003e (a type of \u003chttps://en.wikipedia.org/wiki/Substitution_cipher substitution cipher\u003e), an example of which is the \u003chttps://en.wikipedia.org/wiki/ROT13 ROT13 cipher\u003e (discussed in \u003chttps://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher Cody Challenge Problem 78\u003e).  As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation, numbers, accented letters) are unchanged.  Unlike the Cody Challenge Problem, here the number of letters to shift is not known in advance, and will vary _between_ (not within) batches — also, here you need to decode, not encode.  \r\n\r\nThese latest activities that you are investigating have been nicknamed 'Operation Xiangliu' by your own organisation.  A few decoding options are at your organisation's disposal:  \r\n\r\n# Test the candidate decodings against all words in a large dictionary — this could work, but it is very slow.\r\n# Test the candidate decodings for the appearance of a name or phrase that is certain to appear regularly (e.g. \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44351 \"Operation Phoenix\"\u003e) — unfortunately as yet there is not enough knowledge of the activities to be sure of a suitable name or phrase to use.  \r\n# Test the candidate decodings against all words in a short list comprising, say, the hundred most frequently used English words.\r\n\r\nThe *third option* will be faster than the first option, and more reliable than the second option, so this is the approach you will be taking.  \r\n\r\nYou have been careful to avoid using 'lemmatised' lists (which contain e.g. the verb \"to be\", rather than the various inflected forms such as \"am\", \"is\", \"are\") like those based on the \u003chttps://web.archive.org/web/20111226085859/http://oxforddictionaries.com/words/the-oec-facts-about-the-language OEC\u003e or \u003chttps://www.wordfrequency.info/free.asp?s=y COCA\u003e, and after setting aside \u003chttp://world-english.org/english500.htm another list\u003e you finally choose the \u003chttp://ucrel.lancs.ac.uk/bncfreq/samples/120.pdf list based on the BNC\u003e as the most reliable, and will use the first 100 words on that list.  \r\nThis list will be available for you to access as an input variable, |bncWordlist|, to your function. Note: (i) some entries on the list are morphemes (e.g. \"\u0026#x200A;n't\u0026#x200A;\" and \"\u0026#x200A;'s\u0026#x200A;\") rather than words;  (ii) some entries appear more than once (representing different grammatical word classes).  Of course, in the original messages any capitalisation might be used.  \r\n\r\nYou have been instructed that your 'certitude' (degree of confidence) in the decoding must be reported for each batch, and shall depend proportionally upon the sum of the characters for the words/morphemes in the decoded message that match words/morphemes in |bncWordlist|.  Being able to match words/morphemes accounting for three-tenths of the characters (excluding spaces) shall correspond to 100% certitude;  matching three-twentieths would be 50% certitude, and so on.  Certitude shall be reported as a percentage, rounded _up_ to the nearest integer, not greater than 100.  You need to maximise your certitude for each batch by appropriate choice of the shifting parameter.   If there are multiple shifts of equal certitude, report both options on different rows (arranged in order of ascending shift parameter).\r\n\r\nYour task is to crack the codes and report back in a \u003chttp://au.mathworks.com/help/matlab/ref/struct.html structure array\u003e: \u0026nbsp; (1) the shifting parameter that had been used in the encoding [as \u003chttp://au.mathworks.com/help/matlab/ref/uint8.html uint8\u003e] (usually scalar, but may be column vector); \u0026nbsp; (2) the decoded messages [as a \u003chttp://au.mathworks.com/help/matlab/ref/cell.html?s_tid=doc_ta cell array\u003e (containing \u003chttp://au.mathworks.com/help/matlab/ref/char.html character arrays\u003e)] (usually an array with a single row, but occasionally with multiple rows); \u0026nbsp; (3) your 'certitude' in the decoding [as \u003chttp://au.mathworks.com/help/matlab/ref/uint8.html uint8\u003e] (always scalar).  \r\nThe name of the structure array shall be |s|, with respective fields |shift|, |message|, and |certitude|.  \r\n\r\n*EXAMPLE 1*\r\n\r\nSuppose the batch contained two encoded messages — _\"Vomftt qvstvfe, pqfo op eppst.\"_ and _\"Ffmt dbo ljmm, opu pomz xpvoe.\"_ (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.  \r\nThus the original messages would have been:  _\"Unless pursued, open no doors.\"_ and _\"Eels can kill, not only wound.\"_ .  Twelve of the 51 characters have been matched:  \"no\", \"can\", \"not\", and \"only\".  \r\n\r\nThe correct answer would therefore comprise:  \r\n\r\n  s.shift = uint8(1)  \r\n  s.message = {'Unless pursued, open no doors.', 'Eels can kill, not only wound.'}\r\n  s.certitude = uint8(79)\r\n\r\n*EXAMPLE 2*\r\n\r\nSuppose the batch contained one encoded message — _\"Oa oqvvq'u cnycau dggp: \"Ctu itcvkc ctvku\".\"_ (provided as a character array within a cell array) — and a (right-shifting) ROT2 cipher had been applied.  In that case A→C, B→D, ..., Y→A, and Z→B;  similarly, a→c, b→d, ..., y→a, and z→b.  \r\nThus the original message would have been:  _\"My motto's always been: \"Ars gratia artis\".\"_ .  Eight of the 37 characters have been matched: \"My\", \"\u0026#x200A;'s\u0026#x200A;\", and \"been\".  Note carefully that:  \"\u0026#x200A;'s\u0026#x200A;\" should only be matched once;  \"to\" (in motto), \"be\" (in been), \"at\" (in gratia), \"is\" (in artis) and \"a\" (passim) should _not_ be matched at all;  and \"\u0026#x200A;'\u0026#x200A;\" will only ever be used as an apostrophe (never as a quotation mark).  \r\n\r\nThe correct answer would therefore comprise:  \r\n\r\n  s.shift = uint8(2)  \r\n  s.message = {'My motto''s always been: \"Ars gratia artis\".'}\r\n  s.certitude = uint8(73)\r\n\r\nIf the batch of messages cannot be decoded when following the above assumptions, then return the original encoded message(s) unchanged, with a shift of zero and a certitude of zero.  \r\n\r\n|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.)|  \r\n\r\nTo 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\".  \r\n\r\n----------\r\n\r\nPrevious problem:  \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44356 Operation Orthos\u003e.  Next problem:  TBA.","description_html":"\u003cp\u003eYou have been tasked with decoding several batches of coded messages that have been intercepted.\u003c/p\u003e\u003cp\u003eBased on previous intelligence that has been gathered, you can be confident that the messages were all encoded using a simple \u003ca href = \"https://en.wikipedia.org/wiki/Caesar_cipher\"\u003eCaesar cipher\u003c/a\u003e (a type of \u003ca href = \"https://en.wikipedia.org/wiki/Substitution_cipher\"\u003esubstitution cipher\u003c/a\u003e), an example of which is the \u003ca href = \"https://en.wikipedia.org/wiki/ROT13\"\u003eROT13 cipher\u003c/a\u003e (discussed in \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher\"\u003eCody Challenge Problem 78\u003c/a\u003e).  As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation, numbers, accented letters) are unchanged.  Unlike the Cody Challenge Problem, here the number of letters to shift is not known in advance, and will vary \u003ci\u003ebetween\u003c/i\u003e (not within) batches — also, here you need to decode, not encode.\u003c/p\u003e\u003cp\u003eThese latest activities that you are investigating have been nicknamed 'Operation Xiangliu' by your own organisation.  A few decoding options are at your organisation's disposal:\u003c/p\u003e\u003col\u003e\u003cli\u003eTest the candidate decodings against all words in a large dictionary — this could work, but it is very slow.\u003c/li\u003e\u003cli\u003eTest the candidate decodings for the appearance of a name or phrase that is certain to appear regularly (e.g. \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44351\"\u003e\"Operation Phoenix\"\u003c/a\u003e) — unfortunately as yet there is not enough knowledge of the activities to be sure of a suitable name or phrase to use.\u003c/li\u003e\u003cli\u003eTest the candidate decodings against all words in a short list comprising, say, the hundred most frequently used English words.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eThe \u003cb\u003ethird option\u003c/b\u003e will be faster than the first option, and more reliable than the second option, so this is the approach you will be taking.\u003c/p\u003e\u003cp\u003eYou have been careful to avoid using 'lemmatised' lists (which contain e.g. the verb \"to be\", rather than the various inflected forms such as \"am\", \"is\", \"are\") like those based on the \u003ca href = \"https://web.archive.org/web/20111226085859/http://oxforddictionaries.com/words/the-oec-facts-about-the-language\"\u003eOEC\u003c/a\u003e or \u003ca href = \"https://www.wordfrequency.info/free.asp?s=y\"\u003eCOCA\u003c/a\u003e, and after setting aside \u003ca href = \"http://world-english.org/english500.htm\"\u003eanother list\u003c/a\u003e you finally choose the \u003ca href = \"http://ucrel.lancs.ac.uk/bncfreq/samples/120.pdf\"\u003elist based on the BNC\u003c/a\u003e as the most reliable, and will use the first 100 words on that list.  \r\nThis list will be available for you to access as an input variable, \u003ctt\u003ebncWordlist\u003c/tt\u003e, to your function. Note: (i) some entries on the list are morphemes (e.g. \"\u0026#x200A;n't\u0026#x200A;\" and \"\u0026#x200A;'s\u0026#x200A;\") rather than words;  (ii) some entries appear more than once (representing different grammatical word classes).  Of course, in the original messages any capitalisation might be used.\u003c/p\u003e\u003cp\u003eYou have been instructed that your 'certitude' (degree of confidence) in the decoding must be reported for each batch, and shall depend proportionally upon the sum of the characters for the words/morphemes in the decoded message that match words/morphemes in \u003ctt\u003ebncWordlist\u003c/tt\u003e.  Being able to match words/morphemes accounting for three-tenths of the characters (excluding spaces) shall correspond to 100% certitude;  matching three-twentieths would be 50% certitude, and so on.  Certitude shall be reported as a percentage, rounded \u003ci\u003eup\u003c/i\u003e to the nearest integer, not greater than 100.  You need to maximise your certitude for each batch by appropriate choice of the shifting parameter.   If there are multiple shifts of equal certitude, report both options on different rows (arranged in order of ascending shift parameter).\u003c/p\u003e\u003cp\u003eYour task is to crack the codes and report back in a \u003ca href = \"http://au.mathworks.com/help/matlab/ref/struct.html\"\u003estructure array\u003c/a\u003e: \u0026nbsp; (1) the shifting parameter that had been used in the encoding [as \u003ca href = \"http://au.mathworks.com/help/matlab/ref/uint8.html\"\u003euint8\u003c/a\u003e] (usually scalar, but may be column vector); \u0026nbsp; (2) the decoded messages [as a \u003ca href = \"http://au.mathworks.com/help/matlab/ref/cell.html?s_tid=doc_ta\"\u003ecell array\u003c/a\u003e (containing \u003ca href = \"http://au.mathworks.com/help/matlab/ref/char.html\"\u003echaracter arrays\u003c/a\u003e)] (usually an array with a single row, but occasionally with multiple rows); \u0026nbsp; (3) your 'certitude' in the decoding [as \u003ca href = \"http://au.mathworks.com/help/matlab/ref/uint8.html\"\u003euint8\u003c/a\u003e] (always scalar).  \r\nThe name of the structure array shall be \u003ctt\u003es\u003c/tt\u003e, with respective fields \u003ctt\u003eshift\u003c/tt\u003e, \u003ctt\u003emessage\u003c/tt\u003e, and \u003ctt\u003ecertitude\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003e\u003cb\u003eEXAMPLE 1\u003c/b\u003e\u003c/p\u003e\u003cp\u003eSuppose the batch contained two encoded messages — \u003ci\u003e\"Vomftt qvstvfe, pqfo op eppst.\"\u003c/i\u003e and \u003ci\u003e\"Ffmt dbo ljmm, opu pomz xpvoe.\"\u003c/i\u003e (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.  \r\nThus the original messages would have been:  \u003ci\u003e\"Unless pursued, open no doors.\"\u003c/i\u003e and \u003ci\u003e\"Eels can kill, not only wound.\"\u003c/i\u003e .  Twelve of the 51 characters have been matched:  \"no\", \"can\", \"not\", and \"only\".\u003c/p\u003e\u003cp\u003eThe correct answer would therefore comprise:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003es.shift = uint8(1)  \r\ns.message = {'Unless pursued, open no doors.', 'Eels can kill, not only wound.'}\r\ns.certitude = uint8(79)\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eEXAMPLE 2\u003c/b\u003e\u003c/p\u003e\u003cp\u003eSuppose the batch contained one encoded message — \u003ci\u003e\"Oa oqvvq'u cnycau dggp: \"Ctu itcvkc ctvku\".\"\u003c/i\u003e (provided as a character array within a cell array) — and a (right-shifting) ROT2 cipher had been applied.  In that case A→C, B→D, ..., Y→A, and Z→B;  similarly, a→c, b→d, ..., y→a, and z→b.  \r\nThus the original message would have been:  \u003ci\u003e\"My motto's always been: \"Ars gratia artis\".\"\u003c/i\u003e .  Eight of the 37 characters have been matched: \"My\", \"\u0026#x200A;'s\u0026#x200A;\", and \"been\".  Note carefully that:  \"\u0026#x200A;'s\u0026#x200A;\" should only be matched once;  \"to\" (in motto), \"be\" (in been), \"at\" (in gratia), \"is\" (in artis) and \"a\" (passim) should \u003ci\u003enot\u003c/i\u003e be matched at all;  and \"\u0026#x200A;'\u0026#x200A;\" will only ever be used as an apostrophe (never as a quotation mark).\u003c/p\u003e\u003cp\u003eThe correct answer would therefore comprise:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003es.shift = uint8(2)  \r\ns.message = {'My motto''s always been: \"Ars gratia artis\".'}\r\ns.certitude = uint8(73)\r\n\u003c/pre\u003e\u003cp\u003eIf the batch of messages cannot be decoded when following the above assumptions, then return the original encoded message(s) unchanged, with a shift of zero and a certitude of zero.\u003c/p\u003e\u003cp\u003e\u003ctt\u003eNote:  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.)\u003c/tt\u003e\u003c/p\u003e\u003cp\u003eTo 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\".\u003c/p\u003e\u003cp\u003e----------\u003c/p\u003e\u003cp\u003ePrevious problem:  \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44356\"\u003eOperation Orthos\u003c/a\u003e.  Next problem:  TBA.\u003c/p\u003e","function_template":"% Comments are nice, aren't they....\r\nfunction s = decode(x, bncWordlist)\r\nend","test_suite":"%% NOTE:  \r\n% This test suite can be updated if inappropriate 'hacks' \r\n% are discovered in any submitted solutions.\r\n% The assessment of your submission may therefore change over time.  \r\n\r\nglobal bncWordlist\r\nbncWordlist = {'the', 'of', 'and', 'a', 'in', 'to', 'it', 'is', 'to', 'was', ...\r\n    'I', 'for', 'that', 'you', 'he', 'be', 'with', 'on', 'by', 'at', ...\r\n    'have', 'are', 'not', 'this', '''s', 'but', 'had', 'they', 'his', ...\r\n    'from', 'she', 'that', 'which', 'or', 'we', '''s', 'an', 'n''t', 'were', ...\r\n    'as', 'do', 'been', 'their', 'has', 'would', 'there', 'what', 'will', 'all', ...\r\n    'if', 'can', 'her', 'said', 'who', 'one', 'so', 'up', 'as', 'them', 'some', ...\r\n    'when', 'could', 'him', 'into', 'its', 'then', 'two', 'out', 'time', ...\r\n    'my', 'about', 'did', 'your', 'now', 'me', 'no', 'other', 'only', 'just', ...\r\n    'more', 'these', 'also', 'people', 'know', 'any', 'first', 'see', 'very', 'new', ...\r\n    'may', 'well', 'should', 'her', 'like', 'than', 'how', 'get', 'way', 'one', 'our'};\r\n\r\n\r\n%% Anti-hacking\r\n% EDIT (2019-07-02). Anti-hacking provision\r\n% Ensure only builtin functions will be called.\r\n! rm -v fileread.m\r\n! rm -v assert.m\r\n% END EDIT (2019-07-02)\r\n% EDIT (2018-06-18).  Anti-hacking provision\r\nRE = regexp(fileread('decode.m'), '\\w+', 'match');\r\ntabooWords = {'ans', 'assert', 'freepass', 'tic'};\r\ntestResult = cellfun( @(z) ismember(z, tabooWords), RE );\r\nmsg = ['Please do not do that in your code!' char([10 13]) ...\r\n    'Found: ' strjoin(RE(testResult)) '.' char([10 13]) ...\r\n    'Banned word.' char([10 13])];\r\nassert(~any(  cellfun( @(z) ismember(z, tabooWords), RE )  ), msg)\r\n\r\nfor j = 1 : randi(10)\r\n    decode({'Pizza for dinner.'}, {'mozzarella', 'mushrooms'});\r\nend;\r\n% END EDIT (2018-06-18)\r\n\r\n\r\n%% Test 1\r\nglobal bncWordlist\r\nx =                 {'Vomftt qvstvfe, pqfo op eppst.', 'Ffmt dbo ljmm, opu pomz xpvoe.'};\r\ns_correct.shift = uint8(1);\r\ns_correct.message = {'Unless pursued, open no doors.', 'Eels can kill, not only wound.'};\r\ns_correct.certitude = uint8(79);\r\ns = decode(x, bncWordlist);\r\n%disp(' *** ');  disp(s.message);  disp(' *** ')\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.' )\r\nassert( isequal(s.message{1}, s_correct.message{1}), 'Wrong message{1}.' )\r\nassert( isequal(s.message{2}, s_correct.message{2}), 'Wrong message{2}.' )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.' )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.' )\r\nassert( isequal(s, s_correct), 'Wrong s.' )\r\nassert( isequal(class(s.shift), 'uint8'), 'Wrong class.' )\r\nassert( isequal(class(s.message), 'cell'), 'Wrong class.'  )\r\nassert( isequal(class(s.message{1}), 'char'), 'Wrong class.'  )\r\nassert( isequal(class(s.certitude), 'uint8'), 'Wrong class.'  )\r\n\r\n\r\n%% Test 2\r\nglobal bncWordlist\r\nx =                 {'Doo zduiduh lv edvhg rq ghfhswlrq.', ...\r\n    'Khqfh, zkhq deoh wr dwwdfn, zh pxvw vhhp xqdeoh;  zkhq xvlqj rxu irufhv, zh pxvw vhhp lqdfwlyh;  zkhq zh duh qhdu, zh pxvw pdnh wkh hqhpb eholhyh zh duh idu dzdb; zkhq idu dzdb, zh pxvw pdnh klp eholhyh zh duh qhdu.'};\r\ns_correct.shift = uint8(3);\r\ns_correct.message = {'All warfare is based on deception.', ...\r\n    'Hence, when able to attack, we must seem unable;  when using our forces, we must seem inactive;  when we are near, we must make the enemy believe we are far away; when far away, we must make him believe we are near.'};\r\ns_correct.certitude = uint8(95);\r\ns = decode(x, bncWordlist);\r\n%disp(' *** ');  disp(s.message);  disp(' *** ')\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% Test 3\r\nglobal bncWordlist\r\nx =                 {'Elia lrq yxfqp ql bkqfzb qeb bkbjv.  Cbfdk afploabo, xka zorpe efj.', ...\r\n    'Fc eb fp pbzrob xq xii mlfkqp, yb mobmxoba clo efj.  Fc eb fp fk prmboflo pqobkdqe, bsxab efj.'};\r\ns_correct.shift = uint8(23);\r\ns_correct.message = {'Hold out baits to entice the enemy.  Feign disorder, and crush him.', ...\r\n    'If he is secure at all points, be prepared for him.  If he is in superior strength, evade him.'};\r\ns_correct.certitude = uint8(100);\r\ns = decode(x, bncWordlist);\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% Test 4\r\nglobal bncWordlist\r\nx =                 {'Ax qgmj ghhgfwfl ak gx uzgdwjau lwehwj, kwwc lg ajjalslw zae.  Hjwlwfv lg tw owsc, lzsl zw esq yjgo sjjgysfl.', ...\r\n    'Ax zw ak lscafy zak wskw, yanw zae fg jwkl.', ...\r\n    'Ax zak xgjuwk sjw mfalwv, kwhsjslw lzwe.', ...\r\n    'Sllsuc zae ozwjw zw ak mfhjwhsjwv, shhwsj ozwjw qgm sjw fgl wphwulwv.'};\r\ns_correct.shift = uint8(18);\r\ns_correct.message = {'If your opponent is of choleric temper, seek to irritate him.  Pretend to be weak, that he may grow arrogant.', ...\r\n    'If he is taking his ease, give him no rest.', ...\r\n    'If his forces are united, separate them.', ...\r\n    'Attack him where he is unprepared, appear where you are not expected.'};\r\ns_correct.certitude = uint8(100);\r\ns = decode(x, bncWordlist);\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% Test 5\r\nglobal bncWordlist\r\nx =                 {'Aes cèwo vo foxd bémyvdo vo dowzy', ...\r\n    'Yx wo dbksdo no dbkîdbo aekxn to dbksdo no vk népksdo ne csvoxmo / Vo csvoxmo ocd n''yb, wksc t''ks mryscs vk mknoxmo', ... \r\n    'Mrkaeo wyd, mrkaeo zrbkco nsdc kfom owzrkco / Pksd no Mvkeno WM, vo mywwkxny no vk zrbkco', ...\r\n    'Mkb t''cesc ex WM n''kddkaeo, ckxc dsmc, kedroxdsaeo zkc ox dym / Zbêd à pbkzzob ceb vo lokd zyeb vo wyefowoxd rsz-ryz', ...\r\n    'Ne bkz n''kddkaeo aes pbkzzo, ézkdo, wkdbkaeo od zkdkdbkaeo / Zvec no ckxq de mvkaeoc, t''cesc WM noc Mkbzkdoc', ...\r\n    'Vo zénkqyqeo ox fyqeo ke xyw no myno Cyvkkb ye Mvkeno WM / Do zbyzyco n''émyedob moms / Ae''yx ézovvo voc fyiovvoc, nèc ae''yx cyxxo voc myxcyxxoc'};\r\ns_correct.shift = uint8([0 21]');\r\n% TIP:  The original message was not English!\r\ns_correct.message(1, :) = {'Aes cèwo vo foxd bémyvdo vo dowzy', ... \r\n    'Yx wo dbksdo no dbkîdbo aekxn to dbksdo no vk népksdo ne csvoxmo / Vo csvoxmo ocd n''yb, wksc t''ks mryscs vk mknoxmo', ... \r\n    'Mrkaeo wyd, mrkaeo zrbkco nsdc kfom owzrkco / Pksd no Mvkeno WM, vo mywwkxny no vk zrbkco', ... \r\n    'Mkb t''cesc ex WM n''kddkaeo, ckxc dsmc, kedroxdsaeo zkc ox dym / Zbêd à pbkzzob ceb vo lokd zyeb vo wyefowoxd rsz-ryz', ... \r\n    'Ne bkz n''kddkaeo aes pbkzzo, ézkdo, wkdbkaeo od zkdkdbkaeo / Zvec no ckxq de mvkaeoc, t''cesc WM noc Mkbzkdoc', ... \r\n    'Vo zénkqyqeo ox fyqeo ke xyw no myno Cyvkkb ye Mvkeno WM / Do zbyzyco n''émyedob moms / Ae''yx ézovvo voc fyiovvoc, nèc ae''yx cyxxo voc myxcyxxoc'}\r\ns_correct.message(2, :) = {'Fjx hèbt at ktci gérdait at itbed', ... \r\n    'Dc bt igpxit st igpîigt fjpcs yt igpxit st ap séupxit sj hxatcrt / At hxatcrt thi s''dg, bpxh y''px rwdxhx ap rpstcrt', ... \r\n    'Rwpfjt bdi, rwpfjt ewgpht sxih pktr tbewpht / Upxi st Rapjst BR, at rdbbpcsd st ap ewgpht', ... \r\n    'Rpg y''hjxh jc BR s''piipfjt, hpch ixrh, pjiwtcixfjt eph tc idr / Egêi à ugpeetg hjg at qtpi edjg at bdjktbtci wxe-wde', ... \r\n    'Sj gpe s''piipfjt fjx ugpeet, éepit, bpigpfjt ti epipigpfjt / Eajh st hpcv ij rapfjth, y''hjxh BR sth Rpgepith', ... \r\n    'At eéspvdvjt tc kdvjt pj cdb st rdst Hdappg dj Rapjst BR / It egdedht s''érdjitg rtrx / Fj''dc éetaat ath kdntaath, sèh fj''dc hdcct ath rdchdccth'}\r\ns_correct.certitude = uint8(11);\r\ns = decode(x, bncWordlist);\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% Test 6\r\nglobal bncWordlist\r\nx =                 {'Brvdujcnm mrbxamna yxbcdujcnb ynaonlc mrblryurwn;  brvdujcnm onja yxbcdujcnb lxdajpn;  brvdujcnm fnjtwnbb yxbcdujcnb bcanwpcq.' ...\r\n    'X mrerwn jac xo bdkcunch jwm bnlanlh!'};\r\ns_correct.shift = uint8(9);\r\ns_correct.message = {'Simulated disorder postulates perfect discipline;  simulated fear postulates courage;  simulated weakness postulates strength.' ...\r\n    'O divine art of subtlety and secrecy!'};\r\ns_correct.certitude = uint8(12);\r\ns = decode(x, bncWordlist);\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% Test 7\r\nglobal bncWordlist\r\nx =                 {'Nv treefk vekvi zekf rcczretv nzky evzxysfizex gizetvj lekzc nv riv rthlrzekvu nzky kyvzi uvjzxej.', ... \r\n    'Nv riv efk wzk kf cvru re ridp fe kyv drity lecvjj nv riv wrdzczri nzky kyv wrtv fw kyv tflekip — zkj dflekrzej reu wfivjkj, zkj gzkwrccj reu givtzgztvj, zkj drijyvj reu jnrdgj.', ... \r\n    'Nv jyrcc sv lerscv kf klie erklirc rumrekrxvj kf rttflek lecvjj nv drbv ljv fw cftrc xlzuvj.'};\r\ns_correct.shift = uint8(17);\r\ns_correct.message = {'We cannot enter into alliance with neighboring princes until we are acquainted with their designs.', ...  \r\n    'We are not fit to lead an army on the march unless we are familiar with the face of the country — its mountains and forests, its pitfalls and precipices, its marshes and swamps.', ...  \r\n    'We shall be unable to turn natural advantages to account unless we make use of local guides.'};\r\ns_correct.certitude = uint8(97);\r\ns = decode(x, bncWordlist);\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% Test 8\r\nglobal bncWordlist\r\nx =                 {'Oa oqvvq''u cnycau dggp: \"Ctu itcvkc ctvku\".'};\r\ns_correct.shift = uint8(2);\r\ns_correct.message = {'My motto''s always been: \"Ars gratia artis\".'};\r\ns_correct.certitude = uint8(73);\r\ns = decode(x, bncWordlist);\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% Test 9\r\nglobal bncWordlist\r\nx =                 {'Bestow rewards without regard 2 rule;  issue orders without regard 2 previous arrangements', ...\r\n    '\"Let advance bee richly rewarded \u0026 retreat bee heavily punished.\"', ...\r\n    ' Qwertyuiop''asdfghjkl.   Zxcvbnm-0123456789 = pass. ', ...\r\n    'αβγδ — persimon–apricot hybrid.', ...\r\n    'aIanasatbebydoheifinisitmemynoofonor''ssotoupweallandanyarebutcandidforgethadhasherhimhishowitsmaynewnotnown''toneouroutseeshethetwowaswaywhoyoualsobeenfromhaveintojustknowlikemoreonlysaidsomethanthatthemthentheythistimeverywellwerewhatwhenwillwithyouraboutcouldfirstothertheirtherethesewhichwouldpeopleshould'};\r\ns_correct.shift = uint8(0);\r\ns_correct.message = x;\r\ns_correct.certitude = uint8(0);\r\ns = decode(x, bncWordlist);\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% TIMING \r\n% Note:  The Time Trial section does not check accuracy; that is done above.\r\n\r\n% Acknowledgements  \r\n% Portions of this timing test code were inspired by:\r\n% (1) Problem 937. \"Rubik's Mini Cube: Solve Randomized Cube in 11 Moves or Less; Score is by Time (msec)\" by Richard Zapor.\r\n% (2) Problem 2733. \"Evil Number\" by Jan Orwat.\r\n% (3) Feedback in comments from Peng Liu.\r\n% (4) Problem Problem 1237. \"It's race time! Write a faster function than the test suite call of unique().\" by Jeremy.\r\n\r\n% INITIALISE\r\nglobal bncWordlist\r\nx =                 {'Vomftt qvstvfe, pqfo op eppst.', 'Ffmt dbo ljmm, opu pomz xpvoe.'};\r\nqSmall = 50;\r\nqBig = 1000;\r\n%cutoffTimeBig = 10;    % Maximum allowable walltime (in seconds) to run function in a loop with qBig iterations.\r\n\r\n% EDIT (2018-06-17).  Reduced time [slightly] to pose reasonable challenge.\r\n% Accounted for improving Cody server speed per Problem 44655.\r\ncutoffTimeBig = 8;    % Maximum allowable walltime (in seconds) to run function in a loop with qBig iterations.\r\ntRef = datetime('2018-06-17', 'InputFormat','yyyy-MM-dd');\r\ntNow = datetime('now');\r\nyearsElapsed = (datenum(tNow) - datenum(tRef)) / 365.24;\r\ndisp(' . ');\r\nfprintf('\\r\\n\\r\\n\\r\\nSubmission evaluated for speed on %s.\\r\\n', datestr(tNow, 'dd mmmm yyyy'))\r\nrInf = 0.2;   delta = cutoffTimeBig - rInf;  tau = 3.6;  % Data from Problem 44655, based on Problem 963.\r\nqBig = ceil( qBig * (cutoffTimeBig - rInf) * exp(yearsElapsed/tau) / delta );\r\nfprintf('\\r\\n\\r\\n\\r\\nTo account for computational power increases over time, number of iterations increased to %u.\\r\\n', qBig)\r\n% END EDIT (2018-06-17)\r\n\r\n\r\n% *** PRELIMINARY TIMING WITH timeit ***\r\nfDecode = @()   decode(x, bncWordlist);\r\ndt_timeit = timeit( fDecode );\r\nfor dummy = 1 : 10,  disp(' . ');  end;\r\nfprintf('APPROXIMATE time to decode %u message batches ~ %2.2f seconds, according to ''timeit''.\\n\\r', qBig, dt_timeit * qBig)\r\n\r\n% *** PRELIMINARY TIMING WITH SHORT LOOP ***\r\n% In case the submitted function has a lot of text output, \r\n% get an estimate based on just a few iterations\r\n% Initialise\r\nt0 = clock;\r\n\r\n% Loop\r\nfor i = 1 : qSmall\r\n    solution = decode(x, bncWordlist);\r\nend;\r\n\r\n% Compute and display elapsed time.\r\ndt = etime(clock, t0);\r\nfor dummy = 1 : 10,  disp(' . ');  end;\r\n%fprintf('Your wall time to decode %u message batches = %i seconds.\\n\\r', qSmall, floor(dt))\r\nfprintf('APPROXIMATE wall time to decode %u message batches ~ %2.2f seconds, by extrapolating from %u batches.\\n\\r', qBig, dt * qBig / qSmall, qSmall)\r\n\r\n% *** 'OFFICIAL' TIMING ***\r\n% Re-initialise timer\r\nt0 = clock;\r\nt0_cpu = cputime;\r\n\r\n% Loop\r\nfor i = 1 : qBig\r\n    % EDIT (2018-06-17).   Ensure each case is unique.\r\n    characters = ['  ,   .' char(randi([97,122], [1,23]))];\r\n    x{2} = characters( randperm(30) );\r\n    % END EDIT (2018-06-17)\r\n    solution = decode(x, bncWordlist);\r\nend;\r\n\r\n% Compute and display elapsed time.\r\ndt = etime(clock, t0);\r\nfor dummy = 1 : 10,  disp(' . ');  end;\r\nfprintf('Your wall time to decode %u message batches = %2.2f seconds.\\n\\r', qBig, dt)\r\n\r\ndt_cpu = (cputime - t0_cpu);\r\nfprintf(' ( Your CPU time for this = %2.2f seconds. ) \\n\\r', dt_cpu)\r\n\r\n% Display (default) Cody size-based score.\r\nall_nodes = mtree('decode.m', '-file');\r\nsize_score = count(all_nodes);\r\nfprintf('Your Cody-standard size-based score = %i.\\n\\r', size_score)\r\n\r\n% Report revised performance score\r\ncombinedScore = size_score + round(dt * 10);\r\nfprintf('Your combined score = %i.\\n\\r', combinedScore)\r\ndisp('     -----=====|||||=====-----     ')\r\n\r\n% Now disallow any candidate solutions that are TOO SLOW!\r\nif dt \u003e cutoffTimeBig, \r\n    fprintf('Sorry, your submission is TOO SLOW.  It must be able to finish within %u seconds.\\n\\r', cutoffTimeBig)\r\nend;\r\n\r\nassert( dt \u003c= cutoffTimeBig, 'Exceeded time limit specified in Test Suite.' )","published":true,"deleted":false,"likes_count":2,"comments_count":16,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":13,"test_suite_updated_at":"2019-07-02T13:23:18.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2017-10-12T23:17:24.000Z","updated_at":"2026-04-02T20:05:58.000Z","published_at":"2017-10-15T06:52:40.000Z","restored_at":"2017-10-25T07:03:11.000Z","restored_by":null,"spam":false,"simulink":false,"admin_reviewed":true,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have been tasked with decoding several batches of coded messages that have been intercepted.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBased on previous intelligence that has been gathered, you can be confident that the messages were all encoded using a simple\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Caesar_cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCaesar cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (a type of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Substitution_cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esubstitution cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e), an example of which is the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/ROT13\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eROT13 cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (discussed in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody Challenge Problem 78\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e). As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation, numbers, accented letters) are unchanged. Unlike the Cody Challenge Problem, here the number of letters to shift is not known in advance, and will vary\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ebetween\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (not within) batches — also, here you need to decode, not encode.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThese latest activities that you are investigating have been nicknamed 'Operation Xiangliu' by your own organisation. A few decoding options are at your organisation's disposal:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTest the candidate decodings against all words in a large dictionary — this could work, but it is very slow.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTest the candidate decodings for the appearance of a name or phrase that is certain to appear regularly (e.g.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44351\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\\\"Operation Phoenix\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e) — unfortunately as yet there is not enough knowledge of the activities to be sure of a suitable name or phrase to use.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTest the candidate decodings against all words in a short list comprising, say, the hundred most frequently used English words.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ethird option\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e will be faster than the first option, and more reliable than the second option, so this is the approach you will be taking.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have been careful to avoid using 'lemmatised' lists (which contain e.g. the verb \\\"to be\\\", rather than the various inflected forms such as \\\"am\\\", \\\"is\\\", \\\"are\\\") like those based on the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://web.archive.org/web/20111226085859/http://oxforddictionaries.com/words/the-oec-facts-about-the-language\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOEC\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e or\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.wordfrequency.info/free.asp?s=y\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCOCA\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, and after setting aside\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://world-english.org/english500.htm\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eanother list\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e you finally choose the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://ucrel.lancs.ac.uk/bncfreq/samples/120.pdf\\\"\u003e\u003cw:r\u003e\u003cw:t\u003elist based on the BNC\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e as the most reliable, and will use the first 100 words on that list. This list will be available for you to access as an input variable,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ebncWordlist\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, to your function. Note: (i) some entries on the list are morphemes (e.g. \\\" n't \\\" and \\\" 's \\\") rather than words; (ii) some entries appear more than once (representing different grammatical word classes). Of course, in the original messages any capitalisation might be used.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have been instructed that your 'certitude' (degree of confidence) in the decoding must be reported for each batch, and shall depend proportionally upon the sum of the characters for the words/morphemes in the decoded message that match words/morphemes in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ebncWordlist\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Being able to match words/morphemes accounting for three-tenths of the characters (excluding spaces) shall correspond to 100% certitude; matching three-twentieths would be 50% certitude, and so on. Certitude shall be reported as a percentage, rounded\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eup\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to the nearest integer, not greater than 100. You need to maximise your certitude for each batch by appropriate choice of the shifting parameter. If there are multiple shifts of equal certitude, report both options on different rows (arranged in order of ascending shift parameter).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour task is to crack the codes and report back in a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/struct.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003estructure array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e: (1) the shifting parameter that had been used in the encoding [as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/uint8.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003euint8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e] (usually scalar, but may be column vector); (2) the decoded messages [as a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/cell.html?s_tid=doc_ta\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ecell array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (containing\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/char.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003echaracter arrays\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e)] (usually an array with a single row, but occasionally with multiple rows); (3) your 'certitude' in the decoding [as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/uint8.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003euint8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e] (always scalar). The name of the structure array shall be\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, with respective fields\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eshift\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emessage\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecertitude\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eEXAMPLE 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose the batch contained two encoded messages —\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Vomftt qvstvfe, pqfo op eppst.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Ffmt dbo ljmm, opu pomz xpvoe.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (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. Thus the original messages would have been: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Unless pursued, open no doors.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Eels can kill, not only wound.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e . Twelve of the 51 characters have been matched: \\\"no\\\", \\\"can\\\", \\\"not\\\", and \\\"only\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe correct answer would therefore comprise:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[s.shift = uint8(1)  \\ns.message = {'Unless pursued, open no doors.', 'Eels can kill, not only wound.'}\\ns.certitude = uint8(79)]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eEXAMPLE 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose the batch contained one encoded message —\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Oa oqvvq'u cnycau dggp: \\\"Ctu itcvkc ctvku\\\".\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (provided as a character array within a cell array) — and a (right-shifting) ROT2 cipher had been applied. In that case A→C, B→D, ..., Y→A, and Z→B; similarly, a→c, b→d, ..., y→a, and z→b. Thus the original message would have been: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"My motto's always been: \\\"Ars gratia artis\\\".\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e . Eight of the 37 characters have been matched: \\\"My\\\", \\\" 's \\\", and \\\"been\\\". Note carefully that: \\\" 's \\\" should only be matched once; \\\"to\\\" (in motto), \\\"be\\\" (in been), \\\"at\\\" (in gratia), \\\"is\\\" (in artis) and \\\"a\\\" (passim) should\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enot\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e be matched at all; and \\\" ' \\\" will only ever be used as an apostrophe (never as a quotation mark).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe correct answer would therefore comprise:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[s.shift = uint8(2)  \\ns.message = {'My motto''s always been: \\\"Ars gratia artis\\\".'}\\ns.certitude = uint8(73)]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf the batch of messages cannot be decoded when following the above assumptions, then return the original encoded message(s) unchanged, with a shift of zero and a certitude of zero.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNote: 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.)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo 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\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e----------\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44356\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOperation Orthos\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem: TBA.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":751,"title":"Implement simple rotation cypher","description":"If given a letter from the set:\r\n\r\n  [abc...xyz]\r\n\r\nand a shift, implement a shift cypher.\r\n\r\nExample:\r\n\r\n  'abc' \r\n\r\nwith a shift of -1 yields\r\n\r\n  'zab'\r\n\r\n\r\n\r\n\r\n","description_html":"\u003cp\u003eIf given a letter from the set:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[abc...xyz]\r\n\u003c/pre\u003e\u003cp\u003eand a shift, implement a shift cypher.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e'abc' \r\n\u003c/pre\u003e\u003cp\u003ewith a shift of -1 yields\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e'zab'\r\n\u003c/pre\u003e","function_template":"function outStr = cypher(inStr, shift)\r\n  outStr = inStr;\r\nend","test_suite":"%%\r\ninStr = 'doug';\r\nshift = 10;\r\noutStr = 'nyeq';\r\n\r\nassert(isequal(cypher(inStr, shift),outStr))\r\n\r\n%%\r\ninStr = 'thequickbrownfox';\r\nshift = 5;\r\noutStr = 'ymjvznhpgwtbsktc';\r\n\r\nassert(isequal(cypher(inStr, shift),outStr))\r\n\r\n%%\r\ninStr = 'thecrowfliesatmidnight';\r\nshift = 22;\r\noutStr = 'pdaynksbheaowpiezjecdp';\r\n\r\nassert(isequal(cypher(inStr, shift),outStr))","published":true,"deleted":false,"likes_count":13,"comments_count":2,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1096,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":6,"created_at":"2012-06-06T15:38:43.000Z","updated_at":"2026-02-19T13:12:57.000Z","published_at":"2012-06-08T19:08:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf given a letter from the set:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[[abc...xyz]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eand a shift, implement a shift cypher.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA['abc']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ewith a shift of -1 yields\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA['zab']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44351,"title":"Code breaker, Part I:  Operation Phoenix","description":"You have been tasked with decoding a set of coded messages that have been intercepted.  \r\n\r\nBased on previous intelligence that has been gathered, you can be confident that the messages were encoded using a simple \u003chttps://en.wikipedia.org/wiki/Caesar_cipher Caesar cipher\u003e (a type of \u003chttps://en.wikipedia.org/wiki/Substitution_cipher substitution cipher\u003e), an example of which is the \u003chttps://en.wikipedia.org/wiki/ROT13 ROT13 cipher\u003e (discussed in \u003chttps://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher Cody Challenge Problem 78\u003e).  As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation \u0026 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).  \r\n\r\nYou 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.  \r\n\r\nYour task is to crack the codes and report back in a \u003chttp://au.mathworks.com/help/matlab/ref/struct.html structure array\u003e:  (1) the shifting parameter that had been used in the encoding [as \u003chttp://au.mathworks.com/help/matlab/ref/uint8.html uint8\u003e];  (2)  the decoded message [as \u003chttp://au.mathworks.com/help/matlab/ref/char.html character array\u003e].  \r\nThe name of the structure array shall be \"s\", with respective fields \"shift\" and \"message\".  \r\n\r\nEXAMPLE\r\n\r\nSuppose the original message was _\"Cancel Operation Phoenix immediately \u0026 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.)  \r\nThus the encoded message would be:  _\"Dbodfm Pqfsbujpo Qipfojy jnnfejbufmz \u0026 ftdbqf.\"_\r\n\r\nThe correct answer would comprise:  \r\n\r\n  s.shift = uint8(1)  \r\n  s.message = 'Cancel Operation Phoenix immediately \u0026 escape.'\r\n\r\n|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.|  \r\n\r\nTo 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\".\r\n\r\n----------\r\n\r\nNext problem:  \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44356 Operation Orthos\u003e.\r\n\r\n----------\r\n\r\nStatistics on solutions submitted as at 15 October 2017:\r\n\r\n* *Fastest wall time to decode 5000 messages = 93 milliseconds* , for \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1279303 Solution 1279303\u003e, with a size-based score of 40. \r\n* *Smallest size-based score = 38* , for \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1278780 Solution 1278780\u003e, for which wall time to decode 5000 messages = 515 milliseconds.  \r\n* Best combined score = 49, for \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1279303 Solution 1279303\u003e. ","description_html":"\u003cp\u003eYou have been tasked with decoding a set of coded messages that have been intercepted.\u003c/p\u003e\u003cp\u003eBased on previous intelligence that has been gathered, you can be confident that the messages were encoded using a simple \u003ca href = \"https://en.wikipedia.org/wiki/Caesar_cipher\"\u003eCaesar cipher\u003c/a\u003e (a type of \u003ca href = \"https://en.wikipedia.org/wiki/Substitution_cipher\"\u003esubstitution cipher\u003c/a\u003e), an example of which is the \u003ca href = \"https://en.wikipedia.org/wiki/ROT13\"\u003eROT13 cipher\u003c/a\u003e (discussed in \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher\"\u003eCody Challenge Problem 78\u003c/a\u003e).  As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation \u0026 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).\u003c/p\u003e\u003cp\u003eYou 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.\u003c/p\u003e\u003cp\u003eYour task is to crack the codes and report back in a \u003ca href = \"http://au.mathworks.com/help/matlab/ref/struct.html\"\u003estructure array\u003c/a\u003e:  (1) the shifting parameter that had been used in the encoding [as \u003ca href = \"http://au.mathworks.com/help/matlab/ref/uint8.html\"\u003euint8\u003c/a\u003e];  (2)  the decoded message [as \u003ca href = \"http://au.mathworks.com/help/matlab/ref/char.html\"\u003echaracter array\u003c/a\u003e].  \r\nThe name of the structure array shall be \"s\", with respective fields \"shift\" and \"message\".\u003c/p\u003e\u003cp\u003eEXAMPLE\u003c/p\u003e\u003cp\u003eSuppose the original message was \u003ci\u003e\"Cancel Operation Phoenix immediately \u0026 escape.\"\u003c/i\u003e 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.)  \r\nThus the encoded message would be:  \u003ci\u003e\"Dbodfm Pqfsbujpo Qipfojy jnnfejbufmz \u0026 ftdbqf.\"\u003c/i\u003e\u003c/p\u003e\u003cp\u003eThe correct answer would comprise:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003es.shift = uint8(1)  \r\ns.message = 'Cancel Operation Phoenix immediately \u0026 escape.'\r\n\u003c/pre\u003e\u003cp\u003e\u003ctt\u003eNote: 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.\u003c/tt\u003e\u003c/p\u003e\u003cp\u003eTo 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\".\u003c/p\u003e\u003cp\u003e----------\u003c/p\u003e\u003cp\u003eNext problem:  \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44356\"\u003eOperation Orthos\u003c/a\u003e.\u003c/p\u003e\u003cp\u003e----------\u003c/p\u003e\u003cp\u003eStatistics on solutions submitted as at 15 October 2017:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003eFastest wall time to decode 5000 messages = 93 milliseconds\u003c/b\u003e , for \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1279303\"\u003eSolution 1279303\u003c/a\u003e, with a size-based score of 40.\u003c/li\u003e\u003cli\u003e\u003cb\u003eSmallest size-based score = 38\u003c/b\u003e , for \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1278780\"\u003eSolution 1278780\u003c/a\u003e, for which wall time to decode 5000 messages = 515 milliseconds.\u003c/li\u003e\u003cli\u003eBest combined score = 49, for \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1279303\"\u003eSolution 1279303\u003c/a\u003e.\u003c/li\u003e\u003c/ul\u003e","function_template":"function s = decode(x)\r\n  s = x;\r\nend","test_suite":"%% NOTE:  \r\n% This test suite can be updated if inappropriate 'hacks' \r\n% are discovered in any submitted solutions, \r\n% so your score/size may therefore change over time.  \r\n\r\n\r\n%% Test 1\r\nx = 'Dbodfm Pqfsbujpo Qipfojy jnnfejbufmz \u0026 ftdbqf.';\r\ns_correct.shift = 1;\r\ns_correct.message = 'Cancel Operation Phoenix immediately \u0026 escape.';\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\nassert( isequal(class(s.shift), 'uint8') )\r\nassert( isequal(class(s.message), 'char') )\r\n\r\n\r\n%% Test 2\r\nx = 'Vwlyhapvu Wovlupe ilnpuz Ablzkhf!  Vwlyhapvu Wovlupe pz vby avw wypvypaf.';\r\ns_correct.shift = 7;\r\ns_correct.message = 'Operation Phoenix begins Tuesday!  Operation Phoenix is our top priority.';\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\nassert( isequal(class(s.shift), 'uint8') )\r\nassert( isequal(class(s.message), 'char') )\r\n\r\n\r\n%% Test 3\r\nx = 'Eatpht cdit iwpi iwt ephhldgs wph qttc rwpcvts ugdb \"Fxeudyn\" id \"Dvcsbwl\".  Diwtglxht Detgpixdc Ewdtcxm xh egdrttsxcv prrdgsxcv id eapc.';\r\ns_correct.shift = 15;\r\ns_correct.message = 'Please note that the password has been changed from \"Qipfojy\" to \"Ogndmhw\".  Otherwise Operation Phoenix is proceeding according to plan.';\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\nassert( isequal(class(s.shift), 'uint8') )\r\nassert( isequal(class(s.message), 'char') )\r\n\r\n\r\n%% Test 4\r\nx = 'Mncpyrgml Nfmclgv qryprcb rfpcc bywq yem.  Yjj ncpqmllcj ypc rm pckygl ml bsrw slrgj Mncpyrgml Nfmclgv gq amknjcrcb.';\r\ns_correct.shift = 24;\r\ns_correct.message = 'Operation Phoenix started three days ago.  All personnel are to remain on duty until Operation Phoenix is completed.';\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\nassert( isequal(class(s.shift), 'uint8') )\r\nassert( isequal(class(s.message), 'char') )\r\n\r\n\r\n%% Rescoring \r\n% Acknowledgements \r\n% Portions of this timing test code were inspired by:\r\n% (1) Problem 937. \"Rubik's Mini Cube: Solve Randomized Cube in 11 Moves or Less; Score is by Time (msec)\" by Richard Zapor.\r\n% (2) Problem 2733. \"Evil Number\" by Jan Orwat.\r\n% (3) Feedback in comments from Peng Liu.\r\n% (4) Problem Problem 1237. \"It's race time! Write a faster function than the test suite call of unique().\" by Jeremy.\r\n\r\n% Note:  The Time Trial section does not check accuracy; that is done above.\r\n\r\n% Initialise\r\nx = 'Dbodfm Pqfsbujpo Qipfojy jnnfejbufmz \u0026 ftdbqf.';\r\ncutoffTimeBig = 1000; % Maximum allowable walltime (in milliseconds) to run function in a loop with qBig iterations.\r\n\r\nfor dummy = 1 : 20,  disp(' . ');  end;\r\n\r\n% Run once, untimed?\r\nincludeOverheads = false;\r\nif includeOverheads, \r\n    solution = decode( x );\r\nend;\r\n\r\n% *** PRELIMINARY TIMING ***\r\n% In case the submitted function has a lot of text output, \r\n% get an estimate based on just a few iterations\r\n% Initialise\r\nqSmall = 50;\r\nqBig = 5000;\r\nt0 = clock;\r\n\r\n% Loop\r\nfor i = 1 : qSmall\r\n    solution = decode( x );\r\nend;\r\n\r\n% Compute and display elapsed time.\r\ndt = etime(clock, t0) * 1000;\r\ndisp('     -----=====-----     ')\r\nfprintf('Your wall time to decode %u messages = %i msec.\\n\\r', qSmall, floor(dt))\r\nfprintf('Your APPROXIMATE wall time to decode %u messages would be ~ %i msec.\\n\\r', qBig, ceil(dt * qBig / qSmall))\r\ndisp('     -----=====-----     ')\r\nfor dummy = 1 : 20,  disp(' . ');  end;\r\n\r\n% *** 'OFFICIAL' TIMING ***\r\n% Re-initialise timer\r\nt0 = clock;\r\nt0_cpu = cputime;\r\n\r\n% Loop\r\nfor i = 1 : qBig\r\n    solution = decode( x );\r\nend;\r\n\r\n% Compute and display elapsed time.\r\nfor dummy = 1 : 20,  disp(' . ');  end;\r\ndisp('     -----=====|||||=====-----     ')\r\ndt = etime(clock, t0) * 1000;\r\nfprintf('Your wall time to decode %u messages = %i msec.\\n\\r', qBig, floor(dt))\r\n\r\ndt_cpu = (cputime - t0_cpu) * 1000;\r\nfprintf(' ( Your CPU time for this = %i msec. ) \\n\\r', floor(dt_cpu))\r\n\r\nfDecode = @()   decode(x);\r\ndt_timeit = timeit( fDecode ) * 1000;\r\nfprintf(' [ Your ''timeit'' time to decode %u messages = %i msec. ] \\n\\r', qBig, ceil(dt_timeit * qBig))\r\n\r\n% Display a size-based score.\r\nall_nodes = mtree('decode.m', '-file');        % This is the default in Cody.\r\nstr_nodes = mtfind(all_nodes, 'Kind', 'STRING');\r\neq_nodes = mtfind(all_nodes, 'Kind', 'EQUALS');\r\nprint_nodes = mtfind(all_nodes, 'Kind', 'PRINT');\r\nexpr_nodes = mtfind(all_nodes, 'Kind', 'EXPR');\r\n\r\nsize_score = count(all_nodes) ...\r\n +sum(str_nodes.nodesize-1) ...\r\n +2*(count(expr_nodes) ...\r\n +count(print_nodes) ...\r\n -count(eq_nodes));\r\n\r\nfprintf('Your size-based score = %i.\\n\\r', size_score)\r\n\r\n% Report revised performance score.\r\ncombinedScore = size_score  +  min( 200, floor(dt*(500/qBig)) );\r\nfprintf('Your combined score = %i.\\n\\r', combinedScore)\r\ndisp('     -----=====|||||=====-----     ')\r\n\r\n% Now disallow any candidate solutions that are TOO SLOW!\r\nif dt \u003e cutoffTimeBig, \r\n    fprintf('Sorry, your submission is TOO SLOW. It must be able to finish within %u milliseconds.\\n\\r', cutoffTimeBig)\r\nend;\r\n\r\nassert( dt \u003c= cutoffTimeBig, 'Exceeded time limit specified in Test Suite.' )","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":45,"test_suite_updated_at":"2017-10-15T10:19:08.000Z","rescore_all_solutions":false,"group_id":40,"created_at":"2017-09-29T09:20:59.000Z","updated_at":"2026-04-02T08:27:57.000Z","published_at":"2017-09-29T13:45:26.000Z","restored_at":"2017-10-04T19:25:07.000Z","restored_by":null,"spam":false,"simulink":false,"admin_reviewed":true,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have been tasked with decoding a set of coded messages that have been intercepted.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBased on previous intelligence that has been gathered, you can be confident that the messages were encoded using a simple\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Caesar_cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCaesar cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (a type of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Substitution_cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esubstitution cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e), an example of which is the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/ROT13\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eROT13 cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (discussed in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody Challenge Problem 78\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e). As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation \u0026amp; 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).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou 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.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour task is to crack the codes and report back in a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/struct.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003estructure array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e: (1) the shifting parameter that had been used in the encoding [as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/uint8.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003euint8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e]; (2) the decoded message [as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/char.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003echaracter array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e]. The name of the structure array shall be \\\"s\\\", with respective fields \\\"shift\\\" and \\\"message\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEXAMPLE\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose the original message was\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Cancel Operation Phoenix immediately \u0026amp; escape.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Dbodfm Pqfsbujpo Qipfojy jnnfejbufmz \u0026amp; ftdbqf.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe correct answer would comprise:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[s.shift = uint8(1)  \\ns.message = 'Cancel Operation Phoenix immediately \u0026 escape.']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNote: 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.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo 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\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e----------\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNext problem: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44356\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOperation Orthos\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e----------\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eStatistics on solutions submitted as at 15 October 2017:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFastest wall time to decode 5000 messages = 93 milliseconds\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1279303\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSolution 1279303\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, with a size-based score of 40.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSmallest size-based score = 38\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1278780\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSolution 1278780\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, for which wall time to decode 5000 messages = 515 milliseconds.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBest combined score = 49, for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44351-code-breaker-part-i-operation-phoenix/solutions/1279303\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSolution 1279303\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1219,"title":"Mystery problem","description":"Given integer x between 1 and 50, return integer y=mystery(x), where \r\n\r\n   mystery(1) =  111   mystery(6)  =  809  ...  mystery(46) = 1809\r\n   mystery(2) =  301   mystery(7)  = 2120  ...  mystery(47) = 1319\r\n   mystery(3) =  315   mystery(8)  = 1413  ...  mystery(48) = 1201\r\n   mystery(4) = 2301   mystery(9)  = 1422  ...  mystery(49) =  405\r\n   mystery(5) = 2325   mystery(10) = 1320  ...  mystery(50) =  612 \r\n\r\nThe rest are for you to determine. Your function should allow a row vector as input and produce a row vector as a result, e.g.,\r\n\r\n   mystery(1:3)=[111 301 315].\r\n\r\nHint: this is not really a mathematical problem--the answer will be just a lookup table.","description_html":"\u003cp\u003eGiven integer x between 1 and 50, return integer y=mystery(x), where\u003c/p\u003e\u003cpre\u003e   mystery(1) =  111   mystery(6)  =  809  ...  mystery(46) = 1809\r\n   mystery(2) =  301   mystery(7)  = 2120  ...  mystery(47) = 1319\r\n   mystery(3) =  315   mystery(8)  = 1413  ...  mystery(48) = 1201\r\n   mystery(4) = 2301   mystery(9)  = 1422  ...  mystery(49) =  405\r\n   mystery(5) = 2325   mystery(10) = 1320  ...  mystery(50) =  612 \u003c/pre\u003e\u003cp\u003eThe rest are for you to determine. Your function should allow a row vector as input and produce a row vector as a result, e.g.,\u003c/p\u003e\u003cpre\u003e   mystery(1:3)=[111 301 315].\u003c/pre\u003e\u003cp\u003eHint: this is not really a mathematical problem--the answer will be just a lookup table.\u003c/p\u003e","function_template":"function y=mystery(x)\r\ny=0;\r\n","test_suite":"%%\r\nassert(isequal(mystery(1:5),[111 301 315 2301 2325]))\r\n%%\r\nassert(isequal(mystery(6:10),[809 2120 1413 1422 1320]))\r\n%%\r\nassert(isequal(mystery(46:50),[1809 1319 1201 405 612]))\r\n%%\r\nx=1:50;\r\nm=mystery(x);\r\nassert(all(m==round(m)))\r\ny=spline(x,m,[12.5 37.5]);\r\nassert(all(y==[704.84846527373202 1283.5708406360138]))","published":true,"deleted":false,"likes_count":3,"comments_count":12,"created_by":245,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":14,"test_suite_updated_at":"2013-01-28T15:31:56.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-01-22T15:48:02.000Z","updated_at":"2013-02-26T06:36:07.000Z","published_at":"2013-01-22T15:51:00.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven integer x between 1 and 50, return integer y=mystery(x), where\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   mystery(1) =  111   mystery(6)  =  809  ...  mystery(46) = 1809\\n   mystery(2) =  301   mystery(7)  = 2120  ...  mystery(47) = 1319\\n   mystery(3) =  315   mystery(8)  = 1413  ...  mystery(48) = 1201\\n   mystery(4) = 2301   mystery(9)  = 1422  ...  mystery(49) =  405\\n   mystery(5) = 2325   mystery(10) = 1320  ...  mystery(50) =  612]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe rest are for you to determine. Your function should allow a row vector as input and produce a row vector as a result, e.g.,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   mystery(1:3)=[111 301 315].]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHint: this is not really a mathematical problem--the answer will be just a lookup table.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44356,"title":"Code breaker, Part II:  Operation Orthos","description":"You have been tasked with decoding several batches of coded messages that have been intercepted.  \r\n\r\nBased on previous intelligence that has been gathered, you can be confident that the messages were all encoded using a simple \u003chttps://en.wikipedia.org/wiki/Caesar_cipher Caesar cipher\u003e (a type of \u003chttps://en.wikipedia.org/wiki/Substitution_cipher substitution cipher\u003e), an example of which is the \u003chttps://en.wikipedia.org/wiki/ROT13 ROT13 cipher\u003e (discussed in \u003chttps://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher Cody Challenge Problem 78\u003e).  As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation \u0026 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).  \r\n\r\nYou 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.  \r\n\r\nYour task is to crack the codes and report back in a \u003chttp://au.mathworks.com/help/matlab/ref/struct.html structure array\u003e:  (1) the shifting parameter that had been used in the encoding [as \u003chttp://au.mathworks.com/help/matlab/ref/uint8.html uint8\u003e];  (2)  the decoded messages [as a \u003chttp://au.mathworks.com/help/matlab/ref/cell.html?s_tid=doc_ta cell array\u003e (containing \u003chttp://au.mathworks.com/help/matlab/ref/char.html character arrays\u003e)].  \r\nThe name of the structure array shall be \"s\", with respective fields \"shift\" and \"message\".  \r\n\r\nEXAMPLE\r\n\r\nSuppose 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.)  \r\nThus the original messages would have been:  _\"proceed w/ operation\"_ and _\"Orthos is GO!\"_ .\r\n\r\nThe correct answer would comprise:  \r\n\r\n  s.shift = uint8(1)  \r\n  s.message = {'proceed w/ operation', 'Orthos is GO!'}\r\n\r\nIf the batch of messages cannot be decoded when following the above assumptions, then simply return 'scalar' \u003chttp://au.mathworks.com/help/matlab/ref/nan.html NaN\u003e in both fields (no need for a cell array).  \r\n\r\n|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.)|  \r\n\r\nTo 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\".  \r\n\r\n----------\r\n\r\nPrevious problem:  \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44351 Operation Phoenix\u003e.  Next problem:  \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44383 Operation Xiangliu\u003e.","description_html":"\u003cp\u003eYou have been tasked with decoding several batches of coded messages that have been intercepted.\u003c/p\u003e\u003cp\u003eBased on previous intelligence that has been gathered, you can be confident that the messages were all encoded using a simple \u003ca href = \"https://en.wikipedia.org/wiki/Caesar_cipher\"\u003eCaesar cipher\u003c/a\u003e (a type of \u003ca href = \"https://en.wikipedia.org/wiki/Substitution_cipher\"\u003esubstitution cipher\u003c/a\u003e), an example of which is the \u003ca href = \"https://en.wikipedia.org/wiki/ROT13\"\u003eROT13 cipher\u003c/a\u003e (discussed in \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher\"\u003eCody Challenge Problem 78\u003c/a\u003e).  As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation \u0026 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).\u003c/p\u003e\u003cp\u003eYou 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 \u003ci\u003esimultaneous\u003c/i\u003e occurrence of the separate words \"Operation\" and \"Orthos\" (with any capitalisation) in messages within the given batch.\u003c/p\u003e\u003cp\u003eYour task is to crack the codes and report back in a \u003ca href = \"http://au.mathworks.com/help/matlab/ref/struct.html\"\u003estructure array\u003c/a\u003e:  (1) the shifting parameter that had been used in the encoding [as \u003ca href = \"http://au.mathworks.com/help/matlab/ref/uint8.html\"\u003euint8\u003c/a\u003e];  (2)  the decoded messages [as a \u003ca href = \"http://au.mathworks.com/help/matlab/ref/cell.html?s_tid=doc_ta\"\u003ecell array\u003c/a\u003e (containing \u003ca href = \"http://au.mathworks.com/help/matlab/ref/char.html\"\u003echaracter arrays\u003c/a\u003e)].  \r\nThe name of the structure array shall be \"s\", with respective fields \"shift\" and \"message\".\u003c/p\u003e\u003cp\u003eEXAMPLE\u003c/p\u003e\u003cp\u003eSuppose the batch contained two encoded messages — \u003ci\u003e\"qspdffe x/ pqfsbujpo\"\u003c/i\u003e and \u003ci\u003e\"Psuipt jt HP!\"\u003c/i\u003e (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.)  \r\nThus the original messages would have been:  \u003ci\u003e\"proceed w/ operation\"\u003c/i\u003e and \u003ci\u003e\"Orthos is GO!\"\u003c/i\u003e .\u003c/p\u003e\u003cp\u003eThe correct answer would comprise:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003es.shift = uint8(1)  \r\ns.message = {'proceed w/ operation', 'Orthos is GO!'}\r\n\u003c/pre\u003e\u003cp\u003eIf the batch of messages cannot be decoded when following the above assumptions, then simply return 'scalar' \u003ca href = \"http://au.mathworks.com/help/matlab/ref/nan.html\"\u003eNaN\u003c/a\u003e in both fields (no need for a cell array).\u003c/p\u003e\u003cp\u003e\u003ctt\u003eNote:  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.)\u003c/tt\u003e\u003c/p\u003e\u003cp\u003eTo 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\".\u003c/p\u003e\u003cp\u003e----------\u003c/p\u003e\u003cp\u003ePrevious problem:  \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44351\"\u003eOperation Phoenix\u003c/a\u003e.  Next problem:  \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44383\"\u003eOperation Xiangliu\u003c/a\u003e.\u003c/p\u003e","function_template":"function s = decode(x)\r\n  s = x;\r\nend","test_suite":"%% NOTE:  \r\n% This test suite can be updated if inappropriate 'hacks' \r\n% are discovered in any submitted solutions, \r\n% so the assessment of your submission may therefore change over time.  \r\nRE = regexp(fileread('decode.m'), '\\w+', 'match');\r\ntabooWords = {'ans', 'assert', 'freepass', 'tic'};\r\ntestResult = cellfun( @(z) ismember(z, tabooWords), RE );\r\nmsg = ['Please do not do that in your code!' char([10 13]) ...\r\n    'Found: ' strjoin(RE(testResult)) '.' char([10 13]) ...\r\n    'Banned word.' char([10 13])];\r\nassert(~any(  cellfun( @(z) ismember(z, tabooWords), RE )  ), msg)\r\n\r\n\r\n%% Test 1\r\nx =                 {'qspdffe x/ pqfsbujpo', 'Psuipt jt HP!'};\r\ns_correct.shift = uint8(1);\r\ns_correct.message = {'proceed w/ operation', 'Orthos is GO!'};\r\ns = decode(x);\r\n%disp(' *** ');  disp(s.message);  disp(' *** ')\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message{1}, s_correct.message{1}) )\r\nassert( isequal(s.message{2}, s_correct.message{2}) )\r\nassert( isequal(s.message, s_correct.message) )\r\nassert( isequal(s, s_correct) )\r\nassert( isequal(class(s.shift), 'uint8') )\r\nassert( isequal(class(s.message), 'cell') )\r\nassert( isequal(class(s.message{1}), 'char') )\r\n\r\n\r\n%% Test 2\r\nx =                 {'Hfqq Ons ts 555-7839 FXFU.', 'twymtx nx ts mtqi', 'bfnynsl ktw dtzw fianhj', 'TUJWFYNTS UTXYUTSJI'};\r\ns_correct.shift = uint8(5);\r\ns_correct.message = {'Call Jin on 555-7839 ASAP.', 'orthos is on hold', 'waiting for your advice', 'OPERATION POSTPONED'};\r\ns = decode(x);\r\n%disp(' *** ');  disp(s.message);  disp(' *** ')\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\n\r\n\r\n%% Test 3\r\nx =                 {'Ocz kvnnrjmy rvn xcvibzy: \"Knpdko\" oj \"Gjlzgk\".', 'Jkzmvodji Kcjzids rvn npxxznnapg. Izso rdgg wz Jmocjn.', 'Edi Uvkxgzout rdgg wz gzvydib Ozvh V'};\r\ns_correct.shift = uint8(21);\r\ns_correct.message = {'The password was changed: \"Psuipt\" to \"Loqelp\".', 'Operation Phoenix was successful. Next will be Orthos.', 'Jin Zapcletzy will be leading Team A'};\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\n\r\n\r\n%% Test 4\r\nx =                 {'bxmzzuzs r/ adftae az fdmow', 'adftae etxp oaybxqfq uz 2 iwe', 'abqdmfuaz pmfq eturfqp nmow 2 p.', 'naawe dqoquhqp. fwe Vuz' };\r\ns_correct.shift = uint8(12);\r\ns_correct.message = {'planning f/ orthos on track', 'orthos shld complete in 2 wks', 'operation date shifted back 2 d.', 'books received. tks Jin'};\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\n\r\n\r\n%% Test 5\r\nx =                 {'Hdsffafy xgj Ghwjslagf Gjlzgk zsk gxxauasddq ugeewfuwv.  Lzak oadd tw dwv tq Lwse S, kmhhgjlwv tq Lwse T sk fwwvwv.'};\r\ns_correct.shift = uint8(18);\r\ns_correct.message = {'Planning for Operation Orthos has officially commenced.  This will be led by Team A, supported by Team B as needed.'};\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\n\r\n\r\n%% Test 6\r\nx = {'Mncpyrgml Nfmclgv qryprcb rfpcc bywq yem.  Yjj ncpqmllcj ypc rm pckygl ml bsrw slrgj Mncpyrgml Nfmclgv gq amknjcrcb.'};\r\ns_correct.shift = nan;\r\ns_correct.message = nan;\r\ns = decode(x);\r\nassert( isnan(s.shift) )\r\nassert( isnan(s.message) )\r\n\r\n\r\n%% Test 7\r\nx =                 {'Iutloxskj vgyycuxj oy tuc \"Ruwkrv\".', 'Vrgt lux uxznuy ruuqy UQ, haz tkkj suxk $$$', 'Ksgor Pot Fgvirkzfe ut xacqxb@sgzncuxqy.ius xk. Zakyjge', 'Zgrqkj zu Zkgs H.  Ngvve zu yavvuxz uvkxgzout....', 'Xk. latjy, vry zxgtylkx zu giiuatz \"YZOBKDSYX\" - ZDY', 'jUT''Z cUXXE'};\r\ns_correct.shift = uint8(6);\r\ns_correct.message = {'Confirmed password is now \"Loqelp\".', 'Plan for orthos looks OK, but need more $$$', 'Email Jin Zapcletzy on ruwkrv@mathworks.com re. Tuesday', 'Talked to Team B.  Happy to support operation....', 'Re. funds, pls transfer to account \"STIVEXMSR\" - TXS', 'dON''T wORRY'};\r\ns = decode(x);\r\nassert( isequal(s.shift, s_correct.shift) )\r\nassert( isequal(s.message, s_correct.message) )\r\n\r\n\r\n%% TIMING \r\n% Note:  The Time Trial section does not check accuracy; that is done above.\r\n\r\n% Acknowledgements  \r\n% Portions of this timing test code were inspired by:\r\n% (1) Problem 937. \"Rubik's Mini Cube: Solve Randomized Cube in 11 Moves or Less; Score is by Time (msec)\" by Richard Zapor.\r\n% (2) Problem 2733. \"Evil Number\" by Jan Orwat.\r\n% (3) Feedback in comments from Peng Liu.\r\n% (4) Problem Problem 1237. \"It's race time! Write a faster function than the test suite call of unique().\" by Jeremy.\r\n\r\n% INITIALISE\r\nx = {'qspdffe x/ pqfsbujpo', 'Psuipt jt HP!'};\r\nqSmall = 50;\r\nqBig = 10000;\r\n%cutoffTimeBig = 10;\r\n\r\n% EDIT (2018-06-17).  Reduced time to pose reasonable challenge.\r\n% Accounted for improving Cody server speed per Problem 44655.\r\ncutoffTimeBig = 3;    % Maximum allowable walltime (in seconds) to run function in a loop with qBig iterations.\r\ntRef = datetime('2018-06-17', 'InputFormat','yyyy-MM-dd');\r\ntNow = datetime('now');\r\nyearsElapsed = (datenum(tNow) - datenum(tRef)) / 365.24;\r\nfprintf('\\r\\n\\r\\n\\r\\nSubmission evaluated for speed on %s.\\r\\n', datestr(tNow, 'dd mmmm yyyy'))\r\nrInf = 0.2;   delta = cutoffTimeBig - rInf;  tau = 3.6;  % Data from Problem 44655, based on Problem 963.\r\nqBig = floor( qBig * (cutoffTimeBig - rInf) * exp(yearsElapsed/tau) / delta );\r\nfprintf('\\r\\n\\r\\n\\r\\nTo account for computational power increases over time, number of iterations increased to %u.\\r\\n', qBig)\r\n% END EDIT (2018-06-17)\r\n\r\nfor dummy = 1 : 10,  disp(' . ');  end;\r\n\r\n% *** PRELIMINARY TIMING WITH timeit ***\r\nfDecode = @()   decode(x);\r\ndt_timeit = timeit( fDecode );\r\nfprintf('APPROXIMATE time to decode %u message batches ~ %2.2f seconds, according to ''timeit''.\\n\\r', qBig, dt_timeit * qBig)\r\n\r\n% *** PRELIMINARY TIMING WITH SHORT LOOP ***\r\n% In case the submitted function has a lot of text output, \r\n% get an estimate based on just a few iterations\r\n% Initialise\r\nt0 = clock;\r\n\r\n% Loop\r\nfor i = 1 : qSmall\r\n    solution = decode( x );\r\nend;\r\n\r\n% Compute and display elapsed time.\r\ndt = etime(clock, t0);\r\ndisp('     -----=====-----     ')\r\n%fprintf('Your wall time to decode %u message batches = %i seconds.\\n\\r', qSmall, floor(dt))\r\nfprintf('APPROXIMATE wall time to decode %u message batches ~ %2.2f seconds, by extrapolating from %u batches.\\n\\r', qBig, dt * qBig / qSmall, qSmall)\r\ndisp('     -----=====-----     ')\r\n\r\n% *** 'OFFICIAL' TIMING ***\r\n% Re-initialise timer\r\nt0 = clock;\r\nt0_cpu = cputime;\r\n\r\n% Loop\r\nfor i = 1 : qBig\r\n    solution = decode( x );\r\nend;\r\n\r\n% Compute and display elapsed time.\r\nfor dummy = 1 : 10,  disp(' . ');  end;\r\ndisp('     -----=====|||||=====-----     ')\r\ndt = etime(clock, t0);\r\nfprintf('Your wall time to decode %u message batches = %2.2f seconds.\\n\\r', qBig, dt)\r\n\r\ndt_cpu = (cputime - t0_cpu);\r\nfprintf(' ( Your CPU time for this = %2.2f seconds. ) \\n\\r', dt_cpu)\r\n\r\n% Display (default) Cody size-based score.\r\nall_nodes = mtree('decode.m', '-file');\r\nsize_score = count(all_nodes);\r\nfprintf('Your Cody-standard size-based score = %i.\\n\\r', size_score)\r\n\r\n% Report revised performance score\r\ncombinedScore = size_score + round(dt * 10);\r\nfprintf('Your combined score = %i.\\n\\r', combinedScore)\r\ndisp('     -----=====|||||=====-----     ')\r\n\r\n% Now disallow any candidate solutions that are TOO SLOW!\r\nif dt \u003e cutoffTimeBig, \r\n    fprintf('Sorry, your submission is TOO SLOW.  It must be able to finish within %u seconds.\\n\\r', cutoffTimeBig)\r\nend;\r\n\r\nassert( dt \u003c= cutoffTimeBig )","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":"2018-06-17T14:03:55.000Z","rescore_all_solutions":false,"group_id":40,"created_at":"2017-10-03T06:52:32.000Z","updated_at":"2026-04-02T18:15:25.000Z","published_at":"2017-10-03T11:50:21.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have been tasked with decoding several batches of coded messages that have been intercepted.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBased on previous intelligence that has been gathered, you can be confident that the messages were all encoded using a simple\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Caesar_cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCaesar cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (a type of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Substitution_cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esubstitution cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e), an example of which is the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/ROT13\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eROT13 cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (discussed in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody Challenge Problem 78\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e). As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation \u0026amp; 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).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou 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\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esimultaneous\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e occurrence of the separate words \\\"Operation\\\" and \\\"Orthos\\\" (with any capitalisation) in messages within the given batch.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour task is to crack the codes and report back in a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/struct.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003estructure array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e: (1) the shifting parameter that had been used in the encoding [as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/uint8.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003euint8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e]; (2) the decoded messages [as a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/cell.html?s_tid=doc_ta\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ecell array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (containing\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/char.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003echaracter arrays\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e)]. The name of the structure array shall be \\\"s\\\", with respective fields \\\"shift\\\" and \\\"message\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEXAMPLE\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose the batch contained two encoded messages —\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"qspdffe x/ pqfsbujpo\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Psuipt jt HP!\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (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: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"proceed w/ operation\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Orthos is GO!\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e .\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe correct answer would comprise:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[s.shift = uint8(1)  \\ns.message = {'proceed w/ operation', 'Orthos is GO!'}]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf the batch of messages cannot be decoded when following the above assumptions, then simply return 'scalar'\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/nan.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eNaN\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in both fields (no need for a cell array).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNote: 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.)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo 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\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e----------\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44351\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOperation Phoenix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44383\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOperation Xiangliu\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":78,"title":"Implement a ROT13 cipher","description":"Replace each character in string s1 with the character that is shifted 13 positions from it (wrap back to the beginning if necessary). So A ? N, B ? O, and so on until Y ? L and Z ? M. Case of the output should match the case of the input, so a ? n. Non-alphabetic characters are left in place and untouched.\n\nIf\n\n s1 = 'I love MATLAB'\n\nthen\n\n s2 = 'V ybir ZNGYNO'\n\nSee the \u003chttp://en.wikipedia.org/wiki/ROT13 Wikipedia article\u003e for more info.","description_html":"\u003cp\u003eReplace each character in string s1 with the character that is shifted 13 positions from it (wrap back to the beginning if necessary). So A ? N, B ? O, and so on until Y ? L and Z ? M. Case of the output should match the case of the input, so a ? n. Non-alphabetic characters are left in place and untouched.\u003c/p\u003e\u003cp\u003eIf\u003c/p\u003e\u003cpre\u003e s1 = 'I love MATLAB'\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre\u003e s2 = 'V ybir ZNGYNO'\u003c/pre\u003e\u003cp\u003eSee the \u003ca href=\"http://en.wikipedia.org/wiki/ROT13\"\u003eWikipedia article\u003c/a\u003e for more info.\u003c/p\u003e","function_template":"function s2 = rot13(s1)\n  s2 = s1;\nend","test_suite":"%% Test #1\n\ns1 = 'I love MATLAB';\ns2_correct = 'V ybir ZNGYNO';\nassert(isequal(rot13(s1),s2_correct))\n\n%% Test #2\n\ns1 = 'I \u003c3 MATLAB!!';\ns2_correct = 'V \u003c3 ZNGYNO!!';\nassert(isequal(rot13(s1),s2_correct))\n\n%% Test #3\n\ns1 = 'The quick fox stumbled over the confusing instructions.';\ns2_correct = 'Gur dhvpx sbk fghzoyrq bire gur pbashfvat vafgehpgvbaf.';\nassert(isequal(rot13(s1),s2_correct))\n\n%% Test #4\n\ns1 = 'Snape kills Dumbledore on page 606. Also, there is no Santa.';\ns2_correct = 'Fancr xvyyf Qhzoyrqber ba cntr 606. Nyfb, gurer vf ab Fnagn.';\nassert(isequal(rot13(s1),s2_correct))\n\n","published":true,"deleted":false,"likes_count":13,"comments_count":3,"created_by":1,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1713,"test_suite_updated_at":"2012-01-18T01:00:28.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:28.000Z","updated_at":"2026-01-06T04:39:32.000Z","published_at":"2012-01-18T01:00:28.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReplace each character in string s1 with the character that is shifted 13 positions from it (wrap back to the beginning if necessary). So A ? N, B ? O, and so on until Y ? L and Z ? M. Case of the output should match the case of the input, so a ? n. Non-alphabetic characters are left in place and untouched.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ s1 = 'I love MATLAB']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ s2 = 'V ybir ZNGYNO']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/ROT13\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eWikipedia article\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e for more info.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44383,"title":"Code breaker, Part III:  Operation Xiangliu","description":"You have been tasked with decoding several batches of coded messages that have been intercepted.  \r\n\r\nBased on previous intelligence that has been gathered, you can be confident that the messages were all encoded using a simple \u003chttps://en.wikipedia.org/wiki/Caesar_cipher Caesar cipher\u003e (a type of \u003chttps://en.wikipedia.org/wiki/Substitution_cipher substitution cipher\u003e), an example of which is the \u003chttps://en.wikipedia.org/wiki/ROT13 ROT13 cipher\u003e (discussed in \u003chttps://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher Cody Challenge Problem 78\u003e).  As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation, numbers, accented letters) are unchanged.  Unlike the Cody Challenge Problem, here the number of letters to shift is not known in advance, and will vary _between_ (not within) batches — also, here you need to decode, not encode.  \r\n\r\nThese latest activities that you are investigating have been nicknamed 'Operation Xiangliu' by your own organisation.  A few decoding options are at your organisation's disposal:  \r\n\r\n# Test the candidate decodings against all words in a large dictionary — this could work, but it is very slow.\r\n# Test the candidate decodings for the appearance of a name or phrase that is certain to appear regularly (e.g. \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44351 \"Operation Phoenix\"\u003e) — unfortunately as yet there is not enough knowledge of the activities to be sure of a suitable name or phrase to use.  \r\n# Test the candidate decodings against all words in a short list comprising, say, the hundred most frequently used English words.\r\n\r\nThe *third option* will be faster than the first option, and more reliable than the second option, so this is the approach you will be taking.  \r\n\r\nYou have been careful to avoid using 'lemmatised' lists (which contain e.g. the verb \"to be\", rather than the various inflected forms such as \"am\", \"is\", \"are\") like those based on the \u003chttps://web.archive.org/web/20111226085859/http://oxforddictionaries.com/words/the-oec-facts-about-the-language OEC\u003e or \u003chttps://www.wordfrequency.info/free.asp?s=y COCA\u003e, and after setting aside \u003chttp://world-english.org/english500.htm another list\u003e you finally choose the \u003chttp://ucrel.lancs.ac.uk/bncfreq/samples/120.pdf list based on the BNC\u003e as the most reliable, and will use the first 100 words on that list.  \r\nThis list will be available for you to access as an input variable, |bncWordlist|, to your function. Note: (i) some entries on the list are morphemes (e.g. \"\u0026#x200A;n't\u0026#x200A;\" and \"\u0026#x200A;'s\u0026#x200A;\") rather than words;  (ii) some entries appear more than once (representing different grammatical word classes).  Of course, in the original messages any capitalisation might be used.  \r\n\r\nYou have been instructed that your 'certitude' (degree of confidence) in the decoding must be reported for each batch, and shall depend proportionally upon the sum of the characters for the words/morphemes in the decoded message that match words/morphemes in |bncWordlist|.  Being able to match words/morphemes accounting for three-tenths of the characters (excluding spaces) shall correspond to 100% certitude;  matching three-twentieths would be 50% certitude, and so on.  Certitude shall be reported as a percentage, rounded _up_ to the nearest integer, not greater than 100.  You need to maximise your certitude for each batch by appropriate choice of the shifting parameter.   If there are multiple shifts of equal certitude, report both options on different rows (arranged in order of ascending shift parameter).\r\n\r\nYour task is to crack the codes and report back in a \u003chttp://au.mathworks.com/help/matlab/ref/struct.html structure array\u003e: \u0026nbsp; (1) the shifting parameter that had been used in the encoding [as \u003chttp://au.mathworks.com/help/matlab/ref/uint8.html uint8\u003e] (usually scalar, but may be column vector); \u0026nbsp; (2) the decoded messages [as a \u003chttp://au.mathworks.com/help/matlab/ref/cell.html?s_tid=doc_ta cell array\u003e (containing \u003chttp://au.mathworks.com/help/matlab/ref/char.html character arrays\u003e)] (usually an array with a single row, but occasionally with multiple rows); \u0026nbsp; (3) your 'certitude' in the decoding [as \u003chttp://au.mathworks.com/help/matlab/ref/uint8.html uint8\u003e] (always scalar).  \r\nThe name of the structure array shall be |s|, with respective fields |shift|, |message|, and |certitude|.  \r\n\r\n*EXAMPLE 1*\r\n\r\nSuppose the batch contained two encoded messages — _\"Vomftt qvstvfe, pqfo op eppst.\"_ and _\"Ffmt dbo ljmm, opu pomz xpvoe.\"_ (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.  \r\nThus the original messages would have been:  _\"Unless pursued, open no doors.\"_ and _\"Eels can kill, not only wound.\"_ .  Twelve of the 51 characters have been matched:  \"no\", \"can\", \"not\", and \"only\".  \r\n\r\nThe correct answer would therefore comprise:  \r\n\r\n  s.shift = uint8(1)  \r\n  s.message = {'Unless pursued, open no doors.', 'Eels can kill, not only wound.'}\r\n  s.certitude = uint8(79)\r\n\r\n*EXAMPLE 2*\r\n\r\nSuppose the batch contained one encoded message — _\"Oa oqvvq'u cnycau dggp: \"Ctu itcvkc ctvku\".\"_ (provided as a character array within a cell array) — and a (right-shifting) ROT2 cipher had been applied.  In that case A→C, B→D, ..., Y→A, and Z→B;  similarly, a→c, b→d, ..., y→a, and z→b.  \r\nThus the original message would have been:  _\"My motto's always been: \"Ars gratia artis\".\"_ .  Eight of the 37 characters have been matched: \"My\", \"\u0026#x200A;'s\u0026#x200A;\", and \"been\".  Note carefully that:  \"\u0026#x200A;'s\u0026#x200A;\" should only be matched once;  \"to\" (in motto), \"be\" (in been), \"at\" (in gratia), \"is\" (in artis) and \"a\" (passim) should _not_ be matched at all;  and \"\u0026#x200A;'\u0026#x200A;\" will only ever be used as an apostrophe (never as a quotation mark).  \r\n\r\nThe correct answer would therefore comprise:  \r\n\r\n  s.shift = uint8(2)  \r\n  s.message = {'My motto''s always been: \"Ars gratia artis\".'}\r\n  s.certitude = uint8(73)\r\n\r\nIf the batch of messages cannot be decoded when following the above assumptions, then return the original encoded message(s) unchanged, with a shift of zero and a certitude of zero.  \r\n\r\n|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.)|  \r\n\r\nTo 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\".  \r\n\r\n----------\r\n\r\nPrevious problem:  \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44356 Operation Orthos\u003e.  Next problem:  TBA.","description_html":"\u003cp\u003eYou have been tasked with decoding several batches of coded messages that have been intercepted.\u003c/p\u003e\u003cp\u003eBased on previous intelligence that has been gathered, you can be confident that the messages were all encoded using a simple \u003ca href = \"https://en.wikipedia.org/wiki/Caesar_cipher\"\u003eCaesar cipher\u003c/a\u003e (a type of \u003ca href = \"https://en.wikipedia.org/wiki/Substitution_cipher\"\u003esubstitution cipher\u003c/a\u003e), an example of which is the \u003ca href = \"https://en.wikipedia.org/wiki/ROT13\"\u003eROT13 cipher\u003c/a\u003e (discussed in \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher\"\u003eCody Challenge Problem 78\u003c/a\u003e).  As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation, numbers, accented letters) are unchanged.  Unlike the Cody Challenge Problem, here the number of letters to shift is not known in advance, and will vary \u003ci\u003ebetween\u003c/i\u003e (not within) batches — also, here you need to decode, not encode.\u003c/p\u003e\u003cp\u003eThese latest activities that you are investigating have been nicknamed 'Operation Xiangliu' by your own organisation.  A few decoding options are at your organisation's disposal:\u003c/p\u003e\u003col\u003e\u003cli\u003eTest the candidate decodings against all words in a large dictionary — this could work, but it is very slow.\u003c/li\u003e\u003cli\u003eTest the candidate decodings for the appearance of a name or phrase that is certain to appear regularly (e.g. \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44351\"\u003e\"Operation Phoenix\"\u003c/a\u003e) — unfortunately as yet there is not enough knowledge of the activities to be sure of a suitable name or phrase to use.\u003c/li\u003e\u003cli\u003eTest the candidate decodings against all words in a short list comprising, say, the hundred most frequently used English words.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eThe \u003cb\u003ethird option\u003c/b\u003e will be faster than the first option, and more reliable than the second option, so this is the approach you will be taking.\u003c/p\u003e\u003cp\u003eYou have been careful to avoid using 'lemmatised' lists (which contain e.g. the verb \"to be\", rather than the various inflected forms such as \"am\", \"is\", \"are\") like those based on the \u003ca href = \"https://web.archive.org/web/20111226085859/http://oxforddictionaries.com/words/the-oec-facts-about-the-language\"\u003eOEC\u003c/a\u003e or \u003ca href = \"https://www.wordfrequency.info/free.asp?s=y\"\u003eCOCA\u003c/a\u003e, and after setting aside \u003ca href = \"http://world-english.org/english500.htm\"\u003eanother list\u003c/a\u003e you finally choose the \u003ca href = \"http://ucrel.lancs.ac.uk/bncfreq/samples/120.pdf\"\u003elist based on the BNC\u003c/a\u003e as the most reliable, and will use the first 100 words on that list.  \r\nThis list will be available for you to access as an input variable, \u003ctt\u003ebncWordlist\u003c/tt\u003e, to your function. Note: (i) some entries on the list are morphemes (e.g. \"\u0026#x200A;n't\u0026#x200A;\" and \"\u0026#x200A;'s\u0026#x200A;\") rather than words;  (ii) some entries appear more than once (representing different grammatical word classes).  Of course, in the original messages any capitalisation might be used.\u003c/p\u003e\u003cp\u003eYou have been instructed that your 'certitude' (degree of confidence) in the decoding must be reported for each batch, and shall depend proportionally upon the sum of the characters for the words/morphemes in the decoded message that match words/morphemes in \u003ctt\u003ebncWordlist\u003c/tt\u003e.  Being able to match words/morphemes accounting for three-tenths of the characters (excluding spaces) shall correspond to 100% certitude;  matching three-twentieths would be 50% certitude, and so on.  Certitude shall be reported as a percentage, rounded \u003ci\u003eup\u003c/i\u003e to the nearest integer, not greater than 100.  You need to maximise your certitude for each batch by appropriate choice of the shifting parameter.   If there are multiple shifts of equal certitude, report both options on different rows (arranged in order of ascending shift parameter).\u003c/p\u003e\u003cp\u003eYour task is to crack the codes and report back in a \u003ca href = \"http://au.mathworks.com/help/matlab/ref/struct.html\"\u003estructure array\u003c/a\u003e: \u0026nbsp; (1) the shifting parameter that had been used in the encoding [as \u003ca href = \"http://au.mathworks.com/help/matlab/ref/uint8.html\"\u003euint8\u003c/a\u003e] (usually scalar, but may be column vector); \u0026nbsp; (2) the decoded messages [as a \u003ca href = \"http://au.mathworks.com/help/matlab/ref/cell.html?s_tid=doc_ta\"\u003ecell array\u003c/a\u003e (containing \u003ca href = \"http://au.mathworks.com/help/matlab/ref/char.html\"\u003echaracter arrays\u003c/a\u003e)] (usually an array with a single row, but occasionally with multiple rows); \u0026nbsp; (3) your 'certitude' in the decoding [as \u003ca href = \"http://au.mathworks.com/help/matlab/ref/uint8.html\"\u003euint8\u003c/a\u003e] (always scalar).  \r\nThe name of the structure array shall be \u003ctt\u003es\u003c/tt\u003e, with respective fields \u003ctt\u003eshift\u003c/tt\u003e, \u003ctt\u003emessage\u003c/tt\u003e, and \u003ctt\u003ecertitude\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003e\u003cb\u003eEXAMPLE 1\u003c/b\u003e\u003c/p\u003e\u003cp\u003eSuppose the batch contained two encoded messages — \u003ci\u003e\"Vomftt qvstvfe, pqfo op eppst.\"\u003c/i\u003e and \u003ci\u003e\"Ffmt dbo ljmm, opu pomz xpvoe.\"\u003c/i\u003e (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.  \r\nThus the original messages would have been:  \u003ci\u003e\"Unless pursued, open no doors.\"\u003c/i\u003e and \u003ci\u003e\"Eels can kill, not only wound.\"\u003c/i\u003e .  Twelve of the 51 characters have been matched:  \"no\", \"can\", \"not\", and \"only\".\u003c/p\u003e\u003cp\u003eThe correct answer would therefore comprise:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003es.shift = uint8(1)  \r\ns.message = {'Unless pursued, open no doors.', 'Eels can kill, not only wound.'}\r\ns.certitude = uint8(79)\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eEXAMPLE 2\u003c/b\u003e\u003c/p\u003e\u003cp\u003eSuppose the batch contained one encoded message — \u003ci\u003e\"Oa oqvvq'u cnycau dggp: \"Ctu itcvkc ctvku\".\"\u003c/i\u003e (provided as a character array within a cell array) — and a (right-shifting) ROT2 cipher had been applied.  In that case A→C, B→D, ..., Y→A, and Z→B;  similarly, a→c, b→d, ..., y→a, and z→b.  \r\nThus the original message would have been:  \u003ci\u003e\"My motto's always been: \"Ars gratia artis\".\"\u003c/i\u003e .  Eight of the 37 characters have been matched: \"My\", \"\u0026#x200A;'s\u0026#x200A;\", and \"been\".  Note carefully that:  \"\u0026#x200A;'s\u0026#x200A;\" should only be matched once;  \"to\" (in motto), \"be\" (in been), \"at\" (in gratia), \"is\" (in artis) and \"a\" (passim) should \u003ci\u003enot\u003c/i\u003e be matched at all;  and \"\u0026#x200A;'\u0026#x200A;\" will only ever be used as an apostrophe (never as a quotation mark).\u003c/p\u003e\u003cp\u003eThe correct answer would therefore comprise:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003es.shift = uint8(2)  \r\ns.message = {'My motto''s always been: \"Ars gratia artis\".'}\r\ns.certitude = uint8(73)\r\n\u003c/pre\u003e\u003cp\u003eIf the batch of messages cannot be decoded when following the above assumptions, then return the original encoded message(s) unchanged, with a shift of zero and a certitude of zero.\u003c/p\u003e\u003cp\u003e\u003ctt\u003eNote:  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.)\u003c/tt\u003e\u003c/p\u003e\u003cp\u003eTo 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\".\u003c/p\u003e\u003cp\u003e----------\u003c/p\u003e\u003cp\u003ePrevious problem:  \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44356\"\u003eOperation Orthos\u003c/a\u003e.  Next problem:  TBA.\u003c/p\u003e","function_template":"% Comments are nice, aren't they....\r\nfunction s = decode(x, bncWordlist)\r\nend","test_suite":"%% NOTE:  \r\n% This test suite can be updated if inappropriate 'hacks' \r\n% are discovered in any submitted solutions.\r\n% The assessment of your submission may therefore change over time.  \r\n\r\nglobal bncWordlist\r\nbncWordlist = {'the', 'of', 'and', 'a', 'in', 'to', 'it', 'is', 'to', 'was', ...\r\n    'I', 'for', 'that', 'you', 'he', 'be', 'with', 'on', 'by', 'at', ...\r\n    'have', 'are', 'not', 'this', '''s', 'but', 'had', 'they', 'his', ...\r\n    'from', 'she', 'that', 'which', 'or', 'we', '''s', 'an', 'n''t', 'were', ...\r\n    'as', 'do', 'been', 'their', 'has', 'would', 'there', 'what', 'will', 'all', ...\r\n    'if', 'can', 'her', 'said', 'who', 'one', 'so', 'up', 'as', 'them', 'some', ...\r\n    'when', 'could', 'him', 'into', 'its', 'then', 'two', 'out', 'time', ...\r\n    'my', 'about', 'did', 'your', 'now', 'me', 'no', 'other', 'only', 'just', ...\r\n    'more', 'these', 'also', 'people', 'know', 'any', 'first', 'see', 'very', 'new', ...\r\n    'may', 'well', 'should', 'her', 'like', 'than', 'how', 'get', 'way', 'one', 'our'};\r\n\r\n\r\n%% Anti-hacking\r\n% EDIT (2019-07-02). Anti-hacking provision\r\n% Ensure only builtin functions will be called.\r\n! rm -v fileread.m\r\n! rm -v assert.m\r\n% END EDIT (2019-07-02)\r\n% EDIT (2018-06-18).  Anti-hacking provision\r\nRE = regexp(fileread('decode.m'), '\\w+', 'match');\r\ntabooWords = {'ans', 'assert', 'freepass', 'tic'};\r\ntestResult = cellfun( @(z) ismember(z, tabooWords), RE );\r\nmsg = ['Please do not do that in your code!' char([10 13]) ...\r\n    'Found: ' strjoin(RE(testResult)) '.' char([10 13]) ...\r\n    'Banned word.' char([10 13])];\r\nassert(~any(  cellfun( @(z) ismember(z, tabooWords), RE )  ), msg)\r\n\r\nfor j = 1 : randi(10)\r\n    decode({'Pizza for dinner.'}, {'mozzarella', 'mushrooms'});\r\nend;\r\n% END EDIT (2018-06-18)\r\n\r\n\r\n%% Test 1\r\nglobal bncWordlist\r\nx =                 {'Vomftt qvstvfe, pqfo op eppst.', 'Ffmt dbo ljmm, opu pomz xpvoe.'};\r\ns_correct.shift = uint8(1);\r\ns_correct.message = {'Unless pursued, open no doors.', 'Eels can kill, not only wound.'};\r\ns_correct.certitude = uint8(79);\r\ns = decode(x, bncWordlist);\r\n%disp(' *** ');  disp(s.message);  disp(' *** ')\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.' )\r\nassert( isequal(s.message{1}, s_correct.message{1}), 'Wrong message{1}.' )\r\nassert( isequal(s.message{2}, s_correct.message{2}), 'Wrong message{2}.' )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.' )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.' )\r\nassert( isequal(s, s_correct), 'Wrong s.' )\r\nassert( isequal(class(s.shift), 'uint8'), 'Wrong class.' )\r\nassert( isequal(class(s.message), 'cell'), 'Wrong class.'  )\r\nassert( isequal(class(s.message{1}), 'char'), 'Wrong class.'  )\r\nassert( isequal(class(s.certitude), 'uint8'), 'Wrong class.'  )\r\n\r\n\r\n%% Test 2\r\nglobal bncWordlist\r\nx =                 {'Doo zduiduh lv edvhg rq ghfhswlrq.', ...\r\n    'Khqfh, zkhq deoh wr dwwdfn, zh pxvw vhhp xqdeoh;  zkhq xvlqj rxu irufhv, zh pxvw vhhp lqdfwlyh;  zkhq zh duh qhdu, zh pxvw pdnh wkh hqhpb eholhyh zh duh idu dzdb; zkhq idu dzdb, zh pxvw pdnh klp eholhyh zh duh qhdu.'};\r\ns_correct.shift = uint8(3);\r\ns_correct.message = {'All warfare is based on deception.', ...\r\n    'Hence, when able to attack, we must seem unable;  when using our forces, we must seem inactive;  when we are near, we must make the enemy believe we are far away; when far away, we must make him believe we are near.'};\r\ns_correct.certitude = uint8(95);\r\ns = decode(x, bncWordlist);\r\n%disp(' *** ');  disp(s.message);  disp(' *** ')\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% Test 3\r\nglobal bncWordlist\r\nx =                 {'Elia lrq yxfqp ql bkqfzb qeb bkbjv.  Cbfdk afploabo, xka zorpe efj.', ...\r\n    'Fc eb fp pbzrob xq xii mlfkqp, yb mobmxoba clo efj.  Fc eb fp fk prmboflo pqobkdqe, bsxab efj.'};\r\ns_correct.shift = uint8(23);\r\ns_correct.message = {'Hold out baits to entice the enemy.  Feign disorder, and crush him.', ...\r\n    'If he is secure at all points, be prepared for him.  If he is in superior strength, evade him.'};\r\ns_correct.certitude = uint8(100);\r\ns = decode(x, bncWordlist);\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% Test 4\r\nglobal bncWordlist\r\nx =                 {'Ax qgmj ghhgfwfl ak gx uzgdwjau lwehwj, kwwc lg ajjalslw zae.  Hjwlwfv lg tw owsc, lzsl zw esq yjgo sjjgysfl.', ...\r\n    'Ax zw ak lscafy zak wskw, yanw zae fg jwkl.', ...\r\n    'Ax zak xgjuwk sjw mfalwv, kwhsjslw lzwe.', ...\r\n    'Sllsuc zae ozwjw zw ak mfhjwhsjwv, shhwsj ozwjw qgm sjw fgl wphwulwv.'};\r\ns_correct.shift = uint8(18);\r\ns_correct.message = {'If your opponent is of choleric temper, seek to irritate him.  Pretend to be weak, that he may grow arrogant.', ...\r\n    'If he is taking his ease, give him no rest.', ...\r\n    'If his forces are united, separate them.', ...\r\n    'Attack him where he is unprepared, appear where you are not expected.'};\r\ns_correct.certitude = uint8(100);\r\ns = decode(x, bncWordlist);\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% Test 5\r\nglobal bncWordlist\r\nx =                 {'Aes cèwo vo foxd bémyvdo vo dowzy', ...\r\n    'Yx wo dbksdo no dbkîdbo aekxn to dbksdo no vk népksdo ne csvoxmo / Vo csvoxmo ocd n''yb, wksc t''ks mryscs vk mknoxmo', ... \r\n    'Mrkaeo wyd, mrkaeo zrbkco nsdc kfom owzrkco / Pksd no Mvkeno WM, vo mywwkxny no vk zrbkco', ...\r\n    'Mkb t''cesc ex WM n''kddkaeo, ckxc dsmc, kedroxdsaeo zkc ox dym / Zbêd à pbkzzob ceb vo lokd zyeb vo wyefowoxd rsz-ryz', ...\r\n    'Ne bkz n''kddkaeo aes pbkzzo, ézkdo, wkdbkaeo od zkdkdbkaeo / Zvec no ckxq de mvkaeoc, t''cesc WM noc Mkbzkdoc', ...\r\n    'Vo zénkqyqeo ox fyqeo ke xyw no myno Cyvkkb ye Mvkeno WM / Do zbyzyco n''émyedob moms / Ae''yx ézovvo voc fyiovvoc, nèc ae''yx cyxxo voc myxcyxxoc'};\r\ns_correct.shift = uint8([0 21]');\r\n% TIP:  The original message was not English!\r\ns_correct.message(1, :) = {'Aes cèwo vo foxd bémyvdo vo dowzy', ... \r\n    'Yx wo dbksdo no dbkîdbo aekxn to dbksdo no vk népksdo ne csvoxmo / Vo csvoxmo ocd n''yb, wksc t''ks mryscs vk mknoxmo', ... \r\n    'Mrkaeo wyd, mrkaeo zrbkco nsdc kfom owzrkco / Pksd no Mvkeno WM, vo mywwkxny no vk zrbkco', ... \r\n    'Mkb t''cesc ex WM n''kddkaeo, ckxc dsmc, kedroxdsaeo zkc ox dym / Zbêd à pbkzzob ceb vo lokd zyeb vo wyefowoxd rsz-ryz', ... \r\n    'Ne bkz n''kddkaeo aes pbkzzo, ézkdo, wkdbkaeo od zkdkdbkaeo / Zvec no ckxq de mvkaeoc, t''cesc WM noc Mkbzkdoc', ... \r\n    'Vo zénkqyqeo ox fyqeo ke xyw no myno Cyvkkb ye Mvkeno WM / Do zbyzyco n''émyedob moms / Ae''yx ézovvo voc fyiovvoc, nèc ae''yx cyxxo voc myxcyxxoc'}\r\ns_correct.message(2, :) = {'Fjx hèbt at ktci gérdait at itbed', ... \r\n    'Dc bt igpxit st igpîigt fjpcs yt igpxit st ap séupxit sj hxatcrt / At hxatcrt thi s''dg, bpxh y''px rwdxhx ap rpstcrt', ... \r\n    'Rwpfjt bdi, rwpfjt ewgpht sxih pktr tbewpht / Upxi st Rapjst BR, at rdbbpcsd st ap ewgpht', ... \r\n    'Rpg y''hjxh jc BR s''piipfjt, hpch ixrh, pjiwtcixfjt eph tc idr / Egêi à ugpeetg hjg at qtpi edjg at bdjktbtci wxe-wde', ... \r\n    'Sj gpe s''piipfjt fjx ugpeet, éepit, bpigpfjt ti epipigpfjt / Eajh st hpcv ij rapfjth, y''hjxh BR sth Rpgepith', ... \r\n    'At eéspvdvjt tc kdvjt pj cdb st rdst Hdappg dj Rapjst BR / It egdedht s''érdjitg rtrx / Fj''dc éetaat ath kdntaath, sèh fj''dc hdcct ath rdchdccth'}\r\ns_correct.certitude = uint8(11);\r\ns = decode(x, bncWordlist);\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% Test 6\r\nglobal bncWordlist\r\nx =                 {'Brvdujcnm mrbxamna yxbcdujcnb ynaonlc mrblryurwn;  brvdujcnm onja yxbcdujcnb lxdajpn;  brvdujcnm fnjtwnbb yxbcdujcnb bcanwpcq.' ...\r\n    'X mrerwn jac xo bdkcunch jwm bnlanlh!'};\r\ns_correct.shift = uint8(9);\r\ns_correct.message = {'Simulated disorder postulates perfect discipline;  simulated fear postulates courage;  simulated weakness postulates strength.' ...\r\n    'O divine art of subtlety and secrecy!'};\r\ns_correct.certitude = uint8(12);\r\ns = decode(x, bncWordlist);\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% Test 7\r\nglobal bncWordlist\r\nx =                 {'Nv treefk vekvi zekf rcczretv nzky evzxysfizex gizetvj lekzc nv riv rthlrzekvu nzky kyvzi uvjzxej.', ... \r\n    'Nv riv efk wzk kf cvru re ridp fe kyv drity lecvjj nv riv wrdzczri nzky kyv wrtv fw kyv tflekip — zkj dflekrzej reu wfivjkj, zkj gzkwrccj reu givtzgztvj, zkj drijyvj reu jnrdgj.', ... \r\n    'Nv jyrcc sv lerscv kf klie erklirc rumrekrxvj kf rttflek lecvjj nv drbv ljv fw cftrc xlzuvj.'};\r\ns_correct.shift = uint8(17);\r\ns_correct.message = {'We cannot enter into alliance with neighboring princes until we are acquainted with their designs.', ...  \r\n    'We are not fit to lead an army on the march unless we are familiar with the face of the country — its mountains and forests, its pitfalls and precipices, its marshes and swamps.', ...  \r\n    'We shall be unable to turn natural advantages to account unless we make use of local guides.'};\r\ns_correct.certitude = uint8(97);\r\ns = decode(x, bncWordlist);\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% Test 8\r\nglobal bncWordlist\r\nx =                 {'Oa oqvvq''u cnycau dggp: \"Ctu itcvkc ctvku\".'};\r\ns_correct.shift = uint8(2);\r\ns_correct.message = {'My motto''s always been: \"Ars gratia artis\".'};\r\ns_correct.certitude = uint8(73);\r\ns = decode(x, bncWordlist);\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% Test 9\r\nglobal bncWordlist\r\nx =                 {'Bestow rewards without regard 2 rule;  issue orders without regard 2 previous arrangements', ...\r\n    '\"Let advance bee richly rewarded \u0026 retreat bee heavily punished.\"', ...\r\n    ' Qwertyuiop''asdfghjkl.   Zxcvbnm-0123456789 = pass. ', ...\r\n    'αβγδ — persimon–apricot hybrid.', ...\r\n    'aIanasatbebydoheifinisitmemynoofonor''ssotoupweallandanyarebutcandidforgethadhasherhimhishowitsmaynewnotnown''toneouroutseeshethetwowaswaywhoyoualsobeenfromhaveintojustknowlikemoreonlysaidsomethanthatthemthentheythistimeverywellwerewhatwhenwillwithyouraboutcouldfirstothertheirtherethesewhichwouldpeopleshould'};\r\ns_correct.shift = uint8(0);\r\ns_correct.message = x;\r\ns_correct.certitude = uint8(0);\r\ns = decode(x, bncWordlist);\r\nassert( isequal(s.shift, s_correct.shift), 'Wrong shift.'  )\r\nassert( isequal(s.message, s_correct.message), 'Wrong message.'  )\r\nassert( isequal(s.certitude, s_correct.certitude), 'Wrong certitude.'  )\r\n\r\n\r\n%% TIMING \r\n% Note:  The Time Trial section does not check accuracy; that is done above.\r\n\r\n% Acknowledgements  \r\n% Portions of this timing test code were inspired by:\r\n% (1) Problem 937. \"Rubik's Mini Cube: Solve Randomized Cube in 11 Moves or Less; Score is by Time (msec)\" by Richard Zapor.\r\n% (2) Problem 2733. \"Evil Number\" by Jan Orwat.\r\n% (3) Feedback in comments from Peng Liu.\r\n% (4) Problem Problem 1237. \"It's race time! Write a faster function than the test suite call of unique().\" by Jeremy.\r\n\r\n% INITIALISE\r\nglobal bncWordlist\r\nx =                 {'Vomftt qvstvfe, pqfo op eppst.', 'Ffmt dbo ljmm, opu pomz xpvoe.'};\r\nqSmall = 50;\r\nqBig = 1000;\r\n%cutoffTimeBig = 10;    % Maximum allowable walltime (in seconds) to run function in a loop with qBig iterations.\r\n\r\n% EDIT (2018-06-17).  Reduced time [slightly] to pose reasonable challenge.\r\n% Accounted for improving Cody server speed per Problem 44655.\r\ncutoffTimeBig = 8;    % Maximum allowable walltime (in seconds) to run function in a loop with qBig iterations.\r\ntRef = datetime('2018-06-17', 'InputFormat','yyyy-MM-dd');\r\ntNow = datetime('now');\r\nyearsElapsed = (datenum(tNow) - datenum(tRef)) / 365.24;\r\ndisp(' . ');\r\nfprintf('\\r\\n\\r\\n\\r\\nSubmission evaluated for speed on %s.\\r\\n', datestr(tNow, 'dd mmmm yyyy'))\r\nrInf = 0.2;   delta = cutoffTimeBig - rInf;  tau = 3.6;  % Data from Problem 44655, based on Problem 963.\r\nqBig = ceil( qBig * (cutoffTimeBig - rInf) * exp(yearsElapsed/tau) / delta );\r\nfprintf('\\r\\n\\r\\n\\r\\nTo account for computational power increases over time, number of iterations increased to %u.\\r\\n', qBig)\r\n% END EDIT (2018-06-17)\r\n\r\n\r\n% *** PRELIMINARY TIMING WITH timeit ***\r\nfDecode = @()   decode(x, bncWordlist);\r\ndt_timeit = timeit( fDecode );\r\nfor dummy = 1 : 10,  disp(' . ');  end;\r\nfprintf('APPROXIMATE time to decode %u message batches ~ %2.2f seconds, according to ''timeit''.\\n\\r', qBig, dt_timeit * qBig)\r\n\r\n% *** PRELIMINARY TIMING WITH SHORT LOOP ***\r\n% In case the submitted function has a lot of text output, \r\n% get an estimate based on just a few iterations\r\n% Initialise\r\nt0 = clock;\r\n\r\n% Loop\r\nfor i = 1 : qSmall\r\n    solution = decode(x, bncWordlist);\r\nend;\r\n\r\n% Compute and display elapsed time.\r\ndt = etime(clock, t0);\r\nfor dummy = 1 : 10,  disp(' . ');  end;\r\n%fprintf('Your wall time to decode %u message batches = %i seconds.\\n\\r', qSmall, floor(dt))\r\nfprintf('APPROXIMATE wall time to decode %u message batches ~ %2.2f seconds, by extrapolating from %u batches.\\n\\r', qBig, dt * qBig / qSmall, qSmall)\r\n\r\n% *** 'OFFICIAL' TIMING ***\r\n% Re-initialise timer\r\nt0 = clock;\r\nt0_cpu = cputime;\r\n\r\n% Loop\r\nfor i = 1 : qBig\r\n    % EDIT (2018-06-17).   Ensure each case is unique.\r\n    characters = ['  ,   .' char(randi([97,122], [1,23]))];\r\n    x{2} = characters( randperm(30) );\r\n    % END EDIT (2018-06-17)\r\n    solution = decode(x, bncWordlist);\r\nend;\r\n\r\n% Compute and display elapsed time.\r\ndt = etime(clock, t0);\r\nfor dummy = 1 : 10,  disp(' . ');  end;\r\nfprintf('Your wall time to decode %u message batches = %2.2f seconds.\\n\\r', qBig, dt)\r\n\r\ndt_cpu = (cputime - t0_cpu);\r\nfprintf(' ( Your CPU time for this = %2.2f seconds. ) \\n\\r', dt_cpu)\r\n\r\n% Display (default) Cody size-based score.\r\nall_nodes = mtree('decode.m', '-file');\r\nsize_score = count(all_nodes);\r\nfprintf('Your Cody-standard size-based score = %i.\\n\\r', size_score)\r\n\r\n% Report revised performance score\r\ncombinedScore = size_score + round(dt * 10);\r\nfprintf('Your combined score = %i.\\n\\r', combinedScore)\r\ndisp('     -----=====|||||=====-----     ')\r\n\r\n% Now disallow any candidate solutions that are TOO SLOW!\r\nif dt \u003e cutoffTimeBig, \r\n    fprintf('Sorry, your submission is TOO SLOW.  It must be able to finish within %u seconds.\\n\\r', cutoffTimeBig)\r\nend;\r\n\r\nassert( dt \u003c= cutoffTimeBig, 'Exceeded time limit specified in Test Suite.' )","published":true,"deleted":false,"likes_count":2,"comments_count":16,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":13,"test_suite_updated_at":"2019-07-02T13:23:18.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2017-10-12T23:17:24.000Z","updated_at":"2026-04-02T20:05:58.000Z","published_at":"2017-10-15T06:52:40.000Z","restored_at":"2017-10-25T07:03:11.000Z","restored_by":null,"spam":false,"simulink":false,"admin_reviewed":true,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have been tasked with decoding several batches of coded messages that have been intercepted.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBased on previous intelligence that has been gathered, you can be confident that the messages were all encoded using a simple\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Caesar_cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCaesar cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (a type of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Substitution_cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esubstitution cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e), an example of which is the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/ROT13\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eROT13 cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (discussed in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/78-implement-a-rot13-cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody Challenge Problem 78\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e). As in the Cody Challenge Problem, uppercase and lowercase letters are handled independently of one another, and all other characters (e.g. punctuation, numbers, accented letters) are unchanged. Unlike the Cody Challenge Problem, here the number of letters to shift is not known in advance, and will vary\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ebetween\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (not within) batches — also, here you need to decode, not encode.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThese latest activities that you are investigating have been nicknamed 'Operation Xiangliu' by your own organisation. A few decoding options are at your organisation's disposal:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTest the candidate decodings against all words in a large dictionary — this could work, but it is very slow.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTest the candidate decodings for the appearance of a name or phrase that is certain to appear regularly (e.g.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44351\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\\\"Operation Phoenix\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e) — unfortunately as yet there is not enough knowledge of the activities to be sure of a suitable name or phrase to use.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTest the candidate decodings against all words in a short list comprising, say, the hundred most frequently used English words.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ethird option\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e will be faster than the first option, and more reliable than the second option, so this is the approach you will be taking.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have been careful to avoid using 'lemmatised' lists (which contain e.g. the verb \\\"to be\\\", rather than the various inflected forms such as \\\"am\\\", \\\"is\\\", \\\"are\\\") like those based on the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://web.archive.org/web/20111226085859/http://oxforddictionaries.com/words/the-oec-facts-about-the-language\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOEC\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e or\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.wordfrequency.info/free.asp?s=y\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCOCA\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, and after setting aside\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://world-english.org/english500.htm\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eanother list\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e you finally choose the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://ucrel.lancs.ac.uk/bncfreq/samples/120.pdf\\\"\u003e\u003cw:r\u003e\u003cw:t\u003elist based on the BNC\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e as the most reliable, and will use the first 100 words on that list. This list will be available for you to access as an input variable,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ebncWordlist\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, to your function. Note: (i) some entries on the list are morphemes (e.g. \\\" n't \\\" and \\\" 's \\\") rather than words; (ii) some entries appear more than once (representing different grammatical word classes). Of course, in the original messages any capitalisation might be used.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have been instructed that your 'certitude' (degree of confidence) in the decoding must be reported for each batch, and shall depend proportionally upon the sum of the characters for the words/morphemes in the decoded message that match words/morphemes in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ebncWordlist\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Being able to match words/morphemes accounting for three-tenths of the characters (excluding spaces) shall correspond to 100% certitude; matching three-twentieths would be 50% certitude, and so on. Certitude shall be reported as a percentage, rounded\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eup\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to the nearest integer, not greater than 100. You need to maximise your certitude for each batch by appropriate choice of the shifting parameter. If there are multiple shifts of equal certitude, report both options on different rows (arranged in order of ascending shift parameter).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour task is to crack the codes and report back in a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/struct.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003estructure array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e: (1) the shifting parameter that had been used in the encoding [as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/uint8.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003euint8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e] (usually scalar, but may be column vector); (2) the decoded messages [as a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/cell.html?s_tid=doc_ta\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ecell array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (containing\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/char.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003echaracter arrays\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e)] (usually an array with a single row, but occasionally with multiple rows); (3) your 'certitude' in the decoding [as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://au.mathworks.com/help/matlab/ref/uint8.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003euint8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e] (always scalar). The name of the structure array shall be\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, with respective fields\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eshift\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emessage\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecertitude\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eEXAMPLE 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose the batch contained two encoded messages —\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Vomftt qvstvfe, pqfo op eppst.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Ffmt dbo ljmm, opu pomz xpvoe.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (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. Thus the original messages would have been: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Unless pursued, open no doors.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Eels can kill, not only wound.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e . Twelve of the 51 characters have been matched: \\\"no\\\", \\\"can\\\", \\\"not\\\", and \\\"only\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe correct answer would therefore comprise:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[s.shift = uint8(1)  \\ns.message = {'Unless pursued, open no doors.', 'Eels can kill, not only wound.'}\\ns.certitude = uint8(79)]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eEXAMPLE 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose the batch contained one encoded message —\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Oa oqvvq'u cnycau dggp: \\\"Ctu itcvkc ctvku\\\".\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (provided as a character array within a cell array) — and a (right-shifting) ROT2 cipher had been applied. In that case A→C, B→D, ..., Y→A, and Z→B; similarly, a→c, b→d, ..., y→a, and z→b. Thus the original message would have been: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"My motto's always been: \\\"Ars gratia artis\\\".\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e . Eight of the 37 characters have been matched: \\\"My\\\", \\\" 's \\\", and \\\"been\\\". Note carefully that: \\\" 's \\\" should only be matched once; \\\"to\\\" (in motto), \\\"be\\\" (in been), \\\"at\\\" (in gratia), \\\"is\\\" (in artis) and \\\"a\\\" (passim) should\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enot\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e be matched at all; and \\\" ' \\\" will only ever be used as an apostrophe (never as a quotation mark).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe correct answer would therefore comprise:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[s.shift = uint8(2)  \\ns.message = {'My motto''s always been: \\\"Ars gratia artis\\\".'}\\ns.certitude = uint8(73)]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf the batch of messages cannot be decoded when following the above assumptions, then return the original encoded message(s) unchanged, with a shift of zero and a certitude of zero.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNote: 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.)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo 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\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e----------\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44356\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOperation Orthos\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem: TBA.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"substitution cipher\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"substitution cipher\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"substitution cipher\"","","\"","substitution cipher","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f74d8aacef0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f74d8aace50\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f74d8aabaf0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f74d8aad490\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f74d8aad350\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f74d8aad170\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f74d8aad030\u003e":"tag:\"substitution cipher\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f74d8aad030\u003e":"tag:\"substitution cipher\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"substitution cipher\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"substitution cipher\"","","\"","substitution cipher","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f74d8aacef0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f74d8aace50\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f74d8aabaf0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f74d8aad490\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f74d8aad350\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f74d8aad170\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f74d8aad030\u003e":"tag:\"substitution cipher\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f74d8aad030\u003e":"tag:\"substitution cipher\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":751,"difficulty_rating":"easy-medium"},{"id":44351,"difficulty_rating":"medium"},{"id":1219,"difficulty_rating":"medium"},{"id":44356,"difficulty_rating":"medium"},{"id":78,"difficulty_rating":"medium"},{"id":44383,"difficulty_rating":"hard"}]}}