From 8b756e368a33a02d7783053b84bc1e5b50419ff0 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Fri, 9 Oct 2015 10:34:49 -0400 Subject: Initial commit --- client/f16.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 client/f16.c (limited to 'client/f16.c') diff --git a/client/f16.c b/client/f16.c new file mode 100644 index 0000000..2fd05f9 --- /dev/null +++ b/client/f16.c @@ -0,0 +1,73 @@ +/* Recursive Walking Backup + * Copyright © 2015 Jeffrey Armstrong + * http://jeff.rainbow-100.com/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* f16.c - Implementation of a Fletcher 16-bit checksum. The file also + * contains a simple test program that can be enabled by defining + * TEST_FLETCHER at compile time. + */ + +#include + +/* Computes the Fletcher 16-bit checksum and returns the value in the + * b1 and b2 arguments. + */ +void fletcher16(unsigned char *data, + int n, + unsigned char *b1, + unsigned char *b2) +{ +int c1, c2; +int i; +int toint; + + c1 = 0; c2 = 0; + for(i=0;i 2) { + fletcher16(TEST_STR, strlen(TEST_STR), &b1, &b2); + printf("Results for '%s': %d, %d\n", TEST_STR, (int)b1, (int)b2); + } else { + fp = fopen(argv[1], "rb"); + fread(buf, sizeof(char), 64, fp); + fletcher16(buf, 64, &b1, &b2); + printf("Results for 1st 64 bytes: %d, %d\n", (int)b1, (int)b2); + fclose(fp); + } + return (int)b1; +} + +#endif -- cgit v1.2.3