Problem 58299. Encrypt a message with the square root of 2
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
4142135623730950488016887242096980785696718753769480731766797379907324784…
then those ASCII codes are found at positions 72, 24, 11, and 35.
Those 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.
Write 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).
Solution Stats
Problem Comments
-
4 Comments
Show
1 older comment
Christian Schröder
on 18 May 2023
@David The global variable is provided by the test suite.
David Hill
on 18 May 2023
@Christian
I don't see how the global variable is provided. Went I run the global variable is empty.
ChrisR
on 18 May 2023
David, try it now. The first "test" should be
global sqrt2str
s = webread('https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil');
sqrt2str = s(1230:1013886);
sqrt2str(strfind(sqrt2str,newline))='';
It was in the test suite, but it didn't appear on Cody till I put '%%' ahead of it.
Solution Comments
Show commentsProblem Recent Solvers3
Suggested Problems
-
Back to basics 9 - Indexed References
446 Solvers
-
Replace multiples of 5 with NaN
446 Solvers
-
Simple equation: Annual salary
4201 Solvers
-
convert matrix to single column
415 Solvers
-
989 Solvers
More from this Author291
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!