diff --git a/app/zadanie01.js b/app/zadanie01.js index 842f75e..7c7fe5e 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1,3 +1,38 @@ +const crypto = require('crypto'); + const MY_PWD_HASH = '5dca0fc4e306d92b2077ad85e7c4bd87a3e8648e'; -//Twój kod \ No newline at end of file +const hashArr = ['sha256', 'sha512', 'md5' , 'rmd160']; + +const texts = ['??TegoHasła', +'CodersLab', +'Node.js Szyfruje Pliki', +'Zaźółć Gęślą Jaźń', +'Moje Haslo 1@3!', +'111#$((@)n', +'Dzisiaj Szyfruje 83'] + +let unscript = () => { + + let hashAlgoritm = ''; + let hash = ''; + + for(index in hashArr){ + hashAlgoritm = hashArr[index]; + + for(index in texts){ + + hash = crypto.createHmac(hashAlgoritm, texts[index]).digest('hex'); + + if(hash === MY_PWD_HASH){ + + console.log(`Answer: ${texts[index]}`); + } + + } + + } +} +unscript(); + + diff --git a/app/zadanieDnia1.js b/app/zadanieDnia1.js index 8c20173..68b9959 100644 --- a/app/zadanieDnia1.js +++ b/app/zadanieDnia1.js @@ -1 +1,34 @@ -//Twój kod \ No newline at end of file +const fs = require('fs'); +const crypto = require('crypto'); +const exerHash = '4f7ae6569b55cb6275423ca1cdf31475e607da1d5204c110a58fb480c96e6eca' + +let read = (filePath) => { + + return new Promise((resolve, reject) => { + + fs.readFile(filePath, 'utf-8', (err, data) => { + if (err === null){ + resolve(data) + } else { + throw err; + } + }); + }); +} + +let hashText = (text) => { + hash = crypto.createHmac('sha256', text).digest('hex'); + console.log(hash); +} + + +let filePath = ''; + +process.argv.forEach((val, index) => { + + if(index === 2){ + filePath = val; + read(filePath).then((data) => { hashText(data) } ); + }; + +}); \ No newline at end of file diff --git a/app/zadanieDnia2.js b/app/zadanieDnia2.js index 85846f4..a70b281 100644 --- a/app/zadanieDnia2.js +++ b/app/zadanieDnia2.js @@ -1,3 +1,41 @@ +const crypto = require('crypto'); + const ENCRYPTED_TEXT = '4f9fa8f98650091c4910f5b597773c0a48278cfb001fe4eb3ff47ada85cbf0ed3dc17016b031e1459e6e4d9b001ab6e102c11e834a98dce9530c9668c47b76ee6f09d075d19a38e48b415e067c6ddcfad0d3526c405a4f4f2fb1e7502f303c40'; -//Twój kod \ No newline at end of file +const text = 'Pobawmy się jak komputerowy Detektyw'; + +const algorithm = ['aes192', 'aes-256-cbc', 'aes-256-ecb']; + +const getPassword = (text) => { + let textArr = text.split(' '); + let pass = ''; + + for(index in textArr){ + let word = textArr[index]; + pass += word[0] + word[word.length - 1]; + } + return pass; +} + +let pass = getPassword(text); + +const decodeText = (encodedText, password, algorithm) => { + + for(index in algorithm){ + const decipher = crypto.createDecipher(algorithm[index], password); + let decrypted = decipher.update(encodedText, 'hex', 'utf8'); + + try { + decrypted += decipher.final('utf8'); + console.log(decrypted); + } catch (err) { + console.log(`Wystąpił błąd ${err.message}`); + } + + } + +} + +decodeText(ENCRYPTED_TEXT, pass, algorithm); + +