/** * Calculates number of hashes from stdin or from files * * Expected input ./gethash [-md5] [-c16] [-c32] [-xor] [-hex] [-f file] */ int main( int argc, char *argv[] ) { unsigned char hash = 0; FILE *file = stdin; parse_args(argc, argv, &hash, &file); unsigned int length; unsigned char *data = read_file(file, &length); printf("Length: %i bytes\n", length); if(hash & XOR){ printf("XOR: "); if(hash & HEX) printf("0x%02x\n", xor_compute(data, length)); else printf("%u\n", xor_compute(data, length)); } if(hash & C16){ printf("CRC-16: "); if(hash & HEX) printf("0x%04x\n", crc16_compute(data, length)); else printf("%u\n", crc16_compute(data, length)); } if(hash & C32){ printf("CRC-32: "); if(hash & HEX) printf("0x%08x\n", crc32_compute(data, length)); else printf("%u\n", crc32_compute(data, length)); } if(hash & MD5){ unsigned char result[16]; md5_compute(data, length, result); printf("MD5: "); for (int i = 0; i < 16; i++){ printf("%02x", result[i]); } printf("\n"); } free(data); fclose(file); return 0; }
uint8 xor_compare(uint8 *buff) { uint8 xor = xor_compute(buff); if (xor == buff[buff[0] - 1]) return 0x01; else return 0x00; }