From 7ef89befa1b3dff3c20930d6821e3a7a27e87a82 Mon Sep 17 00:00:00 2001 From: RadekM86 Date: Wed, 31 Jan 2018 19:38:23 +0100 Subject: [PATCH 1/4] Zadanie01 --- app/zadanie01.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/zadanie01.js b/app/zadanie01.js index 842f75e..e50b166 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1,3 +1,14 @@ +const crypto = require('crypto'); const MY_PWD_HASH = '5dca0fc4e306d92b2077ad85e7c4bd87a3e8648e'; -//Twój kod \ No newline at end of file +//Twój kod +const passwordList = ['??TegoHasła','CodersLab','Node.js Szyfruje Pliki','Zaźółć Gęślą Jaźń','Moje Haslo 1@3!','111#$((@)n','Dzisiaj Szyfruje 83']; + +const algorithmList = ['sha256', 'sha512', 'md5', 'rmd160']; + +passwordList.forEach(password=>{ + algorithmList.filter(algorithm=>{ + const encrypted = crypto.createHmac(algorithm, password).digest('hex'); + (encrypted === MY_PWD_HASH)&&console.log(`hasło to: ${password} ; algorytm to: ${algorithm}`) + }) +}) \ No newline at end of file From 8edf5ebc3ec57c41a0fe682b979a4bf7e201bb3b Mon Sep 17 00:00:00 2001 From: RadekM86 Date: Wed, 31 Jan 2018 19:48:10 +0100 Subject: [PATCH 2/4] ZadanieDnia1 --- app/zadanieDnia1.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/zadanieDnia1.js b/app/zadanieDnia1.js index 8c20173..a5310ce 100644 --- a/app/zadanieDnia1.js +++ b/app/zadanieDnia1.js @@ -1 +1,16 @@ -//Twój kod \ No newline at end of file +//Twój kod +const crypto = require('crypto'); +const fs = require('fs'); + +fs.readFile(process.argv[2], 'utf8', (err, data) => { + if (err === null){ + console.log('Poprawnie odczytano plik.'); + let dataHashed = crypto.createHmac('sha256', data) + .digest('hex'); + console.log('Wartość zakodowana:') + console.log(dataHashed); + + }else{ + console.log('Błąd podczas odczytu pliku!', err); + } +}); From 3925c2764500f171dab5da681cb09d1082fbb9d1 Mon Sep 17 00:00:00 2001 From: RadekM86 Date: Wed, 31 Jan 2018 19:54:33 +0100 Subject: [PATCH 3/4] ZadanieDnia2 --- app/zadanieDnia2.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/zadanieDnia2.js b/app/zadanieDnia2.js index 85846f4..792595d 100644 --- a/app/zadanieDnia2.js +++ b/app/zadanieDnia2.js @@ -1,3 +1,14 @@ const ENCRYPTED_TEXT = '4f9fa8f98650091c4910f5b597773c0a48278cfb001fe4eb3ff47ada85cbf0ed3dc17016b031e1459e6e4d9b001ab6e102c11e834a98dce9530c9668c47b76ee6f09d075d19a38e48b415e067c6ddcfad0d3526c405a4f4f2fb1e7502f303c40'; -//Twój kod \ No newline at end of file +//Twój kod +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; +} + +console.log(decodeText(ENCRYPTED_TEXT, "PysęjkkyDw",'aes-256-ecb')) \ No newline at end of file From cba91bebac254b1630d4f46c75fecfdfc52be536 Mon Sep 17 00:00:00 2001 From: RadekM86 Date: Wed, 31 Jan 2018 20:09:51 +0100 Subject: [PATCH 4/4] =?UTF-8?q?Zautomatyzowane=20rozwi=C4=85zanie=20zadani?= =?UTF-8?q?aDnia2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/zadanieDnia2.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/zadanieDnia2.js b/app/zadanieDnia2.js index 792595d..7be38c7 100644 --- a/app/zadanieDnia2.js +++ b/app/zadanieDnia2.js @@ -2,6 +2,12 @@ const ENCRYPTED_TEXT = '4f9fa8f98650091c4910f5b597773c0a48278cfb001fe4eb3ff47ada //Twój kod const crypto = require('crypto'); +const algorithmList = ['aes192', 'aes-256-cbc', 'aes-256-ecb']; +let password = ""; +const sentence = "Pobawmy się jak komputerowy Detektyw"; +let wordsList = []; +wordsList = sentence.split(' ').filter(word=>{password = password + word[0] + word[word.length-1]}) + function decodeText(encodedText, password, algorithm){ const decipher = crypto.createDecipher(algorithm, password); @@ -11,4 +17,12 @@ function decodeText(encodedText, password, algorithm){ return decrypted; } -console.log(decodeText(ENCRYPTED_TEXT, "PysęjkkyDw",'aes-256-ecb')) \ No newline at end of file + +algorithmList.forEach(algorithm=>{ + try{ + console.log(decodeText(ENCRYPTED_TEXT, password, algorithm)) + }catch(err) { + return null + } + +})