Question: I am writing an application to do a brute force attack an AES ECB mode. The criteria it to write a function that can get

I am writing an application to do a brute force attack an AES ECB mode. The criteria it to write a function that can get all pemutations of length 4 from the english character set. It is only getting 4 digits since the rest of the string is already predetermined to save time.

The string that is calculated from the permutation needs to get merged with the remaining 12 characters and then get passed into the following function

#include "cryptopp/cryptlib.h"

#include "cryptopp/hex.h"

#include "cryptopp/filters.h"

#include "cryptopp/des.h"

#include "cryptopp/aes.h"

#include "cryptopp/modes.h"

using namespace CryptoPP;

string plain;

try{

ECB_Mode< AES >::Decryption dec;

dec.SetKey(key, AES::DEFAULT_KEYLENGTH);

StringSource s(cipher, true, new StreamTransformationFilter(dec, new StringSink(plain)));

}

catch(const CryptoPP::Exception& e){

}

return plain;

}

So far I have tryed the following code to get the permutations. It worked great in visual studio but fails to run on ubuntu.

include "stdafx.h"

#include

#include

#include

using namespace std;

void print_str(const char*, std::string, const int, const int);

int main()

{

int length = 4;

char str[] = { 'A', 'B', 'C' , 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; // , '!', '@', '#', '$', '%', '^', '&', '*', ' ', '(', ')', '-', '_', '+', '=', ',', '.', '?', '/', ';', ':', '"'

//};

int n = sizeof str;

print_str(str, "", n, length);

return 0;

}

void print_str(const char str[], std::string prefix, const int n, const int length)

{

if (length == 1)

{

for (int j = 0; j < n; j++)

std::cout << prefix + str[j] << std::endl;

// remove the line above and place code to call the decrypt function here

}

else

{

for (int i = 0; i < n; i++)

print_str(str, prefix + str[i], n, length - 1);

}

}

///////////////////////////////////////////////////////////////////////////////////////////

So I have tryed to come up with another way to create the permutations. However this is very innefficient as it creates every possible permutation of any length that can be made from the string and only displays the ones that are 4 characcters on screen.

#include

#include

using namespace std;

void get(string str, string res)

{

if (res.size() == 4)

cout << res << endl;

for (int i = 0; i < str.length(); i++)

get(string(str).erase(i, 1), res + str[i]);

}

int main(int argc, char **argv)

{

string str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()-_=+[{]}\;:',<.>/?";

//string str = "abc .'";

get(str,"")

return 0;

}

How can I efficiently create the permuations on ubuntu so that I can use the permutation to call the decrypt function to decypt a file on the machine encryptedtext.txt?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!