⚙️ C & C++ Data Encryption standard help

#include <openssl/des.h>
#include <openssl/rand.h>
---------- encryption
void encryptDES(const unsigned char* plaintext, const unsigned char* key, unsigned char* ciphertext) {
DES_key_schedule schedule;
DES_set_key((const_DES_cblock*)key, &schedule);
DES_ecb_encrypt((const_DES_cblock*)plaintext, (DES_cblock*)ciphertext, &schedule, DES_ENCRYPT);
}

void decryptDES(const unsigned char* ciphertext, const unsigned char* key, unsigned char* plaintext) {
DES_key_schedule schedule;
DES_set_key((const_DES_cblock*)key, &schedule);
DES_ecb_encrypt((const_DES_cblock*)ciphertext, (DES_cblock*)plaintext, &schedule, DES_DECRYPT);
}
-------------end

int main() {
unsigned char plaintext[] = "Hello, World!";
unsigned char key[] = "12345678";
unsigned char ciphertext[16];
unsigned char decryptedtext[16];

encryptDES(plaintext, key, ciphertext);
decryptDES(ciphertext, key, decryptedtext);

printf("Ciphertext: %s\n", ciphertext);
printf("Decrypted text: %s\n", decryptedtext);

return 0;
}
 

About this Thread

  • 1
    Replies
  • 471
    Views
  • 2
    Participants
Last reply from:
Accenture

Trending Topics

Online now

Members online
1,091
Guests online
1,742
Total visitors
2,833

Forum statistics

Threads
2,268,530
Posts
28,922,558
Members
1,242,960
Latest member
kazpog93
Back
Top