diff --git a/app/zadanie01.js b/app/zadanie01.js index 842f75e..2947963 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1,3 +1,14 @@ +const crypto = require('crypto'); const MY_PWD_HASH = '5dca0fc4e306d92b2077ad85e7c4bd87a3e8648e'; +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']; -//Twój kod \ No newline at end of file +passwords.forEach(pass => { + algorithms.forEach(code =>{ + const cryptoPass = crypto.createHmac(code, pass).digest('hex'); + if(cryptoPass === MY_PWD_HASH){ + console.log('Hasło to: ' + pass); + console.log('Algorytm to: ' + code); + } + }) +}); diff --git a/app/zadanieDnia1.js b/app/zadanieDnia1.js index 8c20173..a20795c 100644 --- a/app/zadanieDnia1.js +++ b/app/zadanieDnia1.js @@ -1 +1,11 @@ -//Twój kod \ No newline at end of file +const crypto = require('crypto'); +const fs = require('fs'); +process.argv.forEach((data, index) => { + if(index>1){ + fs.readFile(data,'utf8', (err, data) =>{ + if(err===null){ + console.log(crypto.createHmac('sha256', data).digest('hex')); + } else{console.log('Wystąpił błąd odczytu pliku!',err);} + }) + } +}) diff --git a/app/zadanieDnia2.js b/app/zadanieDnia2.js index 85846f4..5bc404c 100644 --- a/app/zadanieDnia2.js +++ b/app/zadanieDnia2.js @@ -1,3 +1,18 @@ const ENCRYPTED_TEXT = '4f9fa8f98650091c4910f5b597773c0a48278cfb001fe4eb3ff47ada85cbf0ed3dc17016b031e1459e6e4d9b001ab6e102c11e834a98dce9530c9668c47b76ee6f09d075d19a38e48b415e067c6ddcfad0d3526c405a4f4f2fb1e7502f303c40'; - -//Twój kod \ No newline at end of file +const crypto = require('crypto'); +let pass = []; +const text = 'Pobawmy się jak komputerowy Detektyw'.split(' ').forEach(word =>{ + pass.push(word[0] + word[word.length-1]); +}); +pass = pass.join(""); +const algorithms = ['aes192', 'aes-256-cbc', 'aes-256-ecb']; +algorithms.forEach(algorithm =>{ + const decipher = crypto.createDecipher(algorithm, pass); + let decrypted = decipher.update(ENCRYPTED_TEXT, 'hex', 'utf8'); + try{ + decrypted += decipher.final('utf8'); + console.log(decrypted); + } catch(e){ + console.log('Nope, not this one!') + } +})