Question: 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

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!