#include<openssl/md5.h>
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
char *md51;
char* md52;
char* temp;
void getMD5(char* output,char* fileName);
int main() {
    md51 = (char *)malloc(sizeof(char)*128);
    md52 = (char *)malloc(sizeof(char)*128);
    temp = (char *)malloc(sizeof(char)*128);
    getMD5(md51,"doc1.txt");
    getMD5(md52,"doc2.txt");
    int i;
    while(strncmp(md51,md52,5)) {
        i++;
        system("sed -i -e 's/^/ /' -e 's/$/ /' doc2.txt");
        if(rand()%2)
        system("sed -i -e's/^ //' doc2.txt");
        getMD5(md52,"doc2.txt");
    }
    return 0;
}

void getMD5(char* output,char* fileName) {
    FILE *fp,*outputfile;
    char var[1024];
    char* cmd = (char *)malloc(sizeof(char)*100);
    sprintf(cmd,"openssl dgst -md5 %s",fileName);
    fp = popen(cmd, "r");
    while (fgets(var, sizeof(var), fp) != NULL) 
    {  
        printf("%s",var);
    }
    pclose(fp);
    free(cmd);
    strtok(var,"=");
    strcpy(output,strtok(NULL,"="));
}