int main(void) { unsigned long a, b, c, d; printf("\n.constants:\n"); a = get_remainder(CRC, 32, 128); b = get_remainder(CRC, 32, 96); c = get_remainder(CRC, 32, 64); d = get_remainder(CRC, 32, 32); print_four_remainders(a, 128, b, 96, c, 64, d, 32, ""); printf("\t/* Barrett constant m - (4^32)/n */\n"); print_quotient(get_quotient(CRC, 32, 64), 64, ""); printf("\t/* Barrett constant n */\n"); printf("\t.octa 0x%032lx\n", CRC_FULL); printf("\t.octa 0x0F0E0D0C0B0A09080706050403020100\t/* byte reverse permute constant */\n"); printf("\n.bit_reflected_constants:\n"); a = reflect(get_remainder(CRC, 32, 32), 32); b = reflect(get_remainder(CRC, 32, 64), 32); c = reflect(get_remainder(CRC, 32, 96), 32); d = reflect(get_remainder(CRC, 32, 128), 32); print_four_remainders(a, 32, b, 64, c, 96, d, 128, "`"); printf("\t/* 33 bit reflected Barrett constant m - (4^32)/n */\n"); print_quotient(reflect(get_quotient(CRC, 32, 64), 33), 64, "`"); printf("\t/* 33 bit reflected Barrett constant n */\n"); printf("\t.octa 0x%032lx\n", reflect(CRC_FULL, 33)); printf("\t/* byte reverse permute constant */\n"); printf("\t.octa 0x0F0E0D0C0B0A09080706050403020100\n"); return 0; }
void PA_RandRemainder(int poker[], int num) { srand((unsigned)time(NULL)); int times = 6 + rand() % 5; // 随机错位洗牌,洗牌6~10次 get_remainder(poker, num, times); }
int main () { FILE *fin = fopen ("ride.in", "r"); FILE *fout = fopen ("ride.out", "w"); char *comet = NULL; char *group = NULL; size_t len = 0; getline(&comet, &len, fin); getline(&group, &len, fin); if (get_remainder(comet) == get_remainder(group)) { fprintf (fout, "GO\n"); } else { fprintf (fout, "STAY\n"); } return 0; }
int deal_one_line(void) { int ret = 0; char ch = 0; int i = 0; char r = 0; int file_end = 0; last = MAX_COUNT - 1; ret = scanf("%c", &ch); if (ret == EOF) { return 1; } memset(binary_str, 0, MAX_COUNT); memset(quotient_str, 0, QUOTIENT_LEN); memset(ori_str, 0, QUOTIENT_LEN); ori_str[i++] = ch - '0'; while (scanf("%c", &ch) != EOF && ch != '\n') { ori_str[i++] = ch - '0'; } if (ch != '\n') { file_end = 1; } while (i > 0) { i = get_remainder(i); } if (last == MAX_COUNT - 1) { printf("0\n"); } else { i = 0; while (!binary_str[i]) { i++; } for (; i < MAX_COUNT; i++) { printf("%d", binary_str[i]); } printf("\n"); } return file_end; }
//Given a message, appends the CRC division remainder. struct Message apply_crc(struct Message message){ message.quarter[0] = 0; message.quarter[0] = get_remainder(message); return message; }
//Given a CRC output message, checks if there are any errors unsigned int detect_error(struct Message message){ unsigned int remainder = get_remainder(message); // printf("%u\n",remainder); return (remainder); }