Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <openssl/evp.h>
- int main (void) {
- EVP_CIPHER_CTX *ctx; //creates a new cipher context
- char plaintext[] = "This is a top secret.";
- unsigned char ciphertext[] = "\x8d\x20\xe5\x05\x6a\x8d\x24\xd0\x46\x2c\xe7\x4e\x49\x04\xc1\xb5\x13\xe1\x0d\x1d\xf4\xa2\xef\x2a\xd4\x54\x0f\xae\x1c\xa0\xaa\xf9";
- unsigned char iv[16] = "\x0";
- unsigned char outbuf[1024];
- int outlen, tmplen;
- //Import dictionary list
- FILE *dictionary;
- char line[20];
- size_t len = 0;
- ssize_t read;
- dictionary = fopen("words.txt", "r");
- if(dictionary == NULL)
- {
- printf("Error reading dictionary file!");
- exit(1);
- }
- //sets up cipher context
- while(fgets(line, 20, dictionary) != NULL)
- {
- ctx = EVP_CIPHER_CTX_new();
- while(strlen(line) < 16)
- {
- strtok(line, "\n");
- strcat(line, " ");
- }
- EVP_EncryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, line, iv);
- if(!EVP_EncryptUpdate(ctx, outbuf, &outlen, plaintext, strlen(plaintext)))
- {
- printf("Encrypt Update Error");
- exit(1);
- }
- /* Buffer passed to EVP_EncryptFinal() must be after data just
- * encrypted to avoid overwriting it.
- */
- if(!EVP_EncryptFinal_ex(ctx, outbuf + outlen, &tmplen))
- {
- printf("Encrypt Final Error");
- exit(1);
- }
- outlen += tmplen;
- EVP_CIPHER_CTX_free(ctx);
- //compare cipertexts
- if(memcmp(outbuf, ciphertext, outlen) == 0)
- {
- printf("%s", line);
- }
- }
- //Close dictionary file
- fclose(dictionary);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement