我正在使用pySerial从连接的设备读取数据.我想计算每个收到的数据包的校验和.数据包作为char数组读入,实际校验和是数据包末尾的最后一个字节.为了计算校验和,我通常会对数据包有效负载求和,然后将其与实际校验和进行比较.
通常在像C这样的语言中,我们会期望溢出,因为校验和本身只有一个字节.我不确定python的内部,但根据我对该语言的经验,它看起来会默认为更大的大小变量(也许是一些内部的bigInt类或其他东西).无论如何都有模仿添加两个字符的预期行为,而不编写我自己的实现?谢谢.
MD5的金额是否仍然适合检查文件欺骗?我知道它不安全,但在尝试查找文件欺骗的情况下,这真的很重要吗?
我应该在SHA系列中使用某些东西吗?
这个用例的最佳实践是什么?
我做了很多研究,这只会使我更加困惑。问题是,是否在Internet层(IP),传输层(TCP / UDP)或两者都验证了数据包校验和?
谢谢Yan
我有一个多维数组,Bytes
定义如下:
type
TRow = array[0..6] of Byte;
var
All: array[0..19112079] of TRow;
Run Code Online (Sandbox Code Playgroud)
现在,我想为数组所包含的每一行生成唯一的校验和并保存到文件中,如下所示:
var
I: Integer;
begin
for I := 0 to 19112079 do
begin
Checksum := GenerateChecksum(All[I]);
Writeln(F, Checksum);
end;
end;
Run Code Online (Sandbox Code Playgroud)
我应该怎么做这个GenerateChecksum()
功能?我试过xor
和CRC32
,但他们是不是真的适合这个任务,因为它们返回重复值.我想为每一行生成一个唯一的校验和.
编辑 哦,校验和应该以允许比较行的方式计算.我想拿两个不同行的校验和,并判断其中一个是否大于另一个,小于另一个,或相等.有机会实现这样的目标吗?
EDIT2 两个相邻行中的示例数据:
Row x - 1: 120, 444, 323, 984, 1024, 76, 130
Row x: 120, 444, 323, 984, 1024, 76, 222
Row x + 1: 120, 444, 323, 984, 1024, 76, 121
. . …
Run Code Online (Sandbox Code Playgroud) 我试过维基百科的例子:http://en.wikipedia.org/wiki/Longitudinal_redundancy_check
这是lrc(C#)的代码:
/// <summary>
/// Longitudinal Redundancy Check (LRC) calculator for a byte array.
/// ex) DATA (hex 6 bytes): 02 30 30 31 23 03
/// LRC (hex 1 byte ): EC
/// </summary>
public static byte calculateLRC(byte[] bytes)
{
byte LRC = 0x00;
for (int i = 0; i < bytes.Length; i++)
{
LRC = (LRC + bytes[i]) & 0xFF;
}
return ((LRC ^ 0xFF) + 1) & 0xFF;
}
Run Code Online (Sandbox Code Playgroud)
它说结果是"EC",但我得到"71",我做错了什么?
谢谢.
我试图弄清楚如何基于相同的InputStream
使用读取多个摘要(md5,sha1,gpg)DigestInputStream
.根据我在文档中检查的内容,似乎可以通过克隆摘要来实现.有人可以说明一下吗?
我不想重新读取流来计算校验和.
I need help with writing a code in C++ to do a 16 bit checksum.
The idea is to get data input from user (a string), convert it to binary form, then calculate checksum and put it in my data packet. I don't have any checksum type specification... I thought XORing the 16 bits would be a good idea. I have the following class packet given:
class packet
{
private:
string message;
unsigned int checksum; // this is a 16 …
Run Code Online (Sandbox Code Playgroud) 我试图在Python中实现Luhn公式,这是我的代码:
import sys
def luhn_check(number):
if number.isdigit():
last_digit = int(str(number)[-1])
reverse_sequence = list(int(d) for d in str(int(number[-2::-1])))
for i in range(0, len(reverse_sequence), 2):
reverse_sequence[i] *= 2
for i in range(len(reverse_sequence)):
if reverse_sequence[i] > 9:
reverse_sequence[i] -= 9
sum_of_digits = 0
for i in range(len(reverse_sequence)):
sum_of_digits += reverse_sequence[i]
result = divmod(sum_of_digits, 10)
if result == last_digit:
print("[VALID] %s" % number)
else:
print("[INVALID] %s" % number)
quit()
print("[ERROR] \" %s \" is not a valid sequence." % number)
quit()
def …
Run Code Online (Sandbox Code Playgroud) 我想为实现路由协议的网络分配计算 1 字节校验和,因为我是全新的,请帮助我提供 1 字节校验和的源代码
这是我的 simPhy.java 类。
import java.util.*;
import java.net.*;
import java.io.*;
/**
* the IpAddress class handles ip address including functionalities such as whether two ip addresses are in the same network
*/
class IpAddress{
/**
* contains the ip address in byte format
*/
byte[] ipAddr=new byte[4];
/**
* receives an ip address in string format and stores it in instance variable ipAddr
*
* @param ipString ip address in String format
*/
public IpAddress(String ipString){ …
Run Code Online (Sandbox Code Playgroud) 这个问题的旧标题: CRC16 combine implementation vs CRC32 combine Implementation之间的区别
我正在尝试实现类似于 CRC32 组合实现的 CRC16 组合实现。我使用的CRC-CCITT(初始值:0xFFFF的,保利:0x1021)描述在这里。
我阅读并试图理解本答案中描述的 CRC32_Combine 实现,但我还没有完全理解它。我已经为 CRC16 组合做了一个 C# 实现,只是将 32x32 矩阵修改为 16x16,更多我不确定。我应该得到以下值,但我没有得到这些值:
Msg1 : "123" CRC-16-CCITT : 0x5bce
Msg2 : "456789" CRC-16-CCITT : 0x6887
Combined Msg1 + Msg2 : "123456789" CRC-16-CCITT should be "0x29B1".
But what I got with my code below is "0x64d8".
Run Code Online (Sandbox Code Playgroud)
ZLib 的 C# 代码:
const UInt16 poly16Reverse = 0x8408;
const Int16 GF2_DIM = 16;
private static UInt16 gf2_matrix_times(UInt16[] mat, UInt16 vec) …
Run Code Online (Sandbox Code Playgroud)