Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. void encrypt(){
  2. //Opening files where text plain text is read and ciphertext stored
  3. fp=fopen("input.txt","rb");
  4. op=fopen("output.txt","wb");
  5. if (fp==NULL) {fputs ("File error",stderr); exit (1);}
  6. if (op==NULL) {fputs ("File error",stderr); exit (1);}
  7.  
  8. //Initializing the encryption KEY
  9. AES_set_encrypt_key(ckey, 128, &key);
  10.  
  11. //Encrypting Blocks of 16 bytes and writing the output.txt with ciphertext
  12. while (1) {
  13. init_ctr(&state, iv); //Counter call
  14. bytes_read = fread(indata, 1, AES_BLOCK_SIZE, fp);
  15. AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);
  16. bytes_written = fwrite(outdata, 1, bytes_read, op);
  17. if (bytes_read < AES_BLOCK_SIZE)
  18. break;
  19. }
  20.  
  21. fclose (fp);
  22. fclose (op);
  23. free (buffer);
  24. }
  25.  
  26. int main(int argc, char *argv[]){
  27. encrypt();
  28. //decrypt();
  29. system("PAUSE");
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement