Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <openssl/evp.h>
  5.  
  6. int main (void) {
  7.  
  8. EVP_CIPHER_CTX *ctx; //creates a new cipher context
  9. char plaintext[] = "This is a top secret.";
  10. 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";
  11. unsigned char iv[16] = "\x0";
  12. unsigned char outbuf[1024];
  13. int outlen, tmplen;
  14.  
  15.  
  16. //Import dictionary list
  17. FILE *dictionary;
  18. char line[20];
  19. size_t len = 0;
  20. ssize_t read;
  21. dictionary = fopen("words.txt", "r");
  22.  
  23. if(dictionary == NULL)
  24. {
  25. printf("Error reading dictionary file!");
  26. exit(1);
  27. }
  28.  
  29. //sets up cipher context
  30.  
  31. while(fgets(line, 20, dictionary) != NULL)
  32. {
  33. ctx = EVP_CIPHER_CTX_new();
  34.  
  35. while(strlen(line) < 16)
  36. {
  37. strtok(line, "\n");
  38. strcat(line, " ");
  39. }
  40. EVP_EncryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, line, iv);
  41.  
  42. if(!EVP_EncryptUpdate(ctx, outbuf, &outlen, plaintext, strlen(plaintext)))
  43. {
  44. printf("Encrypt Update Error");
  45. exit(1);
  46. }
  47. /* Buffer passed to EVP_EncryptFinal() must be after data just
  48. * encrypted to avoid overwriting it.
  49. */
  50. if(!EVP_EncryptFinal_ex(ctx, outbuf + outlen, &tmplen))
  51. {
  52. printf("Encrypt Final Error");
  53. exit(1);
  54. }
  55. outlen += tmplen;
  56.  
  57. EVP_CIPHER_CTX_free(ctx);
  58.  
  59. //compare cipertexts
  60. if(memcmp(outbuf, ciphertext, outlen) == 0)
  61. {
  62. printf("%s", line);
  63. }
  64. }
  65.  
  66. //Close dictionary file
  67. fclose(dictionary);
  68.  
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement