{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-16T00:12:35.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":"2026-04-16T00: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":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\"}]}"}],"problem_search":{"errors":[],"problems":[{"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\"}]}"}],"term":"tag:\"#200\"","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:\"#200\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"#200\"","","\"","#200","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f352937dfd8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f352937df38\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f352937d678\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f352937e258\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f352937e1b8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f352937e118\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f352937e078\u003e":"tag:\"#200\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f352937e078\u003e":"tag:\"#200\""},"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":"cody-search","password":"78X075ddcV44","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:\"#200\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"#200\"","","\"","#200","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f352937dfd8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f352937df38\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f352937d678\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f352937e258\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f352937e1b8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f352937e118\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f352937e078\u003e":"tag:\"#200\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f352937e078\u003e":"tag:\"#200\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":58299,"difficulty_rating":"easy-medium"}]}}