From 0fece951d2a8335a22ded9fb0de45220b4a627f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Bu=C5=82ka?= Date: Wed, 31 Jan 2018 21:49:33 +0000 Subject: [PATCH] Day3 --- app/zadanie01.js | 17 ++++++++++++++++- app/zadanieDnia1.js | 17 ++++++++++++++++- app/zadanieDnia2.js | 18 +++++++++++++++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/app/zadanie01.js b/app/zadanie01.js index 842f75e..95afb5f 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1,3 +1,18 @@ const MY_PWD_HASH = '5dca0fc4e306d92b2077ad85e7c4bd87a3e8648e'; -//Twój kod \ No newline at end of file +const crypto = require('crypto'); + +const data = { + key: [ '??TegoHasła', 'CodersLab', 'Node.js Szyfruje Pliki', 'Zaźółć Gęślą Jaźń', 'Moje Haslo 1@3!', '111#$((@)n', 'Dzisiaj Szyfruje 83'], + algorithm: ['sha256', 'sha512', 'md5', 'rmd160'] +} + + +data.key.forEach(key => { + data.algorithm.forEach( algorithm => { + let hash = crypto.createHmac(algorithm, key).digest('hex'); + if (hash == MY_PWD_HASH){ + console.log('Uzyty klucz to: ' + key + ', a algorytm to: ' + algorithm + '.'); + } + }); +}); \ No newline at end of file diff --git a/app/zadanieDnia1.js b/app/zadanieDnia1.js index 8c20173..bf51f93 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'); + +const args = process.argv[2]; + +fs.readFile(args, 'utf8', (err, data) => { + if (err === null) { + console.log('Odczytalem plik ' + args + '.'); + let hash = crypto.createHmac('sha256', data).digest('hex'); + console.log('Suma kontrolna sha256 dla pliku ' + args + ' to: ' + hash + '.'); + } else { + console.log('Nie udalo sie odczytac pliku. );', err); + } +}); \ No newline at end of file diff --git a/app/zadanieDnia2.js b/app/zadanieDnia2.js index 85846f4..d6c0717 100644 --- a/app/zadanieDnia2.js +++ b/app/zadanieDnia2.js @@ -1,3 +1,19 @@ const ENCRYPTED_TEXT = '4f9fa8f98650091c4910f5b597773c0a48278cfb001fe4eb3ff47ada85cbf0ed3dc17016b031e1459e6e4d9b001ab6e102c11e834a98dce9530c9668c47b76ee6f09d075d19a38e48b415e067c6ddcfad0d3526c405a4f4f2fb1e7502f303c40'; -//Twój kod \ No newline at end of file +//Twój kod + +const data = { + algorithm: 'aes-256-ecb', + pswd: 'PysęjkkyDw', +} + +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, data.pswd, 'aes-256-ecb'));