Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Latest commit

 

History

History
24 lines (19 loc) · 1.01 KB

ex_02.md

File metadata and controls

24 lines (19 loc) · 1.01 KB

Exercise 02

Using the lesson02_example.html file as a template (i.e., a starting point to modify), create an HTML page in which you can "encode" and "decode" a message using a substitution cipher. So, in the page you will have a textarea to input your text, one textarea to show the result (encoded or decoded), and three buttons: to encode, decode or clear the textareas.

The substitution cipher should do a char shift of +7 values. So, when you encode the string "abc" you should get "hij". When encoding "{Hello!!!}", you should get "$Olssv(((&".

To get the char code from the first char in a string, in JavaScript use the function .charCodeAt(0). To convert from char code x to string, use String.fromCharCode(x).

Note: be careful to consider only chars in the range 33-126. Chars outside such range should be ignored, i.e. kept the same. To avoid overflows (i.e., a value that goes above 126), you will need to use the module operator %.

Solutions to this exercise can be found under the solutions/02 folder.