- [Build] Make a two page application for encryption/decryption message
- [Data Processing] Dependent Dropdowns
- React - For Front-End Library 🏡
- TailWindCSS - For Simple Style 💄 & responsiveness ✨
- CSS - Simple Animations 💫
- SheetJS - For parsing excel data
See LIVE here: Renata Task Application
Or
Install the dependencies and devDependencies and start the server.
npm install
npm start
✨ Simple!
- Take an object of array of all alphabates
const alphabates = {
upperCase:['A','B','C',...],
lowerCase:['a','b','c',...]
}
- Recieve the message from Input field
- Generate a random number for secret key. between 1-25
- Match the message letters with alphabate object to find index
- Add the secret key. with index
- Shift the letter number of secret key. times
- Round up the letter if new index > 26
- Concant the new shifted leeter starting with the secret key.
- Finally replace the 'SPACE' with point (.)
Copy to clipboard to copy the result
Only message of characters with uppercase or lowercase can be encoded.
input: CATS And DOGS
output: 25BZSR.Zmc.CNFR
Reverse The Encryption process
- Separate the secret key. from encode message
- Find the letters from alphabate object
- Subtract the secret key. from each index of letters
- Shift back the letters bysecret key. times
- If new index < 0 round up the letter backward
- Concat the decoded letters
- Replace the point(.) with 'SPACE'
Only characters with uppercase or lowercase, numbers and point(.) can be decoded.
input:25BZSR.Zmc.CNFR
output:CATS And DOGS
Data Processing from excel sheet:
- Used SheetJs for parsing the data from excel sheet
- Parsing the data from excel file within onload event
var url = "data.xlsx"; // the excel file should be in public folder
useEffect(() => {
var oReq = new XMLHttpRequest();
oReq.open("GET", url, true);
oReq.responseType = "arraybuffer";
oReq.onload = function (e) {
var arraybuffer = oReq.response;
/* convert data to binary string */
var data = new Uint8Array(arraybuffer);
var arr = [];
for (var i = 0; i !== data.length; ++i)
arr[i] = String.fromCharCode(data[i]);
var bstr = arr.join("");
/* Call XLSX */
var workbook = XLSX.read(bstr, {
type: "binary",
});
/* DO SOMETHING WITH workbook HERE */
var first_sheet_name = workbook.SheetNames[0];
/* Get worksheet */
var worksheet = workbook.Sheets[first_sheet_name];
var data__raw = XLSX.utils.sheet_to_json(worksheet, {
raw: true,
});
console.log("line 33", data__raw);
setFetchedData(data__raw);
console.log(
XLSX.utils.sheet_to_json(worksheet, {
raw: true,
})
);
};
oReq.send();
},[url])
- Set the data in a react state
- Map the first field Language in the Language Dropdown
- After selecting the first dropdown option filter the fetched data according to the selected Laguage field.then map the second dropdown
- Same process with the third dropdown after selecting the topic field from second dropdown
- Finallay find the Iframe link after according to the value of three dropdown
- All the W3school.com links are blocked by their Content Security Policy.That's why , all the links refuse to connect in the iFrame.
- Parsing the Data from Excel sheet was tough.
- For problem One Couldn't found any solution to show the url links because w3school refuse to connect because of their policies. Only in their domain Iframe works fine because of own domain.
- First three Iframe link data is changed with other resource links in the excel file just to show the logic works fine.
- A Default Link is provided in iFrame .