From 046a645d36410b0fd1ab618134cab04bcaa36e07 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 17 Feb 2019 21:13:18 +0100 Subject: [PATCH 1/4] WiP --- app/zadanie01.js | 20 +++++++++++++++++++- app/zadanieDnia1.js | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/app/zadanie01.js b/app/zadanie01.js index 842f75e..a62509b 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1,3 +1,21 @@ const MY_PWD_HASH = '5dca0fc4e306d92b2077ad85e7c4bd87a3e8648e'; -//Twój kod \ No newline at end of file +//Twój kod +const passes = ['??TegoHasła', +'CodersLab', +'Node.js Szyfruje Pliki', +'Zaźółć Gęślą Jaźń', +'Moje Haslo 1@3!', +'111#$((@)n', +'Dzisiaj Szyfruje 83' +] +const algorithmTypes = ['sha256', 'sha512', 'md5', 'rmd160']; +const crypto = require('crypto'); + + +const hash = crypto.createHmac(algorithmTypes[3], passes[4]) + .digest('hex'); +console.log(MY_PWD_HASH.length) +console.log(hash) +console.log('hash length: ', hash.length) +console.log(hash === MY_PWD_HASH); \ No newline at end of file diff --git a/app/zadanieDnia1.js b/app/zadanieDnia1.js index 8c20173..811c2cc 100644 --- a/app/zadanieDnia1.js +++ b/app/zadanieDnia1.js @@ -1 +1,32 @@ -//Twój kod \ No newline at end of file +//Twój kod +const fs = require('fs'); +const crypto = require('crypto'); + +const arr = process.argv[2]; +console.log('argument to: ',arr); +// var text = ''; +fs.readFile(arr, 'utf8', (err, data) => { + if (err === null) { + console.log('Poprawnie odczytano plik :', data); + // const paresData = JSON.parse(data); + + console.log('type to: ' ,typeof data) + + const text = data; + + // console.log('type is: ', typeof paresData) + const hash = crypto.createHmac('sha256', text) + .digest('hex'); + console.log('PASS IS: ', hash); + + + + + + + } else { + console.log('Błąd podczas odczytu pliku!', err); + } +}); + +// \ No newline at end of file From bc79103f3daeec70eb4c4ed6e28cdc37c3175ed6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 18 Feb 2019 11:28:05 +0100 Subject: [PATCH 2/4] zadanie01Complete --- app/zadanie01.js | 14 ++++++++------ app/zadanieDnia1.js | 1 - 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/zadanie01.js b/app/zadanie01.js index a62509b..2cd4b88 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -12,10 +12,12 @@ const passes = ['??TegoHasła', const algorithmTypes = ['sha256', 'sha512', 'md5', 'rmd160']; const crypto = require('crypto'); +// console.log(MY_PWD_HASH.length) -const hash = crypto.createHmac(algorithmTypes[3], passes[4]) - .digest('hex'); -console.log(MY_PWD_HASH.length) -console.log(hash) -console.log('hash length: ', hash.length) -console.log(hash === MY_PWD_HASH); \ No newline at end of file + passes.filter( (pass) => { + algorithmTypes.filter((algo) => { + const hash = crypto.createHmac(algo, pass).digest('hex') + MY_PWD_HASH === hash ? console.log(`algorytm to: ${algo}, +hasło to: ${pass}`) : null + }) + }) \ No newline at end of file diff --git a/app/zadanieDnia1.js b/app/zadanieDnia1.js index 811c2cc..3cec69f 100644 --- a/app/zadanieDnia1.js +++ b/app/zadanieDnia1.js @@ -29,4 +29,3 @@ fs.readFile(arr, 'utf8', (err, data) => { } }); -// \ No newline at end of file From b8fdaa1582909a906becbc59ec95e1b94638c7cf Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 18 Feb 2019 14:52:46 +0100 Subject: [PATCH 3/4] problem with zadanieDnia2 --- app/zadanieDnia2.js | 85 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/app/zadanieDnia2.js b/app/zadanieDnia2.js index 85846f4..4b736d5 100644 --- a/app/zadanieDnia2.js +++ b/app/zadanieDnia2.js @@ -1,3 +1,86 @@ const ENCRYPTED_TEXT = '4f9fa8f98650091c4910f5b597773c0a48278cfb001fe4eb3ff47ada85cbf0ed3dc17016b031e1459e6e4d9b001ab6e102c11e834a98dce9530c9668c47b76ee6f09d075d19a38e48b415e067c6ddcfad0d3526c405a4f4f2fb1e7502f303c40'; -//Twój kod \ No newline at end of file +//Twój kod + +console.log(ENCRYPTED_TEXT.length) + + +const text = 'Pobawmy się jak komputerowy Detektyw' +const result = [] +text.split(" ").forEach( el => result.push(el[0] + el[el.length-1]) ) +const pass = result.join('') + +// console.log(pass) + +// decipher: + +const crypto = require('crypto'); +const algorithms = ['aes192', 'aes-256-cbc', 'aes-256-ecb']; + + + + + + +var dd = ''; +for(let i=0; i { +// if (typeof decodeText(ENCRYPTED_TEXT, password, el) === "string"){ +// console.log(decodeText(ENCRYPTED_TEXT, password, el)) + +// }else{ +// null +// } +// }) + +// console.log(typeof decodeText(ENCRYPTED_TEXT, password, algorithms[1])) + +// if (typeof decodeText(ENCRYPTED_TEXT, password, algorithms[1]) == "string"){ +// console.log('dziala') +// }else{ +// console.log('nie dziala') +// } +// var tekscik = '' +// algorithms.filter(el => { +// typeof decodeText(ENCRYPTED_TEXT, password, el) === "string" +// tekscik += decodeText(ENCRYPTED_TEXT, password, el) +// }) +// console.log(tekscik); \ No newline at end of file From 1b0560427ae697084481aad186cde1d44ce1cab0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 19 Feb 2019 01:33:09 +0100 Subject: [PATCH 4/4] zadanieDnia2 completed --- app/zadanieDnia2.js | 77 +++++++++------------------------------------ 1 file changed, 15 insertions(+), 62 deletions(-) diff --git a/app/zadanieDnia2.js b/app/zadanieDnia2.js index 4b736d5..b24d663 100644 --- a/app/zadanieDnia2.js +++ b/app/zadanieDnia2.js @@ -2,7 +2,7 @@ const ENCRYPTED_TEXT = '4f9fa8f98650091c4910f5b597773c0a48278cfb001fe4eb3ff47ada //Twój kod -console.log(ENCRYPTED_TEXT.length) +// console.log(ENCRYPTED_TEXT.length) const text = 'Pobawmy się jak komputerowy Detektyw' @@ -11,6 +11,7 @@ text.split(" ").forEach( el => result.push(el[0] + el[el.length-1]) ) const pass = result.join('') // console.log(pass) +// console.log('result: ',typeof result) // decipher: @@ -19,68 +20,20 @@ const algorithms = ['aes192', 'aes-256-cbc', 'aes-256-ecb']; +function decodeText(encodedText, password, algorithm) { + const decipher = crypto.createDecipher(algorithm, password); - - -var dd = ''; -for(let i=0; i { -// if (typeof decodeText(ENCRYPTED_TEXT, password, el) === "string"){ -// console.log(decodeText(ENCRYPTED_TEXT, password, el)) - -// }else{ -// null -// } -// }) - -// console.log(typeof decodeText(ENCRYPTED_TEXT, password, algorithms[1])) - -// if (typeof decodeText(ENCRYPTED_TEXT, password, algorithms[1]) == "string"){ -// console.log('dziala') -// }else{ -// console.log('nie dziala') -// } -// var tekscik = '' -// algorithms.filter(el => { -// typeof decodeText(ENCRYPTED_TEXT, password, el) === "string" -// tekscik += decodeText(ENCRYPTED_TEXT, password, el) -// }) -// console.log(tekscik); \ No newline at end of file +algorithms.forEach(el => { + try{ + console.log(decodeText(ENCRYPTED_TEXT, pass, el)) + } + catch(err){ + // console.log('blad: ') + } +})