void encrypt() { printf("\nEnter filename of file to be encrypted: "); scanf("%s",&source_filename); source = fopen(source_filename, "r"); printf("Enter filename of file to store the encrypted data: "); scanf("%s",&destination_filename); destination = fopen(destination_filename, "w"); printf("Enter the keyword: "); scanf("%s",&keyword); n = strlen(keyword); while((data.character = fgetc(source)) != EOF) { key.character = keyword[i%n]; data.decimal = (int)data.character; key.decimal = (int)key.character; decimal_to_binary(); half_binary_to_decimal(0,4,8); decimal_to_hexadecimal(); half_binary_to_decimal(4,8,8); decimal_to_hexadecimal(); i++; } printf("Data was encrypted successfully..."); fclose(source); fclose(destination); }
///////////////////////Converts binary to hexadecimal char binary_to_hexadecimal(char *string){ int i,j,value=0,sum=0; //binary to decimal for(i=3,j=0;i>=0 && j<4;i--,j++) {value=(string[i]-48)*power(2,j); //printf("value is =>%d\n",value); sum=sum+value; } return decimal_to_hexadecimal(sum); //decimal to hexadecimal }