What's new

C & C++ Data Encryption standard help

ZyxGremory

Forum Veteran
Elite
Joined
Aug 30, 2018
Posts
1,252
Solutions
7
Reaction
923
Points
548
mga lods help naman, need ng code sa C na nagiimplement ng DES
 
#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;
}
 

Similar threads

Back
Top