This is an encryption program. I need the encrypt and decrypt functions modified
ID: 3535768 • Letter: T
Question
This is an encryption program. I need the encrypt and decrypt functions modified to look different but still do the same job. The basic idea is you are taking an input array of chars, combining it with a key and then mixing it up as you see it. Just needa different way to jumble it up i guess.
#include <iostream>
using namespace std;
#define BLOCK_SIZE 16
// Initialize key array, same size as data array
// The key is just an arbitary collection of bytes, it can be anything as long as they same key's used for encryption/decryption
const char key[] = "a@SDF23hds234u(D";
// Combines data bytes with key bytes then uses arbitary algorithm to jumble the data
void encrypt(char data[]) {
// Add the value of every index in the key to every index in the data array
for (int i = 0; i < BLOCK_SIZE; i++) {
data[i] = data[i] + key[i];
}
// Shift every member in the array left by 1
// So 0123456789012345 -> 1234567890123450
char first = data[0];
for (int i = 0; i < BLOCK_SIZE - 1; i++) {
data[i] = data[i + 1];
}
data[BLOCK_SIZE - 1] = first;
}
// Uses reverse of encryption algorithm to un-jumble data then seperates data bytes from key bytes
void decrypt(char data[]) {
// Shift every member in the array right by 1
// So 1234567890123450 -> 0123456789012345
char last = data[BLOCK_SIZE - 1];
for (int i = BLOCK_SIZE - 1; i >= 0; i--) {
data[i] = data[i - 1];
}
data[0] = last;
// Subtract the values of they key from the values of the data array
for (int i = 0; i < BLOCK_SIZE; i++) {
data[i] = data[i] - key[i];
}
}
int main() {
// Initialize data array
char data[] = "0123456789012345";
cout << "Encyption" << endl << endl << "[Data In]" << endl;
cout << data;
cout << endl << endl;
encrypt(data);
cout << "[Data Out]" << endl;
cout << data;
cout << endl << endl << endl;
cout << "Decryption" << endl << endl << "[Data In]" << endl;
cout << data;
cout << endl << endl;
decrypt(data);
cout << "[Data Out]" << endl;
cout << data;
cin.get();
return 0;
}
Explanation / Answer
#include #include #include #include #include using namespace std; char getmenuselection (char m) { cout > m; switch (m) { case 'e': case 'E': coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.