{"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":58309,"title":"Decode a message encrypted with the square root of 2","description":"Cody Problem 58299 asks you to encrypt a message by changing all letters to uppercase and randomly choosing a position of the ASCII codes of the message’s characters in the fractional part of the square root of 2. \r\nWrite a function to decrypt a message encrypted in this way. A string with the fractional part of the square root of 2 will be set as a global variable. ","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 93px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 46.5px; transform-origin: 407px 46.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/58299\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eCody Problem 58299\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 318.25px 7.79167px; transform-origin: 318.25px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e asks you to encrypt a message by changing all letters to uppercase and randomly choosing a position of the ASCII codes of the message’s characters in the fractional part of the square root of 2. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 375.85px 7.79167px; transform-origin: 375.85px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to decrypt a message encrypted in this way. A string with the fractional part of the square root of 2 will be set as a global variable. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function plainText = sqrt2decode(codes)\r\n    global sqrt2str    \r\n    plainText = lower(char(codes));","test_suite":"%%\r\nglobal sqrt2str    \r\ns = webread('https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil');\r\nsqrt2str = s(1230:1013886);\r\nsqrt2str(strfind(sqrt2str,newline))='';\r\n\r\n%%\r\nq = char(39);\r\ncodes = [788502 255791 27020 945829 39750 862438 213469 205939 293186 194403 50849 837227 23680 777170 698302 887866 619631 541941 982637 960122 234631 405512 547855 7950 961111 91948 538721 21556 485674 552780 551227 320494 925276 196927 834812 175040 135063 344979 792360 400370 469032 540401];\r\npt_correct = upper(['The second story is about Dad' q 's curiosity.']);\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\nq = char(39);\r\ncodes = [591914 840747 541787 614044 807979 224189 355892 423494 682550 521338 981361 189419 808050 911915 944373 993776 744132 141150 759296 470235 962630 749010 460347 84966 790276 787817 319305 979496 233714 186900 42661 940998 439124 635374 714432 874739 344720 559441 147867 943984 363638 287105 261004 143310 60790 716550 170461 818242 211318 553585 727730 710292 129282 257363 748485 549687 839045 126476 547047 182108 682959 508052 808232 885200 363418 329536 57967 642295 589575 616984 402549 260202 979043 216849 529738 84559 565832 313592 320640 340234 592569 217347 316676 832012 5983 699060 75169 679439 340234 12261 750307 876342 23148 697438 743464 931178 659875 688560 685356 543369 919439 878282 239111 639197 671002 497435 497412 39393 783994 834103 996336 414857 577983 704120 984777 936848 364327 621288 77986 941878 320709];\r\npt_correct = upper(['In 2005 Mom and Dad celebrated their 40th anniversary by taking my family and Rich' q 's family to Yellowstone National Park.']);\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [130393 353677 738370 903643 3564 581437 23834 833430 262988 712081 16900 912092 802225 602317 934440 465768 185278 613819 927070 996389 565011 941667 82469 674306 739868 990449 880811 547348 362880 346445 451459 581009 880364 273794 840619 443295 299931 237038 453095 243319 785884 388159 133746 88672 649683 182750 109587 952810];\r\npt_correct = upper('Emily, Jessica, and Erin were 7, and Jack was 5.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [754611 950965 10682 389736 791866 342532 102974 144421 252303 73534 335719 286872 799001 911457 558320 735276 445852 162269 341612 724458 659261 408095 808407 141183 191383 41810 235799 416988 324369 791369 567235 328209 121501 601989 601543 408744 167084 3717 824309 907688 878173 770788 395269 674521 653516 737417 136250 693004 18695 42938 83298 893791 232968 359547 716373 154081 944005 147781 278690 762395 641626 127746 81379 71050 877584 975323 566081 195409 894256 626719 559483 571802 577642 16613 739008 451833 899673 629239 918889 141859 413590 347966 363156 592562 231361 551641 20802 536555 990082 560638 790578 694214 980663 34729 784078 735631 468633 421305 80487 674917 320121 911694 240267 937464 470537 351783 151386 498420 852973 266751 64522 700849 559501 180540 748748 421710 23821 773760 521658 872461 46507 170227 380893 630380 470998];\r\npt_correct = upper('We rented a house just north of the park, and each day we would drive into the park, hike, look around, and have a good time.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\nreturn\r\n%%\r\ncodes = [795554 916296 609526 964161 695721 316971 184761 995970 266520 372060 961810 141668 545585 961948 77562 101395 313351 626929 592332 915942 564670 74989 740347 230199 979137 250117 850171 392964 21946 601540 929567 372822 49420 326527 406967 946046 469754 901551 536890 276080 770713 892243 518762 106576 356027 349536 88013 889364 820052 92222 178525 764598 427260 5428 931322 493289 458443 397376 227644 344694 43454 422565 436175 675426 481710 363855 839576 809669 6096 862646 868151 80582 469790 785432 185031 479943 517627 736502 647035 333836 687834 756796 338464 685802 771298 364368 795086 849955 539110 533454 152212 3302 362512 564341];\r\npt_correct = upper('One day we did a longer hike in the afternoon, and we got back to the trailhead at about 3:30.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [433619 361932 263909 633917 906791 754700 980868 343228 222731 890095 524316 563776 397399 132600 680546 668607 438140 321071 805906 496701 693041 768408 20571 272011 399281 285213 716350 96621 987090 494180 152677 259740 690358 101937 535101 843614 433418 20389 504142 488418 833388 329794 371125 844722 587487 188995 148130 696600 461262 242053 815556 214532 140403 419590 908775 203875 426488 832429 474735 395921 161487 388018 104229 912866 285076 366249 624917 984821 24650 88627 633980 500662 441589 398552 177690 284750 203599 832775 221514 258473 976865 619947 184664 94396 641391 955689 607555 187076 45741 994279 107342 933440 682434 889317 477797 320616 771084 683748 123450 832795 900659 746748 624682 848007 106925 278622 498171 407820 838018 655752 881940 755789 307415 59113 88563 671463 343076 356192 784691 873480 830588 302810 614106 610568 552571 67563 131474 491463 731918 649492 686731 445936 644832 341843 103686 284086 809024 199624 351857 285876 454377 385273 104534 988018 741067 874701 39888 283400 748867 714383 373782 889059];\r\npt_correct = upper('The kids were still in a good mood, and Rachel and I conferred with Rich and Linda and decided that we should cash in and go back to the house to relax.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [167556 474211 663454 115461 486354 938339 631867 813176 737577 690044 119052 152807 444464 842736 537866 373682 837581 749562 948090 600925 460722 570223 209018 328233 373068 940568 163357 821183 704097 822151 503235 860532 392050 902720 487776 967001 895851 886875 682959 184272 467861 783155 314860 489562 308207 246282 147724 255693 805133 418620 787837 157401 510425 214735 4011 687662 931736 151640 178440 592599 255168 38953 659890 410039 578110 442952 56418 126147 709926 566995 583694 119225 97183 367892 313731 912247 339835 88125 264356 208256 900925 229755 633349 382384 821443 540083 138049 630212 600814 751628 656641 937464 423947 103959 214030 808489 551110 449657 960942 620402 246227 884689 238183 817614 238863 970646 386227 206878 644865 650439 667567];\r\npt_correct = upper('We put this proposal to Dad, and he said, \"Go back? Go back? No, no, no. It s only 3:30. We have lots of time.\"');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [847195 489238 932356 941838 570042 125554 333302 26477 864818 972834 78484 116618 694757 37480 334824 543926 751331 677139 425174 49214 994351 301356 527563 900706 597544 757695 174204 788243 534161 313938 261897 400076 309885 940984 400579 937596 719137 88663 78401 259841 407299 476462 814525 960001 510963 843120 298987 743365 369317 880318 841610 616494 711255 183995 308204 811330 705417 23948 874346 248132 219931 270392 881875 16098 346395 130953 172094 735017 371737 27894 529528 827883 392187 965876 366814 195346 677687 100 938958 599570 211501 590803 598238 92682 538000 70897 998293 440121 693754 784471 982010 112719 951702 672967 863564 317677 670237 653064 677098];\r\npt_correct = upper('Then he grabbed the Yellowstone map, spread it on the hood of the car, and pointed almost randomly.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\nq = char(39);\r\ncodes = [659320 227631 274954 718019 651014 371165 90419 547936 317455 946494 988215 169233 342180 130386 204141 822640 161285 426905 417984 207163 589783 420227 603900 676725 843999];\r\npt_correct = upper(['He said, \"Let' q 's go here.\"']);\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [697309 498072 139847 616036 460434 91452 460049 801786 612552 663239 372588 26278 183603 883838 358687 160398 932996 396412 686984 337273 713022 633761 769926 215964 689835 462089 943462 753637 535076 115291 994724 3419 555297 719602 471788 145791 723544 428585 466474 918338 954330 115873 790601 260309 157927 468630 461749 451143 352455 722311 453168 765065 285284 615985 639710 391035 45275 852754 705774 653389 844419 250764 587009 169123 295209 172519 103647 953318 78379 984660 409662 973003 431205 181530 903980 222751 803846 372510 958505 674419 578821 438449 652375 364347];\r\npt_correct = upper('So we drove to Sheepeater Cliff, a strange collection of hexagonal basaltic columns.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [248382 28142 308843 198878 522209 501100 114082 524301 41728 591654 734162 358080 267045 786562 134945 980838 776756 258108 844560 500391 85520 244430 759558 892488 337528 342260 668309 660014 162477 914632 365677 70299 412709 627387 974605 61589 62723 955839 292791 488375 695447 605042 388139 744611 468706 980514 249861 32825 160953 581148 410573 665712 167314 644379 269246 764369 480738 613239 14331 712262 280652 565540 769487 497534 723639 508704 499408 350746 73072 672769 994335 315268 496012 974183 1498 548405 297216 315786 66804 620984 306854 405545 353531 886945 419244 824728 324108 673613 421052 744385];\r\npt_correct = upper('We scrambled around the cliff until Dad was satisfied, and then we went back to the house.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [946597 293692 607859 938608 195470 794966 175585 426655 901655 457473 741935 803059 844573 292673 98914 66996 398586 876946 701685 247360 141821 611297 119627 439960 415389 304087 858406 220637 900247 798981 636234 352816 378028 190737 12127 415458 471321 225243 848144 601432 765394 220923 632078 155806 156567 780760 559788 186935 327665 259956 826206 155281 936557 565784 280768 871309 84802 111886 965175 957035 931461 218547 699475 928012 773524 84155 48488 834409 370702 713812 459131 946955 499022 269242 148694 250841 835205 932715 413817 972046 572769 557057 725054 378723 717701 431270 839971 781573 960753 111628 546546 623231 182341 727399 43130 339778 344390 76380 555200 389839 281228 322099 942878 493340 637660 317037 28165 976843 415111 128764 467283 859972 453882 548187 246210 867571 104467 591830 582522 979085 359934 579883 167577 985704 786720 416834 300316 975464 390035 69573 659541 804039 639358 15738 17376 151971 233066 232014 462511 676976 877410 783161 963955 925501 695980 615636 519207 136935 354380];\r\npt_correct = upper('While the rest of us got cleaned up, Dad grabbed his camera and field guide of wildflowers and explored the hill by the house for another hour or so.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\nfiletext = fileread('sqrt2decode.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'assert'); \r\nassert(~illegal)\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":46909,"edited_by":46909,"edited_at":"2023-05-18T20:47:43.000Z","deleted_by":null,"deleted_at":null,"solvers_count":3,"test_suite_updated_at":"2023-05-18T20:47:43.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2023-05-17T12:34:14.000Z","updated_at":"2023-05-18T20:47:43.000Z","published_at":"2023-05-17T12:35:40.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/58299\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody Problem 58299\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e asks you to encrypt a message by changing all letters to uppercase and randomly choosing a position of the ASCII codes of the message’s characters in the fractional part of the square root of 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to decrypt a message encrypted in this way. A string with the fractional part of the square root of 2 will be set as a global variable. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":58299,"title":"Encrypt a message with the square root of 2","description":"Suppose you want to encrypt the word ‘TWIN’. The ASCII codes for the four letters are 84, 87, 73, and 78. If you consider the fractional part of the square root of 2 as a string \r\n4142135623730950488016887242096980785696718753769480731766797379907324784…\r\nthen those ASCII codes are found at positions 72, 24, 11, and 35. \r\nThose ASCII codes can be found in other positions in the fractional part of the square of 2. So to add a layer of complexity to the code, choose one of those positions randomly.\r\nWrite a function to encrypt a message in this way. Make sure to convert the string to all uppercase before encrypting. A string with the fractional part of the square root of 2 will be set as a global variable, and a seed will be passed to the function to be used in the command rng(seed).","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 225.45px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 112.725px; transform-origin: 407px 112.725px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 377.25px 7.79167px; transform-origin: 377.25px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSuppose you want to encrypt the word ‘TWIN’. The ASCII codes for the four letters are 84, 87, 73, and 78. If you consider the fractional part of the square root of 2 as a string \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 38.9167px 7.79167px; transform-origin: 38.9167px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e4142135623\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 7.78333px 7.79167px; transform-origin: 7.78333px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; text-decoration-line: underline; \"\u003e73\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 42.8083px 7.79167px; transform-origin: 42.8083px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e09504880168\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 7.78333px 7.79167px; transform-origin: 7.78333px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; text-decoration-line: underline; \"\u003e87\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 35.025px 7.79167px; transform-origin: 35.025px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e242096980\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 7.78333px 7.79167px; transform-origin: 7.78333px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; text-decoration-line: underline; \"\u003e78\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 136.208px 7.79167px; transform-origin: 136.208px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e56967187537694807317667973799073247\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 7.78333px 7.79167px; transform-origin: 7.78333px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; text-decoration-line: underline; \"\u003e84\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 7px 7.79167px; transform-origin: 7px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e…\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 204.067px 7.79167px; transform-origin: 204.067px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ethen those ASCII codes are found at positions 72, 24, 11, and 35. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 378.833px 7.79167px; transform-origin: 378.833px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThose ASCII codes can be found in other positions in the fractional part of the square of 2. So to add a layer of complexity to the code, choose one of those positions randomly.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63.45px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.725px; text-align: left; transform-origin: 384px 31.725px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 369.242px 7.79167px; transform-origin: 369.242px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to encrypt a message in this way. Make sure to convert the string to all uppercase before encrypting. A string with the fractional part of the square root of 2 will be set as a global variable, and a seed will be passed to the function to be used in the command \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 34.65px 7.79167px; transform-origin: 34.65px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 34.65px 8.25px; transform-origin: 34.65px 8.25px; \"\u003erng(seed)\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 7.79167px; transform-origin: 1.94167px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function codes = sqrt2encode(plainText,seed)\r\n    rng(seed)\r\n    global sqrt2str    \r\n    codes = upper(plainText)-'0';","test_suite":"%%\r\nglobal sqrt2str    \r\ns = webread('https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil');\r\nsqrt2str = s(1230:1013886);\r\nsqrt2str(strfind(sqrt2str,newline))='';\r\n\r\n%%\r\nplainText = 'I saw Dad perform magic during one of the summers I worked for ARH.';\r\ncodes = sqrt2encode(plainText,42019);\r\ncodes_correct = [223124 798599 978403 455173 284845 749545 615179 709672 38243 46615 667887 23967 794350 275426 157253 18430 145665 306458 238497 614769 776279 643258 345627 330905 417218 179372 772145 795751 874773 711886 267045 548909 872617 35262 994765 222229 424408 283211 513854 593128 731753 685546 734347 328397 176774 32918 704799 900849 469604 290918 97195 819322 172170 699232 382524 296115 389461 328625 48922 429346 542715 655707 848636 884849 726843 667807 277835];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'He asked me to join him in a meeting with two people, one representing homeowners in a development and one representing the developer.';\r\ncodes = sqrt2encode(plainText,36324);\r\ncodes_correct = [840645 771842 937102 530200 978980 728204 464519 806712 45168 395736 555743 831876 749138 841485 496701 352299 1807 974698 993855 5838 497794 481196 491801 702863 924616 551857 401810 776187 734817 936180 366400 646601 708374 514864 195382 851891 890952 864338 452058 416814 279731 503733 775575 701746 602791 277181 161579 578802 550109 925506 608326 801014 248373 707878 762391 681161 566432 265271 653887 621872 356572 79785 987933 320607 778708 717071 291787 118700 825375 311010 236754 42813 449527 682299 514815 912774 938008 904057 744777 47197 611693 600275 117261 373909 650455 761309 138008 139093 531567 422758 477198 683032 154887 958961 944502 86330 843195 989256 546798 5542 89457 664362 445955 81196 558347 244517 879887 756587 891352 494171 484610 206732 332995 58655 436728 544528 783866 47525 526928 604372 996076 439122 281661 750778 44504 177788 999213 717342 330638 94112 896799 95484 62626 816987];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'The problem was that the drainage was designed to have water flow in the gutters of the streets, but the homeowners had built their driveways out into the streets.';\r\ncodes = sqrt2encode(plainText,18488);\r\ncodes_correct = [321121 230763 35765 330707 177259 486507 283793 584504 841874 124863 373658 754880 173668 810399 492673 168148 519669 123643 844180 708707 516212 348866 843957 878658 798058 848514 818400 841336 413602 105584 861511 122155 862742 78137 466085 375674 957950 91664 610170 551786 245359 748728 34331 686417 334888 509135 294380 834038 141576 345016 88703 997053 571436 296585 353309 273171 898589 124998 706867 994612 350816 617589 287235 78283 15632 907573 709684 406526 885556 90801 787455 371520 714916 42884 505054 738788 816384 93589 818073 872000 929403 558633 842301 312252 917957 594021 601548 888694 262133 664396 83014 94828 512806 587767 624017 496555 226167 910140 417827 484902 804796 282314 460051 274238 957884 895974 383711 472150 518405 149372 320652 432433 676603 883779 169730 853162 484982 868065 749876 651124 838751 147402 804330 724100 418815 983300 866646 570490 773188 286223 762038 703169 898545 180637 178107 631248 565936 739438 107998 704247 596656 780382 971578 709185 56046 135579 181505 363289 544904 179179 450588 610565 258754 604877 982427 87639 981775 285265 798832 242863 713183 964683 667975];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'The bumps from the driveways formed dams or jetties that blocked the flow and caused the streets to flood.';\r\ncodes = sqrt2encode(plainText,51829);\r\ncodes_correct = [559174 959043 443978 19661 96720 653316 533298 666730 561762 474394 240233 467260 19199 21539 625645 245508 961914 38714 660871 884673 897250 762702 229766 145324 117088 853018 841343 296495 860283 661380 761217 744354 685237 135066 877584 337692 138429 374879 445281 38171 627123 503760 741935 861210 817938 246658 570724 76719 679134 492337 693975 175953 444356 774100 4398 965746 419546 227944 785543 744991 852894 360056 837372 663401 771775 518768 830420 675226 956910 459830 982955 867477 73830 868315 954176 482652 707404 449168 636293 422238 243525 611047 151971 352845 519167 837283 41344 20546 995970 988988 720231 24887 735815 565332 867380 698306 174792 167939 526795 366650 672467 379225 77241 245805 651305 579437];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'Well, I was 19, in college, with a few engineering courses under my belt.';\r\ncodes = sqrt2encode(plainText,861);\r\ncodes_correct = [741766 693550 412918 393923 23868 146599 108034 289125 448147 47260 182083 486934 531457 338970 364814 904030 37099 211786 137647 871968 81878 300698 674094 513347 912965 853344 703367 247683 614808 283317 429798 370485 889473 845417 642511 320512 806961 719170 432008 45528 58248 318510 607881 494958 134631 406967 484602 658731 534811 301044 714916 170724 605299 211510 393819 835870 373075 825408 315707 955424 707953 159625 392964 850391 721400 84737 660904 341368 615454 359906 8245 468399 12493];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'In other words, I knew everything.';\r\ncodes = sqrt2encode(plainText,96894);\r\ncodes_correct = [269386 637630 91664 353803 849816 418977 175851 814791 539970 186111 188007 641861 505538 568474 429843 190532 42449 10095 781485 534228 958467 487276 715281 263427 493314 994939 113689 25382 105538 408542 671040 771308 161174 468806];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'To me the answer was clear: the homeowners were wrong.';\r\ncodes = sqrt2encode(plainText,80139);\r\ncodes_correct = [61854 637930 11818 867169 566024 878564 663726 313638 294774 213078 576444 142495 471596 781798 526374 920477 486229 851016 81057 45834 549938 612045 421202 52071 303288 897896 95948 861082 750380 140121 735206 462303 376667 15734 139975 943980 888374 152442 67559 183807 422802 211309 256624 950459 876456 517758 550992 134351 466733 245786 169468 138360 13457 38223];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'They extended their driveways beyond their property, so the only way their representative was going to walk away somewhat happy was if he could find a discounted rate for renting jackhammers.';\r\ncodes = sqrt2encode(plainText,75732);\r\ncodes_correct = [331780 396048 772398 823482 206638 619134 166004 183822 192939 173918 128491 595286 70650 56481 832793 930929 748974 855317 726883 444853 250606 169878 816827 68694 791866 864884 450841 324829 208486 269300 328100 729357 106496 267978 8977 254528 393095 64792 624809 937056 875247 519438 933039 368367 381943 97140 644226 334285 917854 608861 572236 415820 926228 410900 357583 751694 47351 833160 287490 869940 18045 834836 813692 899907 330332 368900 746027 744420 437695 958319 863963 951966 538853 651884 569852 129570 426577 628064 693187 990364 551488 925439 578084 761401 598056 685320 609872 123192 113848 315277 361346 357726 42108 438373 342933 144056 1574 465716 16489 468628 588449 870829 659672 416763 113612 295902 930538 369475 316687 477779 812547 469106 666864 96836 761313 883128 337794 450757 15063 570575 806754 700070 975535 457881 658354 411453 652628 911820 875859 405412 426618 408248 295490 772809 687756 851479 762287 15153 208272 46022 752685 223363 83707 610022 503222 388129 164391 355355 355405 374590 785289 117733 944359 453181 258559 281272 486286 534769 198087 171165 808003 918907 557874 577678 364565 209517 19231 848822 351216 219569 372941 609505 261343 385421 59783 56874 718039 829141 591210 292827 873147 313937 992940 497901 272011 462227 748321 764448 816747 363745 596448];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'But Dad listened to the two of them and somehow came up with a solution that satisfied them both.';\r\ncodes = sqrt2encode(plainText,67149);\r\ncodes_correct = [757661 815797 952576 34930 297252 638137 326352 954388 497168 103546 968551 135070 520374 565378 104537 353702 281350 170770 990108 899247 262148 80885 764300 843368 388019 860254 908775 857238 748037 663137 845647 962026 658114 367339 370683 438805 898351 410474 988151 264421 617772 912252 777975 286130 730164 207569 489357 566062 318563 911925 614794 823240 240264 795871 610017 438594 286046 507424 646130 915974 801916 476693 566861 458230 720760 118831 322814 427671 75822 31766 619341 650295 968571 958175 319414 566641 400510 831100 836036 156953 836819 504017 653726 462299 932356 549522 228404 714490 46002 318300 25859 891062 65051 508087 302554 678876 139690];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'I was so much in awe that I cannot even begin to tell you what he had proposed.';\r\ncodes = sqrt2encode(plainText,2966);\r\ncodes_correct = [673747 849127 73957 431196 124842 352837 178989 363325 731793 721822 802273 974866 368597 866430 980967 374867 211894 415558 908289 437240 100937 507589 256690 124827 418110 242057 483028 801611 724175 645423 889529 504807 942396 327626 549545 737120 280989 925005 732565 326020 830997 692694 44945 225380 307158 972971 711928 279749 386496 207819 478399 698097 221631 266599 460931 1496 964830 554626 759323 790781 225831 652862 381997 136239 440368 826334 343564 51423 15373 688437 602485 791811 319086 667741 768000 269710 778061 448307 224254];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'A few years ago, I asked him about it.';\r\ncodes = sqrt2encode(plainText,39157);\r\ncodes_correct = [7335 705290 726207 886801 182970 560908 788959 898669 78343 182645 86427 815650 665141 473070 406650 314404 474659 249077 81192 114577 333151 379662 772413 143922 611500 860103 169423 690118 293806 499539 765845 639358 611945 683301 156208 818101 532736 768969];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nq = char(39);\r\nplainText = ['He said he didn' q 't remember, but I like to think he was just following the magician' q 's code and not revealing his secret.'];\r\ncodes = sqrt2encode(plainText,40480);\r\ncodes_correct = [696094 365378 387685 289416 990143 500095 815792 311774 605024 665926 38337 365365 475123 842714 213855 845901 867100 450588 587864 781538 145190 172416 192039 175201 816036 14877 878723 549677 196221 617198 676083 833176 866842 267531 494003 640571 868863 688173 845419 527467 334239 790242 376046 809236 760376 134802 164114 145095 367732 558312 363570 599200 320695 182259 498690 383785 170657 870794 204883 421908 375824 574047 521922 537241 26417 884024 355886 550480 237981 644955 793982 125845 59977 357148 832507 645551 715383 344227 716126 656523 587209 273640 269262 277645 65454 958569 722194 113338 898688 541108 307559 820632 920897 408744 499580 132094 558243 998120 662048 849737 343791 453541 27839 133782 361543 941892 708219 893529 379928 932308 593347 154395 859124 391880 206229 680175 40793 737085 732779];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nfiletext = fileread('sqrt2encode.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'assert'); \r\nassert(~illegal)","published":true,"deleted":false,"likes_count":0,"comments_count":4,"created_by":46909,"edited_by":46909,"edited_at":"2023-05-18T20:42:57.000Z","deleted_by":null,"deleted_at":null,"solvers_count":3,"test_suite_updated_at":"2023-05-18T20:42:57.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2023-05-17T04:11:21.000Z","updated_at":"2023-05-18T20:42:57.000Z","published_at":"2023-05-17T04:15:10.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose you want to encrypt the word ‘TWIN’. The ASCII codes for the four letters are 84, 87, 73, and 78. If you consider the fractional part of the square root of 2 as a string \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4142135623\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e73\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e09504880168\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e87\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e242096980\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e78\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e56967187537694807317667973799073247\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e84\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen those ASCII codes are found at positions 72, 24, 11, and 35. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThose ASCII codes can be found in other positions in the fractional part of the square of 2. So to add a layer of complexity to the code, choose one of those positions randomly.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to encrypt a message in this way. Make sure to convert the string to all uppercase before encrypting. A string with the fractional part of the square root of 2 will be set as a global variable, and a seed will be passed to the function to be used in the command \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\u003erng(seed)\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\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":2606,"title":"Decrypt the  cypher using XOR encryption (for beginners)","description":"Inspired by Project Euler n°59\r\n\r\nEach character on a computer is assigned a unique code and the preferred standard is ASCII \r\n(American Standard Code for Information Interchange). For example, uppercase A = 65, asterisk (*) = 42, \r\nand lowercase k = 107.\r\nA basic encryption method is to take a text file or a sentence, convert the bytes to ASCII, then XOR each byte with a given \r\nvalue, taken from a secret key. The advantage with the XOR function is that using the same encryption key on the \r\ncipher text, restores the plain text; for example, 65 XOR 42 = 107, then 107 XOR 42 = 65.\r\n    \r\nYour task has been made easy, as the encryption key consists only of a upper case character (different in every tests). \r\nYou must know that the original text contains common FRENCH words about MATLAB.\r\n\r\nDecrypt the message and find the sum of the ASCII values in the original text.","description_html":"\u003cp\u003eInspired by Project Euler n°59\u003c/p\u003e\u003cp\u003eEach character on a computer is assigned a unique code and the preferred standard is ASCII \r\n(American Standard Code for Information Interchange). For example, uppercase A = 65, asterisk (*) = 42, \r\nand lowercase k = 107.\r\nA basic encryption method is to take a text file or a sentence, convert the bytes to ASCII, then XOR each byte with a given \r\nvalue, taken from a secret key. The advantage with the XOR function is that using the same encryption key on the \r\ncipher text, restores the plain text; for example, 65 XOR 42 = 107, then 107 XOR 42 = 65.\u003c/p\u003e\u003cp\u003eYour task has been made easy, as the encryption key consists only of a upper case character (different in every tests). \r\nYou must know that the original text contains common FRENCH words about MATLAB.\u003c/p\u003e\u003cp\u003eDecrypt the message and find the sum of the ASCII values in the original text.\u003c/p\u003e","function_template":"function y = XOR_cypher(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx=[15 3 22 14 3 0 236 98 39 49 54 98 55 44 98 46 35 44 37 35 37 39 98 38 39 98 42 35 55 54 98 44 43 52 39 35 55];\r\ny_correct=3360;\r\nassert(isequal(XOR_cypher(x),y_correct))\r\n%%\r\nx=[29 40 184 57 63 122 186 122 23 27 14 22 27 24 118 122 44 53 47 41 122 42 53 47 44 63 32 122 59 52 59 54 35 41 63 40 122 62 63 41 122 62 53 52 52 179 63 41 116];\r\ny_correct=4783;\r\nassert(isequal(XOR_cypher(x),y_correct))\r\n%%\r\nx=[28 33 41 53 54 43 60 35 117 121 47 48 42 44 56 53 48 42 60 35 121 60 45 121 52 54 61 176 53 48 42 60 35 121 47 54 42 121 61 54 55 55 176 60 42 121 56 47 60 58 121 20 24 13 21 24 27 119];\r\ny_correct=5667;\r\nassert(isequal(XOR_cypher(x),y_correct))\r\n%%\r\nx=[11 39 50 42 39 36 124 102 42 35 102 42 39 40 33 39 33 35 102 34 51 102 37 39 42 37 51 42 102 53 37 47 35 40 50 47 55 51 35];\r\ny_correct=3666;\r\nassert(isequal(XOR_cypher(x),y_correct))\r\n%%\r\nx=[27 36 62 57 58 62 36 34 107 40 35 36 56 34 57 107 6 42 63 39 42 41 107 46 63 107 59 42 56 107 27 50 63 35 36 37 107 116];\r\ny_correct=3547;\r\nassert(isequal(XOR_cypher(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":5390,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":66,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":32,"created_at":"2014-09-27T10:32:11.000Z","updated_at":"2026-03-19T21:22:18.000Z","published_at":"2014-09-27T10:33:19.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eInspired by Project Euler n°59\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEach character on a computer is assigned a unique code and the preferred standard is ASCII (American Standard Code for Information Interchange). For example, uppercase A = 65, asterisk (*) = 42, and lowercase k = 107. A basic encryption method is to take a text file or a sentence, convert the bytes to ASCII, then XOR each byte with a given value, taken from a secret key. The advantage with the XOR function is that using the same encryption key on the cipher text, restores the plain text; for example, 65 XOR 42 = 107, then 107 XOR 42 = 65.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour task has been made easy, as the encryption key consists only of a upper case character (different in every tests). You must know that the original text contains common FRENCH words about MATLAB.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDecrypt the message and find the sum of the ASCII values in the original text.\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":1467,"title":"Key Generation for Solitaire Cipher","description":"The Solitaire Cipher by Bruce Schneier was introduced to Cody in two problems by Doug Hull:  http://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cipher and http://www.mathworks.com/matlabcentral/cody/problems/766-implement-solitaire-cipher-for-n-long-deck.\r\n\r\nHowever, these problems do not address the initial configuration of the deck.  One simple approach uses a key phrase, as described here:  http://programmingpraxis.com/2011/01/18/solitaire-cipher/\r\n\r\nYour job is to implement this key generator.  Begin with the cards in numeric order (1:28) and process the deck once.  (To \"process\" the deck you should carry out all the steps necessary to produce one character in the keystream with the regular Solitaire cipher, but you don't emit any output.)  Now for each character k in the key, cut the deck by moving k cards from the front to the back of the deck.  After each cut, process the deck once again.  Assume that any non-alphabetic characters in the keyphrase generate a null cut (move zero characters from front to back).\r\n\r\nAt the end, you should return the state of the deck.","description_html":"\u003cp\u003eThe Solitaire Cipher by Bruce Schneier was introduced to Cody in two problems by Doug Hull:  \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cipher\"\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cipher\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/766-implement-solitaire-cipher-for-n-long-deck\"\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/766-implement-solitaire-cipher-for-n-long-deck\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eHowever, these problems do not address the initial configuration of the deck.  One simple approach uses a key phrase, as described here:  \u003ca href = \"http://programmingpraxis.com/2011/01/18/solitaire-cipher/\"\u003ehttp://programmingpraxis.com/2011/01/18/solitaire-cipher/\u003c/a\u003e\u003c/p\u003e\u003cp\u003eYour job is to implement this key generator.  Begin with the cards in numeric order (1:28) and process the deck once.  (To \"process\" the deck you should carry out all the steps necessary to produce one character in the keystream with the regular Solitaire cipher, but you don't emit any output.)  Now for each character k in the key, cut the deck by moving k cards from the front to the back of the deck.  After each cut, process the deck once again.  Assume that any non-alphabetic characters in the keyphrase generate a null cut (move zero characters from front to back).\u003c/p\u003e\u003cp\u003eAt the end, you should return the state of the deck.\u003c/p\u003e","function_template":"function deck = solitaireKey(keyphrase)\r\n  deck = 1:28;\r\nend","test_suite":"%%\r\nx = '';\r\ny_correct = [2:28,1];\r\nassert(isequal(solitaireKey(x),y_correct))\r\n\r\n%%\r\nx = 'SECRET KEY';\r\ny_correct = [26 25 7 8 2 13 6 16 27 4 5 19 23 21 14 15 9 3 20 11 12 28 17 18 10 1 24 22];\r\nassert(isequal(solitaireKey(x),y_correct))\r\n\r\n%%\r\nx = 'I don''t know the key to success, but the key to failure is trying to please everybody.';\r\ny_correct = [16 10 28 4 26 25 8 27 19 24 7 1 9 21 22 23 17 11 14 15 12 13 20 5 2 3 18 6];\r\nassert(isequal(solitaireKey(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":3117,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":6,"test_suite_updated_at":"2013-04-28T15:50:44.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-04-28T15:36:00.000Z","updated_at":"2013-04-28T15:50:44.000Z","published_at":"2013-04-28T15:50:44.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\u003eThe Solitaire Cipher by Bruce Schneier was introduced to Cody in two problems by Doug Hull: \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://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/766-implement-solitaire-cipher-for-n-long-deck\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/766-implement-solitaire-cipher-for-n-long-deck\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\u003eHowever, these problems do not address the initial configuration of the deck. One simple approach uses a key phrase, as described here: \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://programmingpraxis.com/2011/01/18/solitaire-cipher/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://programmingpraxis.com/2011/01/18/solitaire-cipher/\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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 job is to implement this key generator. Begin with the cards in numeric order (1:28) and process the deck once. (To \\\"process\\\" the deck you should carry out all the steps necessary to produce one character in the keystream with the regular Solitaire cipher, but you don't emit any output.) Now for each character k in the key, cut the deck by moving k cards from the front to the back of the deck. After each cut, process the deck once again. Assume that any non-alphabetic characters in the keyphrase generate a null cut (move zero characters from front to back).\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\u003eAt the end, you should return the state of the deck.\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":766,"title":"Implement Solitaire cipher for N long deck.","description":"Implement the \u003chttp://en.wikipedia.org/wiki/Solitaire_(cipher) solitaire cypher\u003e.\r\n\r\nGiven a starting permutation of numbers [1:N], deck, generate M values for the keystream.   The small joker will be value N-1, the big joker will be N.\r\n\r\nThis is an update of this \u003chttp://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cypher problem\u003e.","description_html":"\u003cp\u003eImplement the \u003ca href=\"http://en.wikipedia.org/wiki/Solitaire_(cipher)\"\u003esolitaire cypher\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a starting permutation of numbers [1:N], deck, generate M values for the keystream.   The small joker will be value N-1, the big joker will be N.\u003c/p\u003e\u003cp\u003eThis is an update of this \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cypher\"\u003eproblem\u003c/a\u003e.\u003c/p\u003e","function_template":"function out = solitaire(deck, n)\r\n  out = n;\r\nend","test_suite":"deck = [1 4 7 10 13 16 19 22 25 28 3 6 9 12 15 18 21 24 27 2 5 8 11 14 17 20 23 26];\r\nm    = 10;\r\nout = [8    26     1     4     7    23     8     8     4    24];\r\nassert(isequal(solitaire(deck, m),out))\r\n\r\n%%\r\ndeck = 1:28;\r\nm    = 10;\r\nout = [3    22     9     4    23     7    25    16    14    14];\r\nassert(isequal(solitaire(deck, m),out))\r\n\r\n%%\r\ndeck = 1:28;\r\nm    = 10;\r\nout = [3    22     9     4    23     7    25    16    14    14];\r\nassert(isequal(solitaire(deck, m),out))\r\n\r\n%%\r\ndeck = 1:5;\r\nm    = 10;\r\nout = [3     4     1     1     5     5     4     2     4     1];\r\nassert(isequal(solitaire(deck, m),out))     ","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-06-14T17:57:56.000Z","updated_at":"2026-03-11T09:49:47.000Z","published_at":"2012-06-14T17:59:07.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\u003eImplement 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/Solitaire_(cipher)\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esolitaire cypher\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\u003eGiven a starting permutation of numbers [1:N], deck, generate M values for the keystream. The small joker will be value N-1, the big joker will be N.\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\u003eThis is an update of this\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://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cypher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eproblem\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":1499,"title":"Kryptos - CIA Cypher Sculpture: Vigenere Encryption","description":"The \u003chttp://en.wikipedia.org/wiki/Kryptos Kryptos Sculpture\u003e contains four encypted messages.\r\n\r\nThis Challenge is to Encrypt two of the original messages for the sculptor.\r\n\r\nThe method employed is \u003chttp://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher Vigenere Encryption\u003e. One clarification is that \"?\" are removed from the coding sequence and then re-inserted in the final encoded message.\r\n\r\nOriginal phrase: Between subtle shading and the absence of light lies the nuance of iqlusion.\r\n\r\nFor coding purposes spaces and punctuation are removed, except \"?\".\r\n\r\nPhrase to encode: BETWEENSUBTLESHADINGANDTHEABSENCEOFLIGHTLIESTHENUANCEOFIQLUSION\r\n\r\n*Input:* Encode Phrase, Vigenere alphabet word, Vigenere shift word\r\n\r\nVigenere alphabet word ='KRYPTOS';\r\n\r\nVigenere shift word ='PALIMPSEST';\r\n\r\n*Output:* EMUFPHZLRFAXYUSDJKZLDKRNSHGNFIVJYQTQUXQBQVYUVLLTREVJYQTMKYRDMFD\r\n\r\nThe encryption matrix for this case:\r\n\r\n  KRYPTOSABCDEFGHIJLMNQUVWXZ\r\n\r\n  PTOSABCDEFGHIJLMNQUVWXZKRY\r\n  ABCDEFGHIJLMNQUVWXZKRYPTOS\r\n  LMNQUVWXZKRYPTOSABCDEFGHIJ\r\n  IJLMNQUVWXZKRYPTOSABCDEFGH\r\n  MNQUVWXZKRYPTOSABCDEFGHIJL\r\n  PTOSABCDEFGHIJLMNQUVWXZKRY\r\n  SABCDEFGHIJLMNQUVWXZKRYPTO\r\n  EFGHIJLMNQUVWXZKRYPTOSABCD\r\n  SABCDEFGHIJLMNQUVWXZKRYPTO\r\n  TOSABCDEFGHIJLMNQUVWXZKRYP\r\n\r\nFollow Up Challenges:\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1500-kryptos-cia-cypher-sculpture-vignere-decryption Vigenere Decryption\u003e\r\n\r\n2) Dictionary search\r\n\r\n3) KRYPTOS Part IV\r\n\r\n\u003chttp://math.ucsd.edu/~crypto/Projects/KarlWang/index2.html#1 KRYPTOS Solutions\u003e\r\n\r\n  \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n","description_html":"\u003cp\u003eThe \u003ca href = \"http://en.wikipedia.org/wiki/Kryptos\"\u003eKryptos Sculpture\u003c/a\u003e contains four encypted messages.\u003c/p\u003e\u003cp\u003eThis Challenge is to Encrypt two of the original messages for the sculptor.\u003c/p\u003e\u003cp\u003eThe method employed is \u003ca href = \"http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher\"\u003eVigenere Encryption\u003c/a\u003e. One clarification is that \"?\" are removed from the coding sequence and then re-inserted in the final encoded message.\u003c/p\u003e\u003cp\u003eOriginal phrase: Between subtle shading and the absence of light lies the nuance of iqlusion.\u003c/p\u003e\u003cp\u003eFor coding purposes spaces and punctuation are removed, except \"?\".\u003c/p\u003e\u003cp\u003ePhrase to encode: BETWEENSUBTLESHADINGANDTHEABSENCEOFLIGHTLIESTHENUANCEOFIQLUSION\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e Encode Phrase, Vigenere alphabet word, Vigenere shift word\u003c/p\u003e\u003cp\u003eVigenere alphabet word ='KRYPTOS';\u003c/p\u003e\u003cp\u003eVigenere shift word ='PALIMPSEST';\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e EMUFPHZLRFAXYUSDJKZLDKRNSHGNFIVJYQTQUXQBQVYUVLLTREVJYQTMKYRDMFD\u003c/p\u003e\u003cp\u003eThe encryption matrix for this case:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eKRYPTOSABCDEFGHIJLMNQUVWXZ\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ePTOSABCDEFGHIJLMNQUVWXZKRY\r\nABCDEFGHIJLMNQUVWXZKRYPTOS\r\nLMNQUVWXZKRYPTOSABCDEFGHIJ\r\nIJLMNQUVWXZKRYPTOSABCDEFGH\r\nMNQUVWXZKRYPTOSABCDEFGHIJL\r\nPTOSABCDEFGHIJLMNQUVWXZKRY\r\nSABCDEFGHIJLMNQUVWXZKRYPTO\r\nEFGHIJLMNQUVWXZKRYPTOSABCD\r\nSABCDEFGHIJLMNQUVWXZKRYPTO\r\nTOSABCDEFGHIJLMNQUVWXZKRYP\r\n\u003c/pre\u003e\u003cp\u003eFollow Up Challenges:\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1500-kryptos-cia-cypher-sculpture-vignere-decryption\"\u003eVigenere Decryption\u003c/a\u003e\u003c/p\u003e\u003cp\u003e2) Dictionary search\u003c/p\u003e\u003cp\u003e3) KRYPTOS Part IV\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://math.ucsd.edu/~crypto/Projects/KarlWang/index2.html#1\"\u003eKRYPTOS Solutions\u003c/a\u003e\u003c/p\u003e","function_template":"function encoded=encode_vigenere(phrase,word1,word2)\r\n encoded=phrase;\r\nend","test_suite":"phrase=upper('Between subtle shading and the absence of light lies the nuance of iqlusion.');\r\nphrase_encode=phrase(regexp(phrase,'[A-Z?]'));\r\n\r\nencoded_exp='EMUFPHZLRFAXYUSDJKZLDKRNSHGNFIVJYQTQUXQBQVYUVLLTREVJYQTMKYRDMFD';\r\nword1='KRYPTOS';\r\nword2='PALIMPSEST';\r\nencoded= encode_vigenere(phrase_encode,word1,word2);\r\n\r\nassert(strcmp(encoded_exp,encoded))\r\n%%\r\n\r\nphrase=upper('It was totally invisible Hows that possible? They used the Earths magnetic field X The information was gathered and transmitted undergruund to an unknown location X Does Langley know about this? They should Its buried out there somewhere X Who knows the exact location? Only WW This was his last message X Thirty eight degrees fifty seven minutes six point five seconds north Seventy seven degrees eight minutes forty four seconds west ID by rows');\r\nphrase_encode=phrase(regexp(phrase,'[A-Z?]'));\r\n\r\n\r\nencoded_exp='VFPJUDEEHZWETZYVGWHKKQETGFQJNCEGGWHKK?DQMCPFQZDQMMIAGPFXHQRLGTIMVMZJANQLVKQEDAGDVFRPJUNGEUNAQZGZLECGYUXUEENJTBJLBQCRTBJDFHRRYIZETKZEMVDUFKSJHKFWHKUWQLSZFTIHHDDDUVH?DWKBFUFPWNTDFIYCUQZEREEVLDKFEZMOQQJLTTUGSYQPFEUNLAVIDXFLGGTEZ?FKZBSFDQVGOGIPUFXHHDRKFFHQNTGPUAECNUVPDJMQCLQUMUNEDFQELZZVRRGKFFVOEEXBDMVPNFQXEZLGREDNQFMPNZGLFLPMRJQYALMGNUVPDXVKPDQUMEBEDMHDAFMJGZNUPLGEWJLLAETG';\r\n\r\nword1='KRYPTOS';\r\nword2='ABSCISSA';\r\nencoded= encode_vigenere(phrase_encode,word1,word2);\r\n\r\nassert(strcmp(encoded_exp,encoded))\r\n%%\r\nphrase=upper('The fox jumped over the moon');\r\nphrase_encode=phrase(regexp(phrase,'[A-Z?]'));\r\n\r\nencoded_exp='VUIPFSBYVQMMWPIMEVPZCVK';\r\nword1='KRYPTOS';\r\nword2='MATLAB';\r\nencoded= encode_vigenere(phrase_encode,word1,word2);\r\n\r\nassert(strcmp(encoded_exp,encoded))\r\n\r\n%%\r\nphrase=upper('Between the Devil and the deep blue sea');\r\nphrase_encode=phrase(regexp(phrase,'[A-Z?]'));\r\n\r\n\r\nword1='AWEIGH';\r\nword2='MATLAB';\r\nencoded= encode_vigenere(phrase_encode,word1,word2);\r\nencoded_exp='SENMEDWTZNDDFIBLNNCHVTEDIBBCEZOA';\r\n\r\nassert(strcmp(encoded_exp,encoded))\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":3,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":61,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":28,"created_at":"2013-05-11T20:36:34.000Z","updated_at":"2026-03-07T04:46:20.000Z","published_at":"2013-05-11T21:19:07.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\u003eThe\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/Kryptos\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eKryptos Sculpture\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e contains four encypted messages.\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\u003eThis Challenge is to Encrypt two of the original messages for the sculptor.\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 method employed is\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/Vigen%C3%A8re_cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eVigenere Encryption\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. One clarification is that \\\"?\\\" are removed from the coding sequence and then re-inserted in the final encoded 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\u003eOriginal phrase: Between subtle shading and the absence of light lies the nuance of iqlusion.\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\u003eFor coding purposes spaces and punctuation are removed, except \\\"?\\\".\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\u003ePhrase to encode: BETWEENSUBTLESHADINGANDTHEABSENCEOFLIGHTLIESTHENUANCEOFIQLUSION\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\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Encode Phrase, Vigenere alphabet word, Vigenere shift word\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\u003eVigenere alphabet word ='KRYPTOS';\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\u003eVigenere shift word ='PALIMPSEST';\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\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e EMUFPHZLRFAXYUSDJKZLDKRNSHGNFIVJYQTQUXQBQVYUVLLTREVJYQTMKYRDMFD\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 encryption matrix for this case:\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[KRYPTOSABCDEFGHIJLMNQUVWXZ\\n\\nPTOSABCDEFGHIJLMNQUVWXZKRY\\nABCDEFGHIJLMNQUVWXZKRYPTOS\\nLMNQUVWXZKRYPTOSABCDEFGHIJ\\nIJLMNQUVWXZKRYPTOSABCDEFGH\\nMNQUVWXZKRYPTOSABCDEFGHIJL\\nPTOSABCDEFGHIJLMNQUVWXZKRY\\nSABCDEFGHIJLMNQUVWXZKRYPTO\\nEFGHIJLMNQUVWXZKRYPTOSABCD\\nSABCDEFGHIJLMNQUVWXZKRYPTO\\nTOSABCDEFGHIJLMNQUVWXZKRYP]]\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\u003eFollow Up Challenges:\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\u003e1)\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://www.mathworks.com/matlabcentral/cody/problems/1500-kryptos-cia-cypher-sculpture-vignere-decryption\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eVigenere Decryption\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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\u003e2) Dictionary search\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\u003e3) KRYPTOS Part IV\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:hyperlink w:docLocation=\\\"http://math.ucsd.edu/~crypto/Projects/KarlWang/index2.html#1\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eKRYPTOS Solutions\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":58309,"title":"Decode a message encrypted with the square root of 2","description":"Cody Problem 58299 asks you to encrypt a message by changing all letters to uppercase and randomly choosing a position of the ASCII codes of the message’s characters in the fractional part of the square root of 2. \r\nWrite a function to decrypt a message encrypted in this way. A string with the fractional part of the square root of 2 will be set as a global variable. ","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 93px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 46.5px; transform-origin: 407px 46.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/58299\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eCody Problem 58299\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 318.25px 7.79167px; transform-origin: 318.25px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e asks you to encrypt a message by changing all letters to uppercase and randomly choosing a position of the ASCII codes of the message’s characters in the fractional part of the square root of 2. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 375.85px 7.79167px; transform-origin: 375.85px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to decrypt a message encrypted in this way. A string with the fractional part of the square root of 2 will be set as a global variable. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function plainText = sqrt2decode(codes)\r\n    global sqrt2str    \r\n    plainText = lower(char(codes));","test_suite":"%%\r\nglobal sqrt2str    \r\ns = webread('https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil');\r\nsqrt2str = s(1230:1013886);\r\nsqrt2str(strfind(sqrt2str,newline))='';\r\n\r\n%%\r\nq = char(39);\r\ncodes = [788502 255791 27020 945829 39750 862438 213469 205939 293186 194403 50849 837227 23680 777170 698302 887866 619631 541941 982637 960122 234631 405512 547855 7950 961111 91948 538721 21556 485674 552780 551227 320494 925276 196927 834812 175040 135063 344979 792360 400370 469032 540401];\r\npt_correct = upper(['The second story is about Dad' q 's curiosity.']);\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\nq = char(39);\r\ncodes = [591914 840747 541787 614044 807979 224189 355892 423494 682550 521338 981361 189419 808050 911915 944373 993776 744132 141150 759296 470235 962630 749010 460347 84966 790276 787817 319305 979496 233714 186900 42661 940998 439124 635374 714432 874739 344720 559441 147867 943984 363638 287105 261004 143310 60790 716550 170461 818242 211318 553585 727730 710292 129282 257363 748485 549687 839045 126476 547047 182108 682959 508052 808232 885200 363418 329536 57967 642295 589575 616984 402549 260202 979043 216849 529738 84559 565832 313592 320640 340234 592569 217347 316676 832012 5983 699060 75169 679439 340234 12261 750307 876342 23148 697438 743464 931178 659875 688560 685356 543369 919439 878282 239111 639197 671002 497435 497412 39393 783994 834103 996336 414857 577983 704120 984777 936848 364327 621288 77986 941878 320709];\r\npt_correct = upper(['In 2005 Mom and Dad celebrated their 40th anniversary by taking my family and Rich' q 's family to Yellowstone National Park.']);\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [130393 353677 738370 903643 3564 581437 23834 833430 262988 712081 16900 912092 802225 602317 934440 465768 185278 613819 927070 996389 565011 941667 82469 674306 739868 990449 880811 547348 362880 346445 451459 581009 880364 273794 840619 443295 299931 237038 453095 243319 785884 388159 133746 88672 649683 182750 109587 952810];\r\npt_correct = upper('Emily, Jessica, and Erin were 7, and Jack was 5.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [754611 950965 10682 389736 791866 342532 102974 144421 252303 73534 335719 286872 799001 911457 558320 735276 445852 162269 341612 724458 659261 408095 808407 141183 191383 41810 235799 416988 324369 791369 567235 328209 121501 601989 601543 408744 167084 3717 824309 907688 878173 770788 395269 674521 653516 737417 136250 693004 18695 42938 83298 893791 232968 359547 716373 154081 944005 147781 278690 762395 641626 127746 81379 71050 877584 975323 566081 195409 894256 626719 559483 571802 577642 16613 739008 451833 899673 629239 918889 141859 413590 347966 363156 592562 231361 551641 20802 536555 990082 560638 790578 694214 980663 34729 784078 735631 468633 421305 80487 674917 320121 911694 240267 937464 470537 351783 151386 498420 852973 266751 64522 700849 559501 180540 748748 421710 23821 773760 521658 872461 46507 170227 380893 630380 470998];\r\npt_correct = upper('We rented a house just north of the park, and each day we would drive into the park, hike, look around, and have a good time.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\nreturn\r\n%%\r\ncodes = [795554 916296 609526 964161 695721 316971 184761 995970 266520 372060 961810 141668 545585 961948 77562 101395 313351 626929 592332 915942 564670 74989 740347 230199 979137 250117 850171 392964 21946 601540 929567 372822 49420 326527 406967 946046 469754 901551 536890 276080 770713 892243 518762 106576 356027 349536 88013 889364 820052 92222 178525 764598 427260 5428 931322 493289 458443 397376 227644 344694 43454 422565 436175 675426 481710 363855 839576 809669 6096 862646 868151 80582 469790 785432 185031 479943 517627 736502 647035 333836 687834 756796 338464 685802 771298 364368 795086 849955 539110 533454 152212 3302 362512 564341];\r\npt_correct = upper('One day we did a longer hike in the afternoon, and we got back to the trailhead at about 3:30.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [433619 361932 263909 633917 906791 754700 980868 343228 222731 890095 524316 563776 397399 132600 680546 668607 438140 321071 805906 496701 693041 768408 20571 272011 399281 285213 716350 96621 987090 494180 152677 259740 690358 101937 535101 843614 433418 20389 504142 488418 833388 329794 371125 844722 587487 188995 148130 696600 461262 242053 815556 214532 140403 419590 908775 203875 426488 832429 474735 395921 161487 388018 104229 912866 285076 366249 624917 984821 24650 88627 633980 500662 441589 398552 177690 284750 203599 832775 221514 258473 976865 619947 184664 94396 641391 955689 607555 187076 45741 994279 107342 933440 682434 889317 477797 320616 771084 683748 123450 832795 900659 746748 624682 848007 106925 278622 498171 407820 838018 655752 881940 755789 307415 59113 88563 671463 343076 356192 784691 873480 830588 302810 614106 610568 552571 67563 131474 491463 731918 649492 686731 445936 644832 341843 103686 284086 809024 199624 351857 285876 454377 385273 104534 988018 741067 874701 39888 283400 748867 714383 373782 889059];\r\npt_correct = upper('The kids were still in a good mood, and Rachel and I conferred with Rich and Linda and decided that we should cash in and go back to the house to relax.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [167556 474211 663454 115461 486354 938339 631867 813176 737577 690044 119052 152807 444464 842736 537866 373682 837581 749562 948090 600925 460722 570223 209018 328233 373068 940568 163357 821183 704097 822151 503235 860532 392050 902720 487776 967001 895851 886875 682959 184272 467861 783155 314860 489562 308207 246282 147724 255693 805133 418620 787837 157401 510425 214735 4011 687662 931736 151640 178440 592599 255168 38953 659890 410039 578110 442952 56418 126147 709926 566995 583694 119225 97183 367892 313731 912247 339835 88125 264356 208256 900925 229755 633349 382384 821443 540083 138049 630212 600814 751628 656641 937464 423947 103959 214030 808489 551110 449657 960942 620402 246227 884689 238183 817614 238863 970646 386227 206878 644865 650439 667567];\r\npt_correct = upper('We put this proposal to Dad, and he said, \"Go back? Go back? No, no, no. It s only 3:30. We have lots of time.\"');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [847195 489238 932356 941838 570042 125554 333302 26477 864818 972834 78484 116618 694757 37480 334824 543926 751331 677139 425174 49214 994351 301356 527563 900706 597544 757695 174204 788243 534161 313938 261897 400076 309885 940984 400579 937596 719137 88663 78401 259841 407299 476462 814525 960001 510963 843120 298987 743365 369317 880318 841610 616494 711255 183995 308204 811330 705417 23948 874346 248132 219931 270392 881875 16098 346395 130953 172094 735017 371737 27894 529528 827883 392187 965876 366814 195346 677687 100 938958 599570 211501 590803 598238 92682 538000 70897 998293 440121 693754 784471 982010 112719 951702 672967 863564 317677 670237 653064 677098];\r\npt_correct = upper('Then he grabbed the Yellowstone map, spread it on the hood of the car, and pointed almost randomly.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\nq = char(39);\r\ncodes = [659320 227631 274954 718019 651014 371165 90419 547936 317455 946494 988215 169233 342180 130386 204141 822640 161285 426905 417984 207163 589783 420227 603900 676725 843999];\r\npt_correct = upper(['He said, \"Let' q 's go here.\"']);\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [697309 498072 139847 616036 460434 91452 460049 801786 612552 663239 372588 26278 183603 883838 358687 160398 932996 396412 686984 337273 713022 633761 769926 215964 689835 462089 943462 753637 535076 115291 994724 3419 555297 719602 471788 145791 723544 428585 466474 918338 954330 115873 790601 260309 157927 468630 461749 451143 352455 722311 453168 765065 285284 615985 639710 391035 45275 852754 705774 653389 844419 250764 587009 169123 295209 172519 103647 953318 78379 984660 409662 973003 431205 181530 903980 222751 803846 372510 958505 674419 578821 438449 652375 364347];\r\npt_correct = upper('So we drove to Sheepeater Cliff, a strange collection of hexagonal basaltic columns.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [248382 28142 308843 198878 522209 501100 114082 524301 41728 591654 734162 358080 267045 786562 134945 980838 776756 258108 844560 500391 85520 244430 759558 892488 337528 342260 668309 660014 162477 914632 365677 70299 412709 627387 974605 61589 62723 955839 292791 488375 695447 605042 388139 744611 468706 980514 249861 32825 160953 581148 410573 665712 167314 644379 269246 764369 480738 613239 14331 712262 280652 565540 769487 497534 723639 508704 499408 350746 73072 672769 994335 315268 496012 974183 1498 548405 297216 315786 66804 620984 306854 405545 353531 886945 419244 824728 324108 673613 421052 744385];\r\npt_correct = upper('We scrambled around the cliff until Dad was satisfied, and then we went back to the house.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\ncodes = [946597 293692 607859 938608 195470 794966 175585 426655 901655 457473 741935 803059 844573 292673 98914 66996 398586 876946 701685 247360 141821 611297 119627 439960 415389 304087 858406 220637 900247 798981 636234 352816 378028 190737 12127 415458 471321 225243 848144 601432 765394 220923 632078 155806 156567 780760 559788 186935 327665 259956 826206 155281 936557 565784 280768 871309 84802 111886 965175 957035 931461 218547 699475 928012 773524 84155 48488 834409 370702 713812 459131 946955 499022 269242 148694 250841 835205 932715 413817 972046 572769 557057 725054 378723 717701 431270 839971 781573 960753 111628 546546 623231 182341 727399 43130 339778 344390 76380 555200 389839 281228 322099 942878 493340 637660 317037 28165 976843 415111 128764 467283 859972 453882 548187 246210 867571 104467 591830 582522 979085 359934 579883 167577 985704 786720 416834 300316 975464 390035 69573 659541 804039 639358 15738 17376 151971 233066 232014 462511 676976 877410 783161 963955 925501 695980 615636 519207 136935 354380];\r\npt_correct = upper('While the rest of us got cleaned up, Dad grabbed his camera and field guide of wildflowers and explored the hill by the house for another hour or so.');\r\nassert(isequal(sqrt2decode(codes),pt_correct))\r\n\r\n%%\r\nfiletext = fileread('sqrt2decode.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'assert'); \r\nassert(~illegal)\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":46909,"edited_by":46909,"edited_at":"2023-05-18T20:47:43.000Z","deleted_by":null,"deleted_at":null,"solvers_count":3,"test_suite_updated_at":"2023-05-18T20:47:43.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2023-05-17T12:34:14.000Z","updated_at":"2023-05-18T20:47:43.000Z","published_at":"2023-05-17T12:35:40.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/58299\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody Problem 58299\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e asks you to encrypt a message by changing all letters to uppercase and randomly choosing a position of the ASCII codes of the message’s characters in the fractional part of the square root of 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to decrypt a message encrypted in this way. A string with the fractional part of the square root of 2 will be set as a global variable. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":58299,"title":"Encrypt a message with the square root of 2","description":"Suppose you want to encrypt the word ‘TWIN’. The ASCII codes for the four letters are 84, 87, 73, and 78. If you consider the fractional part of the square root of 2 as a string \r\n4142135623730950488016887242096980785696718753769480731766797379907324784…\r\nthen those ASCII codes are found at positions 72, 24, 11, and 35. \r\nThose ASCII codes can be found in other positions in the fractional part of the square of 2. So to add a layer of complexity to the code, choose one of those positions randomly.\r\nWrite a function to encrypt a message in this way. Make sure to convert the string to all uppercase before encrypting. A string with the fractional part of the square root of 2 will be set as a global variable, and a seed will be passed to the function to be used in the command rng(seed).","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 225.45px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 112.725px; transform-origin: 407px 112.725px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 377.25px 7.79167px; transform-origin: 377.25px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSuppose you want to encrypt the word ‘TWIN’. The ASCII codes for the four letters are 84, 87, 73, and 78. If you consider the fractional part of the square root of 2 as a string \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 38.9167px 7.79167px; transform-origin: 38.9167px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e4142135623\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 7.78333px 7.79167px; transform-origin: 7.78333px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; text-decoration-line: underline; \"\u003e73\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 42.8083px 7.79167px; transform-origin: 42.8083px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e09504880168\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 7.78333px 7.79167px; transform-origin: 7.78333px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; text-decoration-line: underline; \"\u003e87\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 35.025px 7.79167px; transform-origin: 35.025px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e242096980\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 7.78333px 7.79167px; transform-origin: 7.78333px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; text-decoration-line: underline; \"\u003e78\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 136.208px 7.79167px; transform-origin: 136.208px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e56967187537694807317667973799073247\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 7.78333px 7.79167px; transform-origin: 7.78333px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; text-decoration-line: underline; \"\u003e84\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 7px 7.79167px; transform-origin: 7px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e…\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 204.067px 7.79167px; transform-origin: 204.067px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ethen those ASCII codes are found at positions 72, 24, 11, and 35. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 378.833px 7.79167px; transform-origin: 378.833px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThose ASCII codes can be found in other positions in the fractional part of the square of 2. So to add a layer of complexity to the code, choose one of those positions randomly.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63.45px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.725px; text-align: left; transform-origin: 384px 31.725px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 369.242px 7.79167px; transform-origin: 369.242px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to encrypt a message in this way. Make sure to convert the string to all uppercase before encrypting. A string with the fractional part of the square root of 2 will be set as a global variable, and a seed will be passed to the function to be used in the command \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 34.65px 7.79167px; transform-origin: 34.65px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 34.65px 8.25px; transform-origin: 34.65px 8.25px; \"\u003erng(seed)\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 7.79167px; transform-origin: 1.94167px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function codes = sqrt2encode(plainText,seed)\r\n    rng(seed)\r\n    global sqrt2str    \r\n    codes = upper(plainText)-'0';","test_suite":"%%\r\nglobal sqrt2str    \r\ns = webread('https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil');\r\nsqrt2str = s(1230:1013886);\r\nsqrt2str(strfind(sqrt2str,newline))='';\r\n\r\n%%\r\nplainText = 'I saw Dad perform magic during one of the summers I worked for ARH.';\r\ncodes = sqrt2encode(plainText,42019);\r\ncodes_correct = [223124 798599 978403 455173 284845 749545 615179 709672 38243 46615 667887 23967 794350 275426 157253 18430 145665 306458 238497 614769 776279 643258 345627 330905 417218 179372 772145 795751 874773 711886 267045 548909 872617 35262 994765 222229 424408 283211 513854 593128 731753 685546 734347 328397 176774 32918 704799 900849 469604 290918 97195 819322 172170 699232 382524 296115 389461 328625 48922 429346 542715 655707 848636 884849 726843 667807 277835];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'He asked me to join him in a meeting with two people, one representing homeowners in a development and one representing the developer.';\r\ncodes = sqrt2encode(plainText,36324);\r\ncodes_correct = [840645 771842 937102 530200 978980 728204 464519 806712 45168 395736 555743 831876 749138 841485 496701 352299 1807 974698 993855 5838 497794 481196 491801 702863 924616 551857 401810 776187 734817 936180 366400 646601 708374 514864 195382 851891 890952 864338 452058 416814 279731 503733 775575 701746 602791 277181 161579 578802 550109 925506 608326 801014 248373 707878 762391 681161 566432 265271 653887 621872 356572 79785 987933 320607 778708 717071 291787 118700 825375 311010 236754 42813 449527 682299 514815 912774 938008 904057 744777 47197 611693 600275 117261 373909 650455 761309 138008 139093 531567 422758 477198 683032 154887 958961 944502 86330 843195 989256 546798 5542 89457 664362 445955 81196 558347 244517 879887 756587 891352 494171 484610 206732 332995 58655 436728 544528 783866 47525 526928 604372 996076 439122 281661 750778 44504 177788 999213 717342 330638 94112 896799 95484 62626 816987];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'The problem was that the drainage was designed to have water flow in the gutters of the streets, but the homeowners had built their driveways out into the streets.';\r\ncodes = sqrt2encode(plainText,18488);\r\ncodes_correct = [321121 230763 35765 330707 177259 486507 283793 584504 841874 124863 373658 754880 173668 810399 492673 168148 519669 123643 844180 708707 516212 348866 843957 878658 798058 848514 818400 841336 413602 105584 861511 122155 862742 78137 466085 375674 957950 91664 610170 551786 245359 748728 34331 686417 334888 509135 294380 834038 141576 345016 88703 997053 571436 296585 353309 273171 898589 124998 706867 994612 350816 617589 287235 78283 15632 907573 709684 406526 885556 90801 787455 371520 714916 42884 505054 738788 816384 93589 818073 872000 929403 558633 842301 312252 917957 594021 601548 888694 262133 664396 83014 94828 512806 587767 624017 496555 226167 910140 417827 484902 804796 282314 460051 274238 957884 895974 383711 472150 518405 149372 320652 432433 676603 883779 169730 853162 484982 868065 749876 651124 838751 147402 804330 724100 418815 983300 866646 570490 773188 286223 762038 703169 898545 180637 178107 631248 565936 739438 107998 704247 596656 780382 971578 709185 56046 135579 181505 363289 544904 179179 450588 610565 258754 604877 982427 87639 981775 285265 798832 242863 713183 964683 667975];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'The bumps from the driveways formed dams or jetties that blocked the flow and caused the streets to flood.';\r\ncodes = sqrt2encode(plainText,51829);\r\ncodes_correct = [559174 959043 443978 19661 96720 653316 533298 666730 561762 474394 240233 467260 19199 21539 625645 245508 961914 38714 660871 884673 897250 762702 229766 145324 117088 853018 841343 296495 860283 661380 761217 744354 685237 135066 877584 337692 138429 374879 445281 38171 627123 503760 741935 861210 817938 246658 570724 76719 679134 492337 693975 175953 444356 774100 4398 965746 419546 227944 785543 744991 852894 360056 837372 663401 771775 518768 830420 675226 956910 459830 982955 867477 73830 868315 954176 482652 707404 449168 636293 422238 243525 611047 151971 352845 519167 837283 41344 20546 995970 988988 720231 24887 735815 565332 867380 698306 174792 167939 526795 366650 672467 379225 77241 245805 651305 579437];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'Well, I was 19, in college, with a few engineering courses under my belt.';\r\ncodes = sqrt2encode(plainText,861);\r\ncodes_correct = [741766 693550 412918 393923 23868 146599 108034 289125 448147 47260 182083 486934 531457 338970 364814 904030 37099 211786 137647 871968 81878 300698 674094 513347 912965 853344 703367 247683 614808 283317 429798 370485 889473 845417 642511 320512 806961 719170 432008 45528 58248 318510 607881 494958 134631 406967 484602 658731 534811 301044 714916 170724 605299 211510 393819 835870 373075 825408 315707 955424 707953 159625 392964 850391 721400 84737 660904 341368 615454 359906 8245 468399 12493];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'In other words, I knew everything.';\r\ncodes = sqrt2encode(plainText,96894);\r\ncodes_correct = [269386 637630 91664 353803 849816 418977 175851 814791 539970 186111 188007 641861 505538 568474 429843 190532 42449 10095 781485 534228 958467 487276 715281 263427 493314 994939 113689 25382 105538 408542 671040 771308 161174 468806];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'To me the answer was clear: the homeowners were wrong.';\r\ncodes = sqrt2encode(plainText,80139);\r\ncodes_correct = [61854 637930 11818 867169 566024 878564 663726 313638 294774 213078 576444 142495 471596 781798 526374 920477 486229 851016 81057 45834 549938 612045 421202 52071 303288 897896 95948 861082 750380 140121 735206 462303 376667 15734 139975 943980 888374 152442 67559 183807 422802 211309 256624 950459 876456 517758 550992 134351 466733 245786 169468 138360 13457 38223];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'They extended their driveways beyond their property, so the only way their representative was going to walk away somewhat happy was if he could find a discounted rate for renting jackhammers.';\r\ncodes = sqrt2encode(plainText,75732);\r\ncodes_correct = [331780 396048 772398 823482 206638 619134 166004 183822 192939 173918 128491 595286 70650 56481 832793 930929 748974 855317 726883 444853 250606 169878 816827 68694 791866 864884 450841 324829 208486 269300 328100 729357 106496 267978 8977 254528 393095 64792 624809 937056 875247 519438 933039 368367 381943 97140 644226 334285 917854 608861 572236 415820 926228 410900 357583 751694 47351 833160 287490 869940 18045 834836 813692 899907 330332 368900 746027 744420 437695 958319 863963 951966 538853 651884 569852 129570 426577 628064 693187 990364 551488 925439 578084 761401 598056 685320 609872 123192 113848 315277 361346 357726 42108 438373 342933 144056 1574 465716 16489 468628 588449 870829 659672 416763 113612 295902 930538 369475 316687 477779 812547 469106 666864 96836 761313 883128 337794 450757 15063 570575 806754 700070 975535 457881 658354 411453 652628 911820 875859 405412 426618 408248 295490 772809 687756 851479 762287 15153 208272 46022 752685 223363 83707 610022 503222 388129 164391 355355 355405 374590 785289 117733 944359 453181 258559 281272 486286 534769 198087 171165 808003 918907 557874 577678 364565 209517 19231 848822 351216 219569 372941 609505 261343 385421 59783 56874 718039 829141 591210 292827 873147 313937 992940 497901 272011 462227 748321 764448 816747 363745 596448];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'But Dad listened to the two of them and somehow came up with a solution that satisfied them both.';\r\ncodes = sqrt2encode(plainText,67149);\r\ncodes_correct = [757661 815797 952576 34930 297252 638137 326352 954388 497168 103546 968551 135070 520374 565378 104537 353702 281350 170770 990108 899247 262148 80885 764300 843368 388019 860254 908775 857238 748037 663137 845647 962026 658114 367339 370683 438805 898351 410474 988151 264421 617772 912252 777975 286130 730164 207569 489357 566062 318563 911925 614794 823240 240264 795871 610017 438594 286046 507424 646130 915974 801916 476693 566861 458230 720760 118831 322814 427671 75822 31766 619341 650295 968571 958175 319414 566641 400510 831100 836036 156953 836819 504017 653726 462299 932356 549522 228404 714490 46002 318300 25859 891062 65051 508087 302554 678876 139690];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'I was so much in awe that I cannot even begin to tell you what he had proposed.';\r\ncodes = sqrt2encode(plainText,2966);\r\ncodes_correct = [673747 849127 73957 431196 124842 352837 178989 363325 731793 721822 802273 974866 368597 866430 980967 374867 211894 415558 908289 437240 100937 507589 256690 124827 418110 242057 483028 801611 724175 645423 889529 504807 942396 327626 549545 737120 280989 925005 732565 326020 830997 692694 44945 225380 307158 972971 711928 279749 386496 207819 478399 698097 221631 266599 460931 1496 964830 554626 759323 790781 225831 652862 381997 136239 440368 826334 343564 51423 15373 688437 602485 791811 319086 667741 768000 269710 778061 448307 224254];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nplainText = 'A few years ago, I asked him about it.';\r\ncodes = sqrt2encode(plainText,39157);\r\ncodes_correct = [7335 705290 726207 886801 182970 560908 788959 898669 78343 182645 86427 815650 665141 473070 406650 314404 474659 249077 81192 114577 333151 379662 772413 143922 611500 860103 169423 690118 293806 499539 765845 639358 611945 683301 156208 818101 532736 768969];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nq = char(39);\r\nplainText = ['He said he didn' q 't remember, but I like to think he was just following the magician' q 's code and not revealing his secret.'];\r\ncodes = sqrt2encode(plainText,40480);\r\ncodes_correct = [696094 365378 387685 289416 990143 500095 815792 311774 605024 665926 38337 365365 475123 842714 213855 845901 867100 450588 587864 781538 145190 172416 192039 175201 816036 14877 878723 549677 196221 617198 676083 833176 866842 267531 494003 640571 868863 688173 845419 527467 334239 790242 376046 809236 760376 134802 164114 145095 367732 558312 363570 599200 320695 182259 498690 383785 170657 870794 204883 421908 375824 574047 521922 537241 26417 884024 355886 550480 237981 644955 793982 125845 59977 357148 832507 645551 715383 344227 716126 656523 587209 273640 269262 277645 65454 958569 722194 113338 898688 541108 307559 820632 920897 408744 499580 132094 558243 998120 662048 849737 343791 453541 27839 133782 361543 941892 708219 893529 379928 932308 593347 154395 859124 391880 206229 680175 40793 737085 732779];\r\nassert(isequal(codes,codes_correct))\r\n\r\n%%\r\nfiletext = fileread('sqrt2encode.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'assert'); \r\nassert(~illegal)","published":true,"deleted":false,"likes_count":0,"comments_count":4,"created_by":46909,"edited_by":46909,"edited_at":"2023-05-18T20:42:57.000Z","deleted_by":null,"deleted_at":null,"solvers_count":3,"test_suite_updated_at":"2023-05-18T20:42:57.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2023-05-17T04:11:21.000Z","updated_at":"2023-05-18T20:42:57.000Z","published_at":"2023-05-17T04:15:10.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose you want to encrypt the word ‘TWIN’. The ASCII codes for the four letters are 84, 87, 73, and 78. If you consider the fractional part of the square root of 2 as a string \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4142135623\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e73\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e09504880168\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e87\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e242096980\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e78\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e56967187537694807317667973799073247\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e84\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen those ASCII codes are found at positions 72, 24, 11, and 35. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThose ASCII codes can be found in other positions in the fractional part of the square of 2. So to add a layer of complexity to the code, choose one of those positions randomly.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to encrypt a message in this way. Make sure to convert the string to all uppercase before encrypting. A string with the fractional part of the square root of 2 will be set as a global variable, and a seed will be passed to the function to be used in the command \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\u003erng(seed)\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\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":2606,"title":"Decrypt the  cypher using XOR encryption (for beginners)","description":"Inspired by Project Euler n°59\r\n\r\nEach character on a computer is assigned a unique code and the preferred standard is ASCII \r\n(American Standard Code for Information Interchange). For example, uppercase A = 65, asterisk (*) = 42, \r\nand lowercase k = 107.\r\nA basic encryption method is to take a text file or a sentence, convert the bytes to ASCII, then XOR each byte with a given \r\nvalue, taken from a secret key. The advantage with the XOR function is that using the same encryption key on the \r\ncipher text, restores the plain text; for example, 65 XOR 42 = 107, then 107 XOR 42 = 65.\r\n    \r\nYour task has been made easy, as the encryption key consists only of a upper case character (different in every tests). \r\nYou must know that the original text contains common FRENCH words about MATLAB.\r\n\r\nDecrypt the message and find the sum of the ASCII values in the original text.","description_html":"\u003cp\u003eInspired by Project Euler n°59\u003c/p\u003e\u003cp\u003eEach character on a computer is assigned a unique code and the preferred standard is ASCII \r\n(American Standard Code for Information Interchange). For example, uppercase A = 65, asterisk (*) = 42, \r\nand lowercase k = 107.\r\nA basic encryption method is to take a text file or a sentence, convert the bytes to ASCII, then XOR each byte with a given \r\nvalue, taken from a secret key. The advantage with the XOR function is that using the same encryption key on the \r\ncipher text, restores the plain text; for example, 65 XOR 42 = 107, then 107 XOR 42 = 65.\u003c/p\u003e\u003cp\u003eYour task has been made easy, as the encryption key consists only of a upper case character (different in every tests). \r\nYou must know that the original text contains common FRENCH words about MATLAB.\u003c/p\u003e\u003cp\u003eDecrypt the message and find the sum of the ASCII values in the original text.\u003c/p\u003e","function_template":"function y = XOR_cypher(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx=[15 3 22 14 3 0 236 98 39 49 54 98 55 44 98 46 35 44 37 35 37 39 98 38 39 98 42 35 55 54 98 44 43 52 39 35 55];\r\ny_correct=3360;\r\nassert(isequal(XOR_cypher(x),y_correct))\r\n%%\r\nx=[29 40 184 57 63 122 186 122 23 27 14 22 27 24 118 122 44 53 47 41 122 42 53 47 44 63 32 122 59 52 59 54 35 41 63 40 122 62 63 41 122 62 53 52 52 179 63 41 116];\r\ny_correct=4783;\r\nassert(isequal(XOR_cypher(x),y_correct))\r\n%%\r\nx=[28 33 41 53 54 43 60 35 117 121 47 48 42 44 56 53 48 42 60 35 121 60 45 121 52 54 61 176 53 48 42 60 35 121 47 54 42 121 61 54 55 55 176 60 42 121 56 47 60 58 121 20 24 13 21 24 27 119];\r\ny_correct=5667;\r\nassert(isequal(XOR_cypher(x),y_correct))\r\n%%\r\nx=[11 39 50 42 39 36 124 102 42 35 102 42 39 40 33 39 33 35 102 34 51 102 37 39 42 37 51 42 102 53 37 47 35 40 50 47 55 51 35];\r\ny_correct=3666;\r\nassert(isequal(XOR_cypher(x),y_correct))\r\n%%\r\nx=[27 36 62 57 58 62 36 34 107 40 35 36 56 34 57 107 6 42 63 39 42 41 107 46 63 107 59 42 56 107 27 50 63 35 36 37 107 116];\r\ny_correct=3547;\r\nassert(isequal(XOR_cypher(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":5390,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":66,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":32,"created_at":"2014-09-27T10:32:11.000Z","updated_at":"2026-03-19T21:22:18.000Z","published_at":"2014-09-27T10:33:19.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eInspired by Project Euler n°59\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEach character on a computer is assigned a unique code and the preferred standard is ASCII (American Standard Code for Information Interchange). For example, uppercase A = 65, asterisk (*) = 42, and lowercase k = 107. A basic encryption method is to take a text file or a sentence, convert the bytes to ASCII, then XOR each byte with a given value, taken from a secret key. The advantage with the XOR function is that using the same encryption key on the cipher text, restores the plain text; for example, 65 XOR 42 = 107, then 107 XOR 42 = 65.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour task has been made easy, as the encryption key consists only of a upper case character (different in every tests). You must know that the original text contains common FRENCH words about MATLAB.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDecrypt the message and find the sum of the ASCII values in the original text.\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":1467,"title":"Key Generation for Solitaire Cipher","description":"The Solitaire Cipher by Bruce Schneier was introduced to Cody in two problems by Doug Hull:  http://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cipher and http://www.mathworks.com/matlabcentral/cody/problems/766-implement-solitaire-cipher-for-n-long-deck.\r\n\r\nHowever, these problems do not address the initial configuration of the deck.  One simple approach uses a key phrase, as described here:  http://programmingpraxis.com/2011/01/18/solitaire-cipher/\r\n\r\nYour job is to implement this key generator.  Begin with the cards in numeric order (1:28) and process the deck once.  (To \"process\" the deck you should carry out all the steps necessary to produce one character in the keystream with the regular Solitaire cipher, but you don't emit any output.)  Now for each character k in the key, cut the deck by moving k cards from the front to the back of the deck.  After each cut, process the deck once again.  Assume that any non-alphabetic characters in the keyphrase generate a null cut (move zero characters from front to back).\r\n\r\nAt the end, you should return the state of the deck.","description_html":"\u003cp\u003eThe Solitaire Cipher by Bruce Schneier was introduced to Cody in two problems by Doug Hull:  \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cipher\"\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cipher\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/766-implement-solitaire-cipher-for-n-long-deck\"\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/766-implement-solitaire-cipher-for-n-long-deck\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eHowever, these problems do not address the initial configuration of the deck.  One simple approach uses a key phrase, as described here:  \u003ca href = \"http://programmingpraxis.com/2011/01/18/solitaire-cipher/\"\u003ehttp://programmingpraxis.com/2011/01/18/solitaire-cipher/\u003c/a\u003e\u003c/p\u003e\u003cp\u003eYour job is to implement this key generator.  Begin with the cards in numeric order (1:28) and process the deck once.  (To \"process\" the deck you should carry out all the steps necessary to produce one character in the keystream with the regular Solitaire cipher, but you don't emit any output.)  Now for each character k in the key, cut the deck by moving k cards from the front to the back of the deck.  After each cut, process the deck once again.  Assume that any non-alphabetic characters in the keyphrase generate a null cut (move zero characters from front to back).\u003c/p\u003e\u003cp\u003eAt the end, you should return the state of the deck.\u003c/p\u003e","function_template":"function deck = solitaireKey(keyphrase)\r\n  deck = 1:28;\r\nend","test_suite":"%%\r\nx = '';\r\ny_correct = [2:28,1];\r\nassert(isequal(solitaireKey(x),y_correct))\r\n\r\n%%\r\nx = 'SECRET KEY';\r\ny_correct = [26 25 7 8 2 13 6 16 27 4 5 19 23 21 14 15 9 3 20 11 12 28 17 18 10 1 24 22];\r\nassert(isequal(solitaireKey(x),y_correct))\r\n\r\n%%\r\nx = 'I don''t know the key to success, but the key to failure is trying to please everybody.';\r\ny_correct = [16 10 28 4 26 25 8 27 19 24 7 1 9 21 22 23 17 11 14 15 12 13 20 5 2 3 18 6];\r\nassert(isequal(solitaireKey(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":3117,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":6,"test_suite_updated_at":"2013-04-28T15:50:44.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-04-28T15:36:00.000Z","updated_at":"2013-04-28T15:50:44.000Z","published_at":"2013-04-28T15:50:44.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\u003eThe Solitaire Cipher by Bruce Schneier was introduced to Cody in two problems by Doug Hull: \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://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cipher\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/766-implement-solitaire-cipher-for-n-long-deck\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/766-implement-solitaire-cipher-for-n-long-deck\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\u003eHowever, these problems do not address the initial configuration of the deck. One simple approach uses a key phrase, as described here: \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://programmingpraxis.com/2011/01/18/solitaire-cipher/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://programmingpraxis.com/2011/01/18/solitaire-cipher/\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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 job is to implement this key generator. Begin with the cards in numeric order (1:28) and process the deck once. (To \\\"process\\\" the deck you should carry out all the steps necessary to produce one character in the keystream with the regular Solitaire cipher, but you don't emit any output.) Now for each character k in the key, cut the deck by moving k cards from the front to the back of the deck. After each cut, process the deck once again. Assume that any non-alphabetic characters in the keyphrase generate a null cut (move zero characters from front to back).\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\u003eAt the end, you should return the state of the deck.\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":766,"title":"Implement Solitaire cipher for N long deck.","description":"Implement the \u003chttp://en.wikipedia.org/wiki/Solitaire_(cipher) solitaire cypher\u003e.\r\n\r\nGiven a starting permutation of numbers [1:N], deck, generate M values for the keystream.   The small joker will be value N-1, the big joker will be N.\r\n\r\nThis is an update of this \u003chttp://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cypher problem\u003e.","description_html":"\u003cp\u003eImplement the \u003ca href=\"http://en.wikipedia.org/wiki/Solitaire_(cipher)\"\u003esolitaire cypher\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a starting permutation of numbers [1:N], deck, generate M values for the keystream.   The small joker will be value N-1, the big joker will be N.\u003c/p\u003e\u003cp\u003eThis is an update of this \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cypher\"\u003eproblem\u003c/a\u003e.\u003c/p\u003e","function_template":"function out = solitaire(deck, n)\r\n  out = n;\r\nend","test_suite":"deck = [1 4 7 10 13 16 19 22 25 28 3 6 9 12 15 18 21 24 27 2 5 8 11 14 17 20 23 26];\r\nm    = 10;\r\nout = [8    26     1     4     7    23     8     8     4    24];\r\nassert(isequal(solitaire(deck, m),out))\r\n\r\n%%\r\ndeck = 1:28;\r\nm    = 10;\r\nout = [3    22     9     4    23     7    25    16    14    14];\r\nassert(isequal(solitaire(deck, m),out))\r\n\r\n%%\r\ndeck = 1:28;\r\nm    = 10;\r\nout = [3    22     9     4    23     7    25    16    14    14];\r\nassert(isequal(solitaire(deck, m),out))\r\n\r\n%%\r\ndeck = 1:5;\r\nm    = 10;\r\nout = [3     4     1     1     5     5     4     2     4     1];\r\nassert(isequal(solitaire(deck, m),out))     ","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-06-14T17:57:56.000Z","updated_at":"2026-03-11T09:49:47.000Z","published_at":"2012-06-14T17:59:07.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\u003eImplement 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/Solitaire_(cipher)\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esolitaire cypher\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\u003eGiven a starting permutation of numbers [1:N], deck, generate M values for the keystream. The small joker will be value N-1, the big joker will be N.\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\u003eThis is an update of this\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://www.mathworks.com/matlabcentral/cody/problems/753-solitaire-cypher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eproblem\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":1499,"title":"Kryptos - CIA Cypher Sculpture: Vigenere Encryption","description":"The \u003chttp://en.wikipedia.org/wiki/Kryptos Kryptos Sculpture\u003e contains four encypted messages.\r\n\r\nThis Challenge is to Encrypt two of the original messages for the sculptor.\r\n\r\nThe method employed is \u003chttp://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher Vigenere Encryption\u003e. One clarification is that \"?\" are removed from the coding sequence and then re-inserted in the final encoded message.\r\n\r\nOriginal phrase: Between subtle shading and the absence of light lies the nuance of iqlusion.\r\n\r\nFor coding purposes spaces and punctuation are removed, except \"?\".\r\n\r\nPhrase to encode: BETWEENSUBTLESHADINGANDTHEABSENCEOFLIGHTLIESTHENUANCEOFIQLUSION\r\n\r\n*Input:* Encode Phrase, Vigenere alphabet word, Vigenere shift word\r\n\r\nVigenere alphabet word ='KRYPTOS';\r\n\r\nVigenere shift word ='PALIMPSEST';\r\n\r\n*Output:* EMUFPHZLRFAXYUSDJKZLDKRNSHGNFIVJYQTQUXQBQVYUVLLTREVJYQTMKYRDMFD\r\n\r\nThe encryption matrix for this case:\r\n\r\n  KRYPTOSABCDEFGHIJLMNQUVWXZ\r\n\r\n  PTOSABCDEFGHIJLMNQUVWXZKRY\r\n  ABCDEFGHIJLMNQUVWXZKRYPTOS\r\n  LMNQUVWXZKRYPTOSABCDEFGHIJ\r\n  IJLMNQUVWXZKRYPTOSABCDEFGH\r\n  MNQUVWXZKRYPTOSABCDEFGHIJL\r\n  PTOSABCDEFGHIJLMNQUVWXZKRY\r\n  SABCDEFGHIJLMNQUVWXZKRYPTO\r\n  EFGHIJLMNQUVWXZKRYPTOSABCD\r\n  SABCDEFGHIJLMNQUVWXZKRYPTO\r\n  TOSABCDEFGHIJLMNQUVWXZKRYP\r\n\r\nFollow Up Challenges:\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1500-kryptos-cia-cypher-sculpture-vignere-decryption Vigenere Decryption\u003e\r\n\r\n2) Dictionary search\r\n\r\n3) KRYPTOS Part IV\r\n\r\n\u003chttp://math.ucsd.edu/~crypto/Projects/KarlWang/index2.html#1 KRYPTOS Solutions\u003e\r\n\r\n  \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n","description_html":"\u003cp\u003eThe \u003ca href = \"http://en.wikipedia.org/wiki/Kryptos\"\u003eKryptos Sculpture\u003c/a\u003e contains four encypted messages.\u003c/p\u003e\u003cp\u003eThis Challenge is to Encrypt two of the original messages for the sculptor.\u003c/p\u003e\u003cp\u003eThe method employed is \u003ca href = \"http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher\"\u003eVigenere Encryption\u003c/a\u003e. One clarification is that \"?\" are removed from the coding sequence and then re-inserted in the final encoded message.\u003c/p\u003e\u003cp\u003eOriginal phrase: Between subtle shading and the absence of light lies the nuance of iqlusion.\u003c/p\u003e\u003cp\u003eFor coding purposes spaces and punctuation are removed, except \"?\".\u003c/p\u003e\u003cp\u003ePhrase to encode: BETWEENSUBTLESHADINGANDTHEABSENCEOFLIGHTLIESTHENUANCEOFIQLUSION\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e Encode Phrase, Vigenere alphabet word, Vigenere shift word\u003c/p\u003e\u003cp\u003eVigenere alphabet word ='KRYPTOS';\u003c/p\u003e\u003cp\u003eVigenere shift word ='PALIMPSEST';\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e EMUFPHZLRFAXYUSDJKZLDKRNSHGNFIVJYQTQUXQBQVYUVLLTREVJYQTMKYRDMFD\u003c/p\u003e\u003cp\u003eThe encryption matrix for this case:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eKRYPTOSABCDEFGHIJLMNQUVWXZ\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ePTOSABCDEFGHIJLMNQUVWXZKRY\r\nABCDEFGHIJLMNQUVWXZKRYPTOS\r\nLMNQUVWXZKRYPTOSABCDEFGHIJ\r\nIJLMNQUVWXZKRYPTOSABCDEFGH\r\nMNQUVWXZKRYPTOSABCDEFGHIJL\r\nPTOSABCDEFGHIJLMNQUVWXZKRY\r\nSABCDEFGHIJLMNQUVWXZKRYPTO\r\nEFGHIJLMNQUVWXZKRYPTOSABCD\r\nSABCDEFGHIJLMNQUVWXZKRYPTO\r\nTOSABCDEFGHIJLMNQUVWXZKRYP\r\n\u003c/pre\u003e\u003cp\u003eFollow Up Challenges:\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1500-kryptos-cia-cypher-sculpture-vignere-decryption\"\u003eVigenere Decryption\u003c/a\u003e\u003c/p\u003e\u003cp\u003e2) Dictionary search\u003c/p\u003e\u003cp\u003e3) KRYPTOS Part IV\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://math.ucsd.edu/~crypto/Projects/KarlWang/index2.html#1\"\u003eKRYPTOS Solutions\u003c/a\u003e\u003c/p\u003e","function_template":"function encoded=encode_vigenere(phrase,word1,word2)\r\n encoded=phrase;\r\nend","test_suite":"phrase=upper('Between subtle shading and the absence of light lies the nuance of iqlusion.');\r\nphrase_encode=phrase(regexp(phrase,'[A-Z?]'));\r\n\r\nencoded_exp='EMUFPHZLRFAXYUSDJKZLDKRNSHGNFIVJYQTQUXQBQVYUVLLTREVJYQTMKYRDMFD';\r\nword1='KRYPTOS';\r\nword2='PALIMPSEST';\r\nencoded= encode_vigenere(phrase_encode,word1,word2);\r\n\r\nassert(strcmp(encoded_exp,encoded))\r\n%%\r\n\r\nphrase=upper('It was totally invisible Hows that possible? They used the Earths magnetic field X The information was gathered and transmitted undergruund to an unknown location X Does Langley know about this? They should Its buried out there somewhere X Who knows the exact location? Only WW This was his last message X Thirty eight degrees fifty seven minutes six point five seconds north Seventy seven degrees eight minutes forty four seconds west ID by rows');\r\nphrase_encode=phrase(regexp(phrase,'[A-Z?]'));\r\n\r\n\r\nencoded_exp='VFPJUDEEHZWETZYVGWHKKQETGFQJNCEGGWHKK?DQMCPFQZDQMMIAGPFXHQRLGTIMVMZJANQLVKQEDAGDVFRPJUNGEUNAQZGZLECGYUXUEENJTBJLBQCRTBJDFHRRYIZETKZEMVDUFKSJHKFWHKUWQLSZFTIHHDDDUVH?DWKBFUFPWNTDFIYCUQZEREEVLDKFEZMOQQJLTTUGSYQPFEUNLAVIDXFLGGTEZ?FKZBSFDQVGOGIPUFXHHDRKFFHQNTGPUAECNUVPDJMQCLQUMUNEDFQELZZVRRGKFFVOEEXBDMVPNFQXEZLGREDNQFMPNZGLFLPMRJQYALMGNUVPDXVKPDQUMEBEDMHDAFMJGZNUPLGEWJLLAETG';\r\n\r\nword1='KRYPTOS';\r\nword2='ABSCISSA';\r\nencoded= encode_vigenere(phrase_encode,word1,word2);\r\n\r\nassert(strcmp(encoded_exp,encoded))\r\n%%\r\nphrase=upper('The fox jumped over the moon');\r\nphrase_encode=phrase(regexp(phrase,'[A-Z?]'));\r\n\r\nencoded_exp='VUIPFSBYVQMMWPIMEVPZCVK';\r\nword1='KRYPTOS';\r\nword2='MATLAB';\r\nencoded= encode_vigenere(phrase_encode,word1,word2);\r\n\r\nassert(strcmp(encoded_exp,encoded))\r\n\r\n%%\r\nphrase=upper('Between the Devil and the deep blue sea');\r\nphrase_encode=phrase(regexp(phrase,'[A-Z?]'));\r\n\r\n\r\nword1='AWEIGH';\r\nword2='MATLAB';\r\nencoded= encode_vigenere(phrase_encode,word1,word2);\r\nencoded_exp='SENMEDWTZNDDFIBLNNCHVTEDIBBCEZOA';\r\n\r\nassert(strcmp(encoded_exp,encoded))\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":3,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":61,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":28,"created_at":"2013-05-11T20:36:34.000Z","updated_at":"2026-03-07T04:46:20.000Z","published_at":"2013-05-11T21:19:07.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\u003eThe\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/Kryptos\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eKryptos Sculpture\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e contains four encypted messages.\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\u003eThis Challenge is to Encrypt two of the original messages for the sculptor.\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 method employed is\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/Vigen%C3%A8re_cipher\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eVigenere Encryption\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. One clarification is that \\\"?\\\" are removed from the coding sequence and then re-inserted in the final encoded 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\u003eOriginal phrase: Between subtle shading and the absence of light lies the nuance of iqlusion.\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\u003eFor coding purposes spaces and punctuation are removed, except \\\"?\\\".\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\u003ePhrase to encode: BETWEENSUBTLESHADINGANDTHEABSENCEOFLIGHTLIESTHENUANCEOFIQLUSION\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\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Encode Phrase, Vigenere alphabet word, Vigenere shift word\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\u003eVigenere alphabet word ='KRYPTOS';\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\u003eVigenere shift word ='PALIMPSEST';\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\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e EMUFPHZLRFAXYUSDJKZLDKRNSHGNFIVJYQTQUXQBQVYUVLLTREVJYQTMKYRDMFD\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 encryption matrix for this case:\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[KRYPTOSABCDEFGHIJLMNQUVWXZ\\n\\nPTOSABCDEFGHIJLMNQUVWXZKRY\\nABCDEFGHIJLMNQUVWXZKRYPTOS\\nLMNQUVWXZKRYPTOSABCDEFGHIJ\\nIJLMNQUVWXZKRYPTOSABCDEFGH\\nMNQUVWXZKRYPTOSABCDEFGHIJL\\nPTOSABCDEFGHIJLMNQUVWXZKRY\\nSABCDEFGHIJLMNQUVWXZKRYPTO\\nEFGHIJLMNQUVWXZKRYPTOSABCD\\nSABCDEFGHIJLMNQUVWXZKRYPTO\\nTOSABCDEFGHIJLMNQUVWXZKRYP]]\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\u003eFollow Up Challenges:\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\u003e1)\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://www.mathworks.com/matlabcentral/cody/problems/1500-kryptos-cia-cypher-sculpture-vignere-decryption\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eVigenere Decryption\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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\u003e2) Dictionary search\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\u003e3) KRYPTOS Part IV\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:hyperlink w:docLocation=\\\"http://math.ucsd.edu/~crypto/Projects/KarlWang/index2.html#1\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eKRYPTOS Solutions\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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:\"encryption\"","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:\"encryption\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"encryption\"","","\"","encryption","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fac44feed98\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fac44feecf8\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fac44fee438\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fac44fef018\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fac44feef78\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fac44feeed8\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fac44feee38\u003e":"tag:\"encryption\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fac44feee38\u003e":"tag:\"encryption\""},"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:\"encryption\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"encryption\"","","\"","encryption","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fac44feed98\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fac44feecf8\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fac44fee438\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fac44fef018\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fac44feef78\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fac44feeed8\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fac44feee38\u003e":"tag:\"encryption\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fac44feee38\u003e":"tag:\"encryption\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":58309,"difficulty_rating":"easy-medium"},{"id":58299,"difficulty_rating":"easy-medium"},{"id":2606,"difficulty_rating":"medium"},{"id":1467,"difficulty_rating":"medium"},{"id":766,"difficulty_rating":"medium"},{"id":1499,"difficulty_rating":"medium-hard"}]}}