Commit 690b97fa authored by Håkon Harnes's avatar Håkon Harnes

code cleanup

parent 63abed30
......@@ -7,6 +7,10 @@
#include <sstream>
#include <fstream>
/*
* Class used for decrypting passwords that
* are encrypted with OpenSSL's PBKDF2
*/
class Decryptor {
const std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
......@@ -37,25 +41,33 @@ public:
}
private:
// Recursive function to calculate hash (equivalent to n nested for loops)
std::string calcHash(int n, std::string password) {
for (char c : alphabet) {
std::string tmp = password + c;
// Outer loops add characters and pass it on to the inner loops
if (n > 1) {
std::string decryption = calcHash(n - 1, tmp);
if (decryption != "")
return decryption;
} else {
}
// The inner loop does the hashing
else {
std::string hash = PBKDF2(tmp, salt, iterations, keyLen);
std::cout << hash << " - " << tmp << std::endl;
// Returns password if hashes match
if (hash == key) {
return tmp;
}
}
}
// Returns an empty string if password was not found
return "";
}
......
22 serialization::archive 17 0 0 0 0 54 /Users/hakon/programming/security/Assignment 08/Task a 60 /Users/hakon/programming/security/Assignment 08/Task a/build 0 0 106 0 0 0 1 # 1 1 1 2 18446744073709551615 7 include 1 2 1 9 18446744073709551615 15 "Decryptor.hpp" 1 10 1 25 18446744073709551615 3 std 3 1 3 4 0 2 :: 3 4 3 6 1 6 string 3 6 3 12 2 15 decryptPassword 3 13 3 28 1 1 ( 3 28 3 29 1 3 int 3 29 3 32 18446744073709551615 1 n 3 33 3 34 3 1 , 3 34 3 35 1 3 std 3 36 3 39 0 2 :: 3 39 3 41 18446744073709551615 6 string 3 41 3 47 2 8 password 3 48 3 56 4 1 ) 3 56 3 57 1 1 ; 3 57 3 58 18446744073709551615 3 int 5 1 5 4 18446744073709551615 4 main 5 5 5 9 5 1 ( 5 9 5 10 5 1 ) 5 10 5 11 5 1 { 5 12 5 13 18446744073709551615 5 const 6 3 6 8 18446744073709551615 3 std 6 9 6 12 0 2 :: 6 12 6 14 18446744073709551615 6 string 6 14 6 20 2 3 key 6 21 6 24 6 1 = 6 25 6 26 18446744073709551615 42 "ab29d7b5c589e18b52261ecba1d3a7e7cbf212c6" 6 27 6 69 18446744073709551615 1 ; 6 69 6 70 18446744073709551615 5 const 7 3 7 8 18446744073709551615 3 std 7 9 7 12 0 2 :: 7 12 7 14 18446744073709551615 6 string 7 14 7 20 2 4 salt 7 21 7 25 7 1 = 7 26 7 27 18446744073709551615 16 "Saltet til Ola" 7 28 7 44 18446744073709551615 1 ; 7 44 7 45 18446744073709551615 5 const 9 3 9 8 18446744073709551615 3 int 9 9 9 12 18446744073709551615 10 iterations 9 13 9 23 8 1 = 9 24 9 25 18446744073709551615 4 2048 9 26 9 30 18446744073709551615 1 ; 9 30 9 31 18446744073709551615 5 const 10 3 10 8 18446744073709551615 3 int 10 9 10 12 18446744073709551615 6 maxLen 10 13 10 19 9 1 = 10 20 10 21 18446744073709551615 2 10 10 22 10 24 18446744073709551615 1 ; 10 24 10 25 18446744073709551615 9 Decryptor 12 3 12 12 10 9 decryptor 12 13 12 22 11 1 ( 12 22 12 23 10 3 key 12 23 12 26 6 1 , 12 26 12 27 10 4 salt 12 28 12 32 7 1 , 12 32 12 33 10 10 iterations 12 34 12 44 8 1 , 12 44 12 45 10 6 maxLen 12 46 12 52 9 1 ) 12 52 12 53 10 1 ; 12 53 12 54 18446744073709551615 3 std 13 3 13 6 0 2 :: 13 6 13 8 18446744073709551615 6 string 13 8 13 14 2 8 password 13 15 13 23 12 1 = 13 24 13 25 18446744073709551615 9 decryptor 13 26 13 35 11 1 . 13 35 13 36 13 15 decryptPassword 13 36 13 51 13 1 ( 13 51 13 52 13 1 ) 13 52 13 53 13 1 ; 13 53 13 54 18446744073709551615 2 if 15 3 15 5 18446744073709551615 1 ( 15 6 15 7 18446744073709551615 8 password 15 7 15 15 12 2 != 15 16 15 18 14 2 "" 15 19 15 21 18446744073709551615 1 ) 15 21 15 22 18446744073709551615 3 std 16 5 16 8 0 2 :: 16 8 16 10 18446744073709551615 4 cout 16 10 16 14 15 2 << 16 15 16 17 16 20 "\nPASSWORD FOUND: " 16 18 16 38 18446744073709551615 2 << 16 39 16 41 16 8 password 16 42 16 50 12 2 << 16 51 16 53 16 4 "\n" 16 54 16 58 18446744073709551615 2 << 17 15 17 17 17 3 std 17 18 17 21 0 2 :: 17 21 17 23 18 4 endl 17 23 17 27 18 1 ; 17 27 17 28 18446744073709551615 4 else 18 3 18 7 18446744073709551615 3 std 19 5 19 8 0 2 :: 19 8 19 10 18446744073709551615 4 cout 19 10 19 14 15 2 << 19 15 19 17 16 33 "\nUNABLE TO DECRYPT PASSWORD!\n" 19 18 19 51 18446744073709551615 2 << 20 15 20 17 17 3 std 20 18 20 21 0 2 :: 20 21 20 23 18 4 endl 20 23 20 27 18 1 ; 20 27 20 28 18446744073709551615 220 /*
22 serialization::archive 17 0 0 0 0 54 /Users/hakon/programming/security/Assignment 08/Task a 60 /Users/hakon/programming/security/Assignment 08/Task a/build 0 0 95 0 0 0 1 # 1 1 1 2 18446744073709551615 7 include 1 2 1 9 18446744073709551615 15 "Decryptor.hpp" 1 10 1 25 18446744073709551615 3 int 3 1 3 4 18446744073709551615 4 main 3 5 3 9 0 1 ( 3 9 3 10 0 1 ) 3 10 3 11 0 1 { 3 12 3 13 18446744073709551615 33 // Variables used for decrypting 5 3 5 36 18446744073709551615 5 const 6 3 6 8 18446744073709551615 3 std 6 9 6 12 1 2 :: 6 12 6 14 18446744073709551615 6 string 6 14 6 20 2 3 key 6 21 6 24 3 1 = 6 25 6 26 18446744073709551615 42 "ab29d7b5c589e18b52261ecba1d3a7e7cbf212c6" 6 27 6 69 18446744073709551615 1 ; 6 69 6 70 18446744073709551615 5 const 7 3 7 8 18446744073709551615 3 std 7 9 7 12 1 2 :: 7 12 7 14 18446744073709551615 6 string 7 14 7 20 2 4 salt 7 21 7 25 4 1 = 7 26 7 27 18446744073709551615 16 "Saltet til Ola" 7 28 7 44 18446744073709551615 1 ; 7 44 7 45 18446744073709551615 5 const 8 3 8 8 18446744073709551615 3 int 8 9 8 12 18446744073709551615 10 iterations 8 13 8 23 5 1 = 8 24 8 25 18446744073709551615 4 2048 8 26 8 30 18446744073709551615 1 ; 8 30 8 31 18446744073709551615 5 const 9 3 9 8 18446744073709551615 3 int 9 9 9 12 18446744073709551615 6 maxLen 9 13 9 19 6 1 = 9 20 9 21 18446744073709551615 2 10 9 22 9 24 18446744073709551615 1 ; 9 24 9 25 18446744073709551615 25 // Initializes decryptor 11 3 11 28 18446744073709551615 9 Decryptor 12 3 12 12 7 9 decryptor 12 13 12 22 8 1 ( 12 22 12 23 7 3 key 12 23 12 26 3 1 , 12 26 12 27 7 4 salt 12 28 12 32 4 1 , 12 32 12 33 7 10 iterations 12 34 12 44 5 1 , 12 44 12 45 7 6 maxLen 12 46 12 52 6 1 ) 12 52 12 53 7 1 ; 12 53 12 54 18446744073709551615 3 std 13 3 13 6 1 2 :: 13 6 13 8 18446744073709551615 6 string 13 8 13 14 2 8 password 13 15 13 23 9 1 = 13 24 13 25 18446744073709551615 9 decryptor 13 26 13 35 8 1 . 13 35 13 36 10 15 decryptPassword 13 36 13 51 10 1 ( 13 51 13 52 10 1 ) 13 52 13 53 10 1 ; 13 53 13 54 18446744073709551615 39 // Prints the result of the decryption 15 3 15 42 18446744073709551615 2 if 16 3 16 5 18446744073709551615 1 ( 16 6 16 7 18446744073709551615 8 password 16 7 16 15 9 2 != 16 16 16 18 11 2 "" 16 19 16 21 18446744073709551615 1 ) 16 21 16 22 18446744073709551615 3 std 17 5 17 8 1 2 :: 17 8 17 10 18446744073709551615 4 cout 17 10 17 14 12 2 << 17 15 17 17 13 20 "\nPASSWORD FOUND: " 17 18 17 38 18446744073709551615 2 << 17 39 17 41 13 8 password 17 42 17 50 9 2 << 17 51 17 53 13 4 "\n" 17 54 17 58 18446744073709551615 2 << 18 15 18 17 14 3 std 18 18 18 21 1 2 :: 18 21 18 23 15 4 endl 18 23 18 27 15 1 ; 18 27 18 28 18446744073709551615 4 else 19 3 19 7 18446744073709551615 3 std 20 5 20 8 1 2 :: 20 8 20 10 18446744073709551615 4 cout 20 10 20 14 12 2 << 20 15 20 17 13 33 "\nUNABLE TO DECRYPT PASSWORD!\n" 20 18 20 51 18446744073709551615 2 << 21 15 21 17 14 3 std 21 18 21 21 1 2 :: 21 21 21 23 15 4 endl 21 23 21 27 15 1 ; 21 27 21 28 18446744073709551615 220 /*
-- OUTPUT --
146a0ad2711640cb8cb2e40b1c27435c2e8ba3c3 - QwC
975f6b1a139b3be77ca83be02ce2946beb877be4 - QwD
......@@ -6,4 +6,4 @@
PASSWORD FOUND: QwE
*/ 22 3 30 6 18446744073709551615 1 } 31 1 31 2 18446744073709551615 0 0 19 0 0 0 22 0 0 1 2 0 3 std 8 1 2 0 15 decryptPassword 20 1 2 0 14 string:__1:std 10 1 2 0 68 3:33:/Users/hakon/programming/security/Assignment 08/Task a/main.cpp 10 1 2 0 68 3:48:/Users/hakon/programming/security/Assignment 08/Task a/main.cpp 8 1 2 0 4 main 9 1 2 0 68 6:21:/Users/hakon/programming/security/Assignment 08/Task a/main.cpp 9 1 2 0 68 7:21:/Users/hakon/programming/security/Assignment 08/Task a/main.cpp 9 1 2 0 68 9:13:/Users/hakon/programming/security/Assignment 08/Task a/main.cpp 9 1 2 0 69 10:13:/Users/hakon/programming/security/Assignment 08/Task a/main.cpp 4 1 2 0 9 Decryptor 9 1 2 0 69 12:13:/Users/hakon/programming/security/Assignment 08/Task a/main.cpp 9 1 2 0 69 13:15:/Users/hakon/programming/security/Assignment 08/Task a/main.cpp 21 1 2 0 25 decryptPassword:Decryptor 8 1 2 0 18 operator!=:__1:std 9 1 2 0 12 cout:__1:std 8 1 2 0 16 operator:__1:std 21 1 2 0 30 operator:basic_ostream:__1:std 8 1 2 0 12 endl:__1:std 0 0 2 0 0 0 68 /Users/hakon/programming/security/Assignment 08/Task a/Decryptor.hpp 1600414591 63 /Users/hakon/programming/security/Assignment 08/Task a/main.cpp 1600414633
\ No newline at end of file
*/ 23 3 31 6 18446744073709551615 1 } 32 1 32 2 18446744073709551615 0 0 16 0 0 0 8 0 0 1 2 0 4 main 22 1 2 0 3 std 20 1 2 0 14 string:__1:std 9 1 2 0 68 6:21:/Users/hakon/programming/security/Assignment 08/Task a/main.cpp 9 1 2 0 68 7:21:/Users/hakon/programming/security/Assignment 08/Task a/main.cpp 9 1 2 0 68 8:13:/Users/hakon/programming/security/Assignment 08/Task a/main.cpp 9 1 2 0 68 9:13:/Users/hakon/programming/security/Assignment 08/Task a/main.cpp 4 1 2 0 9 Decryptor 9 1 2 0 69 12:13:/Users/hakon/programming/security/Assignment 08/Task a/main.cpp 9 1 2 0 69 13:15:/Users/hakon/programming/security/Assignment 08/Task a/main.cpp 21 1 2 0 25 decryptPassword:Decryptor 8 1 2 0 18 operator!=:__1:std 9 1 2 0 12 cout:__1:std 8 1 2 0 16 operator:__1:std 21 1 2 0 30 operator:basic_ostream:__1:std 8 1 2 0 12 endl:__1:std 0 0 2 0 0 0 68 /Users/hakon/programming/security/Assignment 08/Task a/Decryptor.hpp 1600420529 63 /Users/hakon/programming/security/Assignment 08/Task a/main.cpp 1600420265
\ No newline at end of file
#include "Decryptor.hpp"
std::string decryptPassword(int n, std::string password);
int main() {
// Variables used for decrypting
const std::string key = "ab29d7b5c589e18b52261ecba1d3a7e7cbf212c6";
const std::string salt = "Saltet til Ola";
const int iterations = 2048;
const int maxLen = 10;
// Initializes decryptor
Decryptor decryptor(key, salt, iterations, maxLen);
std::string password = decryptor.decryptPassword();
// Prints the result of the decryption
if (password != "")
std::cout << "\nPASSWORD FOUND: " << password << "\n"
<< std::endl;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment