From f58811af2e09e5bd85eb4222b753ca98d5c566f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20G=C3=B3rzanowska?= Date: Thu, 15 Feb 2018 04:20:00 +0100 Subject: [PATCH 1/5] password & algorithms in arrays --- .idea/Node.js_challenge_dzien_3.iml | 12 ++ .idea/misc.xml | 6 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + .idea/workspace.xml | 184 ++++++++++++++++++++++++++++ app/zadanie01.js | 20 ++- 6 files changed, 235 insertions(+), 1 deletion(-) 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 create mode 100644 .idea/workspace.xml 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/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..857b5ad --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,184 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + false + true + true + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -125,15 +124,17 @@ - + @@ -141,7 +142,7 @@ - + @@ -174,8 +175,16 @@ - - + + + + + + + + + + diff --git a/app/zadanie01.js b/app/zadanie01.js index 45b3558..20dee0b 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1,21 +1,23 @@ +const crypto = require('crypto'); + const MY_PWD_HASH = '5dca0fc4e306d92b2077ad85e7c4bd87a3e8648e'; const password = ['??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']; -const crypto = require('crypto'); - -function decodeText(encodedText, password, algorithm){ - const decipher = crypto.createDecipher(algorithm, password); - - let decrypted = decipher.update(encodedText, 'hex', 'utf8'); - decrypted += decipher.final('utf8'); - return decrypted; -} -password.map((password, algorithms) => - console.log(decodeText(MY_PWD_HASH, password, algorithms)) -); +let whichPassword = (password, algorithms, hash) => { + let correctPassword; + password.forEach(p => { + algorithms.forEach(a => { + if (crypto.createHmac(a, p).digest('hex') === hash) { + correctPassword = `Our password is: ${p}. Our algorithm is: ${a}`; + }; + }); + }); + return whichPassword ? console.log(correctPassword) : console.log('Password not find'); +}; +whichPassword(password, algorithms, MY_PWD_HASH); \ No newline at end of file From e4a5164a3ee3646ec2f2b345c313d8b47fa0d90a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20G=C3=B3rzanowska?= Date: Thu, 15 Feb 2018 11:04:57 +0100 Subject: [PATCH 3/5] crypto done --- app/zadanieDnia1.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/zadanieDnia1.js b/app/zadanieDnia1.js index 8c20173..30b0818 100644 --- a/app/zadanieDnia1.js +++ b/app/zadanieDnia1.js @@ -1 +1,19 @@ -//Twój kod \ No newline at end of file +const fs = require('fs'); +const crypto = require('crypto'); + +function ReadAndCrypto(fileName) { + fs.readFile(fileName, 'utf8', (err, data) => { + if (err === null){ + console.log("Poprawnie odczytano plik. \n", data); + const hash = crypto.createHmac('sha256', data) + .digest('hex'); + console.log(hash); + + + } else { + console.log('Błąd podczas odczytu pliku!', err); + } + }); +} + +ReadAndCrypto(process.argv[2]); From 2ab440a877886ddc24c46b9beff39a2621915173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20G=C3=B3rzanowska?= Date: Thu, 15 Feb 2018 11:10:21 +0100 Subject: [PATCH 4/5] ZadanieDnia1 --- .gitignore | 3 +++ app/zadanieDnia1.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..de88951 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +*.*~ +node_modules diff --git a/app/zadanieDnia1.js b/app/zadanieDnia1.js index 30b0818..a69b222 100644 --- a/app/zadanieDnia1.js +++ b/app/zadanieDnia1.js @@ -4,7 +4,7 @@ const crypto = require('crypto'); function ReadAndCrypto(fileName) { fs.readFile(fileName, 'utf8', (err, data) => { if (err === null){ - console.log("Poprawnie odczytano plik. \n", data); + console.log("Poprawnie odczytano plik. \n"); const hash = crypto.createHmac('sha256', data) .digest('hex'); console.log(hash); From 3382345ac06458ec481c9fb83d79faa6875d6c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20G=C3=B3rzanowska?= Date: Thu, 15 Feb 2018 13:30:04 +0100 Subject: [PATCH 5/5] challenge done --- app/zadanieDnia2.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/zadanieDnia2.js b/app/zadanieDnia2.js index 85846f4..80c1353 100644 --- a/app/zadanieDnia2.js +++ b/app/zadanieDnia2.js @@ -1,3 +1,19 @@ const ENCRYPTED_TEXT = '4f9fa8f98650091c4910f5b597773c0a48278cfb001fe4eb3ff47ada85cbf0ed3dc17016b031e1459e6e4d9b001ab6e102c11e834a98dce9530c9668c47b76ee6f09d075d19a38e48b415e067c6ddcfad0d3526c405a4f4f2fb1e7502f303c40'; +const algorithms = ['aes192', 'aes-256-cbc', 'aes-256-ecb']; +const password = 'PysęjkkyDw'; +const crypto = require('crypto'); + +function decodeText(text, password, algorithm){ + const decipher = crypto.createDecipher(algorithm, password); + + let decrypted = decipher.update(text, 'hex', 'utf8'); + decrypted += decipher.final('utf8'); + + console.log(decrypted); + return decrypted; +} + +decodeText(ENCRYPTED_TEXT, password, 'aes-256-ecb'); + + -//Twój kod \ No newline at end of file