From 483c288825aa0ab8f508fb63b331e78c8283d47a Mon Sep 17 00:00:00 2001 From: Yurii Drahomaretskyi Date: Thu, 30 Jul 2020 15:23:09 +0200 Subject: [PATCH] done --- .idea/.gitignore | 5 +++++ .idea/Node.js_challenge_dzien_3.iml | 12 ++++++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ app/zadanie01.js | 26 +++++++++++++++++++++++++- app/zadanieDnia1.js | 21 ++++++++++++++++++++- app/zadanieDnia2.js | 15 ++++++++++++++- 8 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/Node.js_challenge_dzien_3.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/Node.js_challenge_dzien_3.iml b/.idea/Node.js_challenge_dzien_3.iml new file mode 100644 index 0000000..24643cc --- /dev/null +++ b/.idea/Node.js_challenge_dzien_3.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b77df43 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/zadanie01.js b/app/zadanie01.js index 842f75e..199a573 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1,3 +1,27 @@ const MY_PWD_HASH = '5dca0fc4e306d92b2077ad85e7c4bd87a3e8648e'; -//Twój kod \ No newline at end of file +//Twój kod + +const crypto = require('crypto'); + +const passwords = ['??TegoHasła', + 'CodersLab', + 'Node.js Szyfruje Pliki', + 'Zaźółć Gęślą Jaźń', + 'Moje Haslo 1@3!', + '111#$((@)n', + 'Dzisiaj Szyfruje 83' +] + +const algorithms = ['sha256', 'sha512', 'md5', 'rmd160']; + +algorithms.forEach(algoritm => { + passwords.forEach(pasword => { + let hash = crypto.createHmac(algoritm, pasword) + .digest('hex'); + + if (MY_PWD_HASH === hash) { + console.log(`algoritm - ${algoritm}, pasword - ${pasword}`); + } + }) +}) diff --git a/app/zadanieDnia1.js b/app/zadanieDnia1.js index 8c20173..e59ebc7 100644 --- a/app/zadanieDnia1.js +++ b/app/zadanieDnia1.js @@ -1 +1,20 @@ -//Twój kod \ No newline at end of file +//Twój kod +const fs = require('fs'); +const crypto = require('crypto'); + +const codeFunc = (linkToFile) => { + fs.readFile(linkToFile, 'utf8', (err, data) => { + if (err === null) { + console.log(data); + const hash = crypto.createHmac('sha256', data) + .digest('hex'); + console.log(hash); + } else { + console.log(err); + } + }) +} + +const linkToSomeText = './data/zadanieDnia1/testFile.txt'; + +codeFunc(linkToSomeText); diff --git a/app/zadanieDnia2.js b/app/zadanieDnia2.js index 85846f4..6ea0936 100644 --- a/app/zadanieDnia2.js +++ b/app/zadanieDnia2.js @@ -1,3 +1,16 @@ const ENCRYPTED_TEXT = '4f9fa8f98650091c4910f5b597773c0a48278cfb001fe4eb3ff47ada85cbf0ed3dc17016b031e1459e6e4d9b001ab6e102c11e834a98dce9530c9668c47b76ee6f09d075d19a38e48b415e067c6ddcfad0d3526c405a4f4f2fb1e7502f303c40'; -//Twój kod \ No newline at end of file +//Twój kod + +const crypto = require('crypto'); +const algorithms = ['aes192', 'aes-256-cbc', 'aes-256-ecb']; +const pass = 'PysęjkkyDw'; +function decodeText(encodedText, password, algorithm) { + const decipher = crypto.createDecipher(algorithm, password); + + let decrypted = decipher.update(encodedText, 'hex', 'utf8'); + decrypted += decipher.final('utf8'); + return decrypted; +} + +decodeText(ENCRYPTED_TEXT, pass, 'aes-256-ecb'); \ No newline at end of file