#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;
}