From c29324452d222ed44b54e0db78cc51411d6fc4c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Dadlez?= Date: Wed, 31 Jan 2018 23:16:19 +0100 Subject: [PATCH] =?UTF-8?q?rozwi=C4=85zania?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/zadanie01.js | 12 +++++++++++- app/zadanieDnia1.js | 20 +++++++++++++++++++- app/zadanieDnia2.js | 17 ++++++++++++++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/app/zadanie01.js b/app/zadanie01.js index 842f75e..c2a56c8 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1,3 +1,13 @@ +const crypto = require('crypto'); const MY_PWD_HASH = '5dca0fc4e306d92b2077ad85e7c4bd87a3e8648e'; -//Twój kod \ No newline at end of file +//Twój kod +const passwords = ['??TegoHasła', 'CodersLab', 'Node.js Szyfruje Pliki', 'Zaźółć Gęślą Jaźń', 'Moje Haslo 1@3!', '111#$((@)n', 'Dzisiaj Szyfruje 83']; +const algorythms = ['sha256', 'sha512', 'md5', 'rmd160']; + +passwords.forEach(pswd => { + algorythms.forEach(algorythm => { + const result = crypto.createHmac(algorythm, pswd); + console.log(result.digest('hex') === MY_PWD_HASH ? '-> ' : ' ', algorythm, `"${pswd}"`); + }); +}); \ No newline at end of file diff --git a/app/zadanieDnia1.js b/app/zadanieDnia1.js index 8c20173..d678a81 100644 --- a/app/zadanieDnia1.js +++ b/app/zadanieDnia1.js @@ -1 +1,19 @@ -//Twój kod \ No newline at end of file +//Twój kod +const fs = require('fs'); +const crypto = require('crypto'); + +const file = process.argv[2] || './data/zadanieDia1/testFile.txt'; + +const controlSum = (file) => { + console.log('file: ', file); + fs.readFile(file, 'utf8', (err, data) => { + console.log('data: ', data); + if (!err) { + console.log('hash: ', crypto.createHmac('sha256', data).digest('hex')); + } else { + console.log('Błąd przy czytaniu pliku:\n', err); + } + }); +}; + +controlSum(file); //czemu rezultat jest inny niż w poleceniu? \ No newline at end of file diff --git a/app/zadanieDnia2.js b/app/zadanieDnia2.js index 85846f4..552e894 100644 --- a/app/zadanieDnia2.js +++ b/app/zadanieDnia2.js @@ -1,3 +1,18 @@ +const crypto = require('crypto'); const ENCRYPTED_TEXT = '4f9fa8f98650091c4910f5b597773c0a48278cfb001fe4eb3ff47ada85cbf0ed3dc17016b031e1459e6e4d9b001ab6e102c11e834a98dce9530c9668c47b76ee6f09d075d19a38e48b415e067c6ddcfad0d3526c405a4f4f2fb1e7502f303c40'; -//Twój kod \ No newline at end of file +//Twój kod +const password = 'PysęjkkyDw'; +const algorythms = ['aes192', 'aes-256-cbc', 'aes-256-ecb']; + +algorythms.forEach(algorythm => { + const decipher = crypto.createDecipher(algorythm, password); + let decrypted = decipher.update(ENCRYPTED_TEXT, 'hex', 'utf8'); + try { + decrypted += decipher.final('utf8'); + console.log(decrypted); + } + catch (err) { + console.log(algorythm, 'nop'); + } +}); \ No newline at end of file