Question: Part 3 (25): Caesar Cipher encryption function Create a JavaScript function that accepts three parameters, and returns the Caesar Cipher encrypted text. Reference the Caesar
Part 3 (25): Caesar Cipher encryption function
Create a JavaScript function that accepts three parameters, and returns the Caesar Cipher encrypted text. Reference the Caesar Cipher (Links to an external site.) Wikipedia page to learn more about the technical specifications of the Caesar Cipher.
Function name: CaesarEncrypt(clearText, shiftNum, shiftLeft)
Parameters:
- clearText: the unencrypted string
- shiftNum: the integer number of positions to shift, default to two positions shift
- shiftLeft: the Boolean value of whether the shifting is left (true), or right (false), default to left shift is true
Return: Encrypted text using the parameter values.
Output: No output
You will ONLY encrypt (i.e., shift) uppercase or lowercase alphabetic characters, and numbers. All other characters are returned unshifted.
This function must be contained within an external JavaScript file called Project1.js.
Part 4 (25): Caesar Cipher substitution alphabet function
Create a JavaScript function that outputs the Caesar Cipher substitution alphabet (Links to an external site.) using the ASCII table between decimal value 33 (!) and 126 (~). The function will update the DOM with separate HTML div elements for each of the characters within the ASCII range (33 - 126).
Function name: DisplaySubstitutionAlphabet()
Parameters:
- No parameters are required for this function
Return: This function does not return anything.
Output: Update DOM with substitution table using div elements for each of the ASCII range (33 - 126)
Original=Shifted
For example, for ASCII range 57 - 66, with a left shift of two positions, the results are displayed below:
...9=7:=:;=;<=<===>=>?=?@=@A=YB=Z...
This function MUST use the following JavaScript programming elements:
- Current position shift number
- Shift left or shift right status
- Obtain a reference to the output div
- document querySelector
- Generate an array containing the ASCII numbers using
- Array()
- Spread operator
- Array keys() method
- Filter the ASCII numbers to limit the array to the specified ASCII decimal range
- Array filter() method
- Iterate through each of the ASCII numbers
- Array map() method or Array forEach() method (see Map vs. ForEach (Links to an external site.))
- Generate a string with the final ouput
- Template literal for the output
- String fromCharCode() method
- Update the output div
- document createElement()
- element innerHTML property
- output div appendChild()
Tip: See Refresher Quiz Questions and Answers solution to "Declare an array integers initialized with 0 through 5 and write a for loop with index that uses the array length" question.
This function must be contained within an external JavaScript file called Project1.js.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
