Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone change this C++ code to C sharp, python, or matlab plz #include #include #include using namespace std; #define DIR_ENCRYPT 0 #define DIR_DECRYPT 1

Can someone change this C++ code to C sharp, python, or matlab plz

#include #include #include using namespace std;

#define DIR_ENCRYPT 0 #define DIR_DECRYPT 1 #define BLK_SIZE 512

void keyScheduler(unsigned short key, unsigned char * K) { // left nibble xor middle nibble K[3] = ((key >> 8) & 0xf) ^ ((key >> 4) & 0xf);

// middle nibble xor right nibble K[4] = ((key >> 4) & 0xf) ^ (key & 0xf);

// right nibble xor left nibble K[5] = (key & 0xf) ^ ((key >> 8) & 0xf); }

unsigned char cryptByte(unsigned char inputByte, unsigned char * K, int direction) { unsigned char L = inputByte >> 4; unsigned char R = inputByte & 0xf; unsigned char nextL; for (int i = 0; i < 3; i++) { nextL = R; R = K[direction == DIR_ENCRYPT ? i : (2-i)] ^ R ^ L; L = nextL; }

return (R << 4) | L; }

void RDES(char *input, char *output, int blkSize, unsigned char * K, int direction) { for (int i = 0; i < blkSize; i++) { output[i] = cryptByte(input[i], K, direction); } }

void print_bytes(std::ostream& out, const char *title, const unsigned char *data, size_t dataLen, bool format = true) { out << title << std::endl; out << std::setfill('0'); for (size_t i = 0; i < dataLen; ++i) { out << std::hex << std::setw(2) << (int)data[i]; if (format) { out << (((i + 1) % 32 == 0) ? " " : " "); } } out << std::endl; } int main() { unsigned char K[3]{ 0 }; char plainText[BLK_SIZE]{ 0 }; char encrypted[BLK_SIZE]{ 0 }; char decrypted[BLK_SIZE]{ 0 };

keyScheduler(0xabc, K);

sprintf(plainText, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");

cout << "Plain Text Input:" << endl; cout << plainText << endl << endl;

RDES(plainText, encrypted, BLK_SIZE, K, DIR_ENCRYPT); print_bytes(cout, "Encrypted Block:", (const unsigned char *)encrypted, BLK_SIZE);

RDES(encrypted, decrypted, BLK_SIZE, K, DIR_DECRYPT); cout << "Decrypted Output:" << endl; cout << decrypted << endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions

Question

What are the attributes of a technical decision?

Answered: 1 week ago

Question

How do the two components of this theory work together?

Answered: 1 week ago