type linux node2 v1 rasb14 2019-02-14 21:45:59 v3.1.3 (2018-09-13)
Generated 2019-02-14 22:45:59 by dbwebb lab-utility v3.1.3 (2018-09-13).
JavaScript using nodejs. During these exercises we train on the built-in nodejs modules filesystem, querystring and crypto. Documentation can be found at nodejs api.
This section is about the built-in module filesystem and how to read and write files synchronously.
Start by requiring the filesystem module fs.
Use the fs module and the function readFileSync to read the entire ircLog.txt in UTF-8 encoding into a variable. Answer with the number of characters in the file.
Use your variable from the exercise above and answer with the contents on line 4.
Write line number 4 of ircLog.txt to a new file that you create called highlights.txt. Replace highlights.txt if it already exists.
Answer with characters 7 through 10 from highlights.txt.
Tip: Use the function writeFileSync() when writing to files.
This section is about the built-in module querystring and how to parse and encode query strings.
Start by requiring the querystring module querystring.
Use the querystring module to parse a query string ‘first_name=Jim&last_name=Lovell&mission=Apollo13’. Answer with the value of mission.
Use the parsed query string from above to concatenate the astronaut’s full name with the string ’ was on the ’ and the mission that the astronaut was on.
Create a javascript object with the following attributes and values:
url = https://dbwebb.se/
id = 414
payload = aHR0cHM6Ly9kYndlYmIuc2Uv
type = json
Encode the javascript object as a querystring and answer with the encoded query string.
This section is about the built-in module crypto and how to encrypt data with nodejs.
Start by requiring the crypto module.
Use the crypto module to create a hash of ‘Couldnt be much more from the heart’ using the sha256 algorithm.
Answer with a digest of the hash in hex format.
Create an array called cryptoStrings holding the strings ‘Couldnt be much more from the heart’, ‘Forever trusting who we are’, ‘And nothing else matters’, ‘Never opened myself this way’.
Use filter to create an array only containing elements that has the string ‘nothing else matters’ in them.
Answer with the array.
Use the array from above only containing elements with ‘nothing else matters’.
For the elements in the array create a hex digest of a hash created with with the sha256 algorithm of each element.
Answer with the array of hashes.
Use filter to keep all elements in cryptoStrings that contains both an ‘i’, an ‘e’, and a ‘m’, check both capital and non-capital letters.
For the remaining elements create a hex digest of a hash created with with the sha256 algorithm of each remaining element.
Answer with the array of hashes.
Using the same cryptoStrings array from above remove all elements that does NOT contain ‘matters’, check both capital and non-capital letters.
For the remaining elements create a HMAC using the sha256 algorithm and the secret ‘metallica’ for each element. Create a base64 digest of the HMAC for each element.
Answer with the array of HMACs.
type