checksum

Crcmod python3 polynomial error

旧城冷巷雨未停 提交于 2019-12-24 04:58:10
问题 I need to use a crc checksum in a python3 program, but my knowledge of crc is virtually non-existent. Here is the test code I wrote import crcmod crc_func = crcmod.mkCrcFun(0x1d, initCrc=0x07, xorOut=0x00) print(hex(crc_func(b'123456789'))) When I run this, I get the following error: ValueError: The degree of the polynomial must be 8, 16, 24, 32 or 64 But 1D is 8 bit, so I must be doing something wrong. Please explain what I did wrong. 回答1: But 1D is 8 bit No it isn't; it's 5 bits: >>> bin

Compress a file in memory, compute checksum and write it as `gzip` in python

巧了我就是萌 提交于 2019-12-24 03:25:49
问题 I want to compress files and compute the checksum of the compressed file using python. My first naive attempt was to use 2 functions: def compress_file(input_filename, output_filename): f_in = open(input_filename, 'rb') f_out = gzip.open(output_filename, 'wb') f_out.writelines(f_in) f_out.close() f_in.close() def md5sum(filename): with open(filename) as f: md5 = hashlib.md5(f.read()).hexdigest() return md5 However, it leads to the compressed file being written and then re-read. With many

MySQL rows checksum

半腔热情 提交于 2019-12-24 02:33:41
问题 Is it possible to select entire row in a table and get sort of checksum? I am looking for a way to tell my code to update data only if at least one record has been changed. From perspective of data changes tracking it would help me to size down a number of changes noted in history table. - Thanks. 回答1: You can combine the MD5() and CONCAT() functions to generate an MD5 checksum for the row: SELECT MD5(CONCAT(col1, col2, col3, ...)) as MD5_checksum FROM table; If one of the columns is nullable

Generate a number in a specific range from a checksum

纵饮孤独 提交于 2019-12-24 01:53:20
问题 I'm working on a number generator that takes a string as input, and produces a number in a specific range as output. In order to do this, I'll need to determine the minimum and maximum possible value that an md5 checksum can have, and then convert the md5 checksum to a number in that range. How can I convert an md5 checksum to a number in a specified range? function getNumberInRange(md5checksum, min, max){ //generate a number between min to max, inclusive, using the md5 checksum that is

NSData to CRC-16?

大城市里の小女人 提交于 2019-12-24 00:16:06
问题 I am trying to to calculate CRC-16 from NSData. It is not working, I am expecting "BB3D" from 123456789, but I get nothing like it. This is the code that I have: static const unsigned short crc16table[] = { 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, 0xD801, 0x18C0, 0x1980, 0xD941,

Error recovery algorithms? [closed]

荒凉一梦 提交于 2019-12-23 19:27:19
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I am doing a software that grabs in the end a numeric string, that string encodes important data, and any error destroy the contents. Worse: It is VERY prone for errors, because of how data is transmitted (and I can do nothing about it). So I decided to add a verification digit of sorts... After some research, I

NodeJS detect modified files

南楼画角 提交于 2019-12-23 19:12:18
问题 App loads user's text files and each of them can be changed by user. On app's start I want to check if any file was changed since last time. I think the most efficient way is to calculate checksum of each file and save to one json file. On app's start I will check each file checksum and compare it to data from json file Is there any more optimal/efficient way of doing this ? Or how exactly calculate file checksum ? 回答1: I believe Using fs.stat and checking 'last modified' is much faster than

Implementing SQL CHECKSUM in Java

风流意气都作罢 提交于 2019-12-23 12:42:50
问题 I have an existing database in SQL Server 2008 that performs user authentication via stored procedure for an existing PHP web application. The web application sends the stored procedure a string, however the stored procedure stores, and checks the value with SQL Checksum (http://msdn.microsoft.com/en-us/library/ms189788.aspx). The Stored Procedure casts the string as NVARCHAR(50), and stores the CHECKSUM as int in the user table. I am now writing a new Java application on top of the existing

C# ICMPv6 checksum calculation

吃可爱长大的小学妹 提交于 2019-12-23 02:59:10
问题 I need to compute ICMPv6 checksum. I have found correct manual in RFC 2460 and written code in c#, which is pasted below. In a code you can see that i add to checksum source IP, destination IP of packet, than ICMPv6 message length (which is 32 bytes for Neighbor Advertisement) and then i add next header ID which is 58 for ICMPv6. Then there is FOR cycle, which adds to checksum whole ICMPv6 message (which starts with message type i believe, e.g. 88 00 ... for Neighbor advertisement). Than i

checksum calculation

江枫思渺然 提交于 2019-12-23 01:25:36
问题 To calculate CRC I found a piece of code but I am not understanding the concept. Here is the code: count =128 and ptr=some value; calcrc(unsigned char *ptr, int count) { unsigned short crc; unsigned char i; crc = 0; while (--count >= 0) { crc = crc ^ (unsigned short)*ptr++ << 8; i = 8; do { if (crc & 0x8000) crc = crc << 1 ^ 0x1021; else crc = crc << 1; } while(--i); } return (crc); } Please any body explain and tell me the logic. 回答1: This looks like a CRC (specifically it looks like CRC-16