我想计算我想发送的UDP报头数据包的校验和:
packetosend = """60 00 00 00 00 24 3a 40 20 02 c0 a8 01 50 00 01 00 00
00 00 00 00 09 38 20 02 c0 a8 01 50 00 01 00 00 00 00 00 00 09 6f"""
Run Code Online (Sandbox Code Playgroud)
所以我需要加入这个utf-16(不是问题)并计算这个特定数据包的校验和.我怎样才能做到这一点?
谢谢!
编辑:是的它是ICMPv6数据包的IPv6标头,无论如何我想知道的是公式,以及它是如何工作的.
我将给出一个ICMP ping echo(v4)数据包的另一个例子:
packet = """
08 00 d1 15 76 0c 00 07 bf d3 55 4a ad b5 03 00 // "d1 15" is the packet checksum
08 09 0a …
Run Code Online (Sandbox Code Playgroud) 谷歌已经让我失望了,即使在这里我也找不到答案 - 让我真的在这里发布我的第一个问题.
我正在尝试获取命令"mvn install"以自动生成工件的校验和,并将校验和与工件一起放在存储库中.我读过的所有内容似乎表明它应该在没有我介入的情况下发生,但我得到的只是工件,源zip,pom和本地元数据xml.
该项目的pom看起来像这样:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.pkg.name</groupId>
<artifactId>Logging</artifactId>
<version>1.2.0-SNAPSHOT</version>
<build>
<sourceDirectory>src/java</sourceDirectory>
<testSourceDirectory>test/java</testSourceDirectory>
<resources>
<resource>
<directory>src/conf</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>test/conf</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<debug>true</debug>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.4</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6.SEC02</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies> …
Run Code Online (Sandbox Code Playgroud) 我正在开发游戏.我将游戏对象存储在此地图中:
std::map<std::string, Object*> mObjects;
Run Code Online (Sandbox Code Playgroud)
std::string
是在代码中进一步查找的对象的键/名称.指向某些对象非常容易,例如:mObjects["Player"] = ...
.但是我担心由于在该地图中的每次搜索中分配std :: string而导致速度变慢.所以我决定int
用作该地图的关键.
第一个问题:那真的会更快吗?
第二,我不想删除我当前访问的对象类型,所以我找到了方法:存储crc
字符串计算为关键.例如:
Object *getObject(std::string &key)
{
int checksum = GetCrc32(key);
return mObjects[checksum];
}
Object *temp = getOject("Player");
Run Code Online (Sandbox Code Playgroud)
或者这是个坏主意?为了计算crc
我会用boost::crc
.或者这是个坏主意,校验和的计算比使用密钥类型在地图中搜索要慢得多std::string
?
TCP 是否不负责通过在传输过程中发生丢失等可能需要的任何事情来确保通过网络完整发送流?
难道它没有做好吗?
为什么更高的应用层协议及其应用程序仍然执行校验和?
我正在使用adler32校验和算法从数据库ID生成一个数字.因此,当我在数据库中插入一行时,我会获取该行的标识并使用它来创建校验和.我遇到的问题是我刚刚在数据库中插入了207个后才生成重复校验和.这比我预期的要快得多.这是我的代码:
String dbIdStr = Long.toString(dbId);
byte[] bytes = dbIdStr.getBytes();
Checksum checksum = new Adler32();
checksum.update(bytes, 0, bytes.length);
result = checksum.getValue();
Run Code Online (Sandbox Code Playgroud)
我在做什么/怎么做有什么问题吗?我应该使用不同的方法来创建唯一的字符串吗?我这样做是因为我不想在url中使用db id ...对db结构的更改将破坏世界上所有的链接.
谢谢!
在查看了多个用于生成 Java MD5 和 SHA* 散列的在线参考资料后,我注意到纯文本(文件字符串)在被馈送到 Digest 对象以生成散列之前和之后经过了一定的准备。具体来说,数据首先转换为字节数组,然后馈送到摘要,然后输出哈希转换为十六进制流。为什么所有这些字节和十六进制转换?
PS:我想答案与 Java 和 Digest 对象如何开展业务有关,我提出这个问题的动机是为了理解这种行为,并可能获得对一些文档/文献的引用,这些文档/文献对此进行了深入解释.
丹克!
我们在sql server中执行一些数据的校验和,如下所示:
declare @cs int;
select
@cs = CHECKSUM_AGG(CHECKSUM(someid, position))
from
SomeTable
where
userid = @userId
group by
userid;
Run Code Online (Sandbox Code Playgroud)
然后,这些数据与客户共享.我们希望能够在客户端重复校验和...但是似乎没有关于如何计算上述函数中的校验和的任何信息.任何人都可以开导我吗?
我的任务是整合大约15年的实验室记录,其中大部分是学生作业或原始数据.我们正在谈论100,000多个人工生成的文件.
我的计划是编写一个Python 2.7脚本,它将映射整个目录结构,为每个目录结构创建校验和,然后标记重复项以进行删除.我预计可能会有10-25%的重复.
我的理解是MD5碰撞在理论上是可能的,但是这不太可能,这实际上是一个安全的程序(假设如果发生1次碰撞,我的工作将是安全的).
这是一个安全的假设吗?如果实现很重要,我打算使用的唯一Python库是:
hashlib
校验和;sqlite
用于数据处理结果; os
用于目录映射在我的项目中,我只是尝试将liquibase从3.2.2升级到3.4.2(包括jar和maven插件).编辑:同样升级到3.3.x. 因此,启动应用程序现在会出现以下错误:
Caused by: liquibase.exception.ValidationFailedException: Validation Failed:
4 change sets check sum
src/main/resources/changelogs/xxx_add_indices_to_event_tables.xml::xxx-add_indices_to_event_tables::xxx is now: 7:0fc8f1faf484a59a96125f3e63431128
Run Code Online (Sandbox Code Playgroud)
这适用于50个中的4个变更集,所有这些变更集都添加了索引,例如:
<createIndex indexName="idx_eventtype" tableName="events">
<column name="eventtype" type="varchar(64)"/>
</createIndex>
Run Code Online (Sandbox Code Playgroud)
虽然我可以在本地修复此问题,但手动修复所有正在运行的环境会非常痛苦.这是一个错误,还是有一些解决方法?
当谷歌搜索有关Python列表理解的信息时,我获得了一个google foobar挑战,我在过去的几天里一直在慢慢地工作以获得乐趣.最新挑战:
有效地要求生成ID列表,忽略每个新行的增加数字,直到剩下一个ID.然后你应该XOR(^)ID来产生校验和.我创建了一个输出正确答案的工作程序,但是在分配的时间内传递所有测试用例(通过6/10)效率不高.长度为50,000应该在20秒内产生结果,但需要320.
有人可以引导我朝着正确的方向前进,但请不要为我做这件事,我很乐意用这个挑战推动自己.也许我可以实现一种数据结构或算法来加快计算时间?
代码背后的逻辑:
首先,获取起始ID和长度
生成ID列表,忽略来自每个新行的ID越来越多的ID,从忽略第一行的0开始.
使用for循环对IDS列表中的所有数字进行异或
答案以int形式返回
import timeit
def answer(start,length):
x = start
lengthmodified = length
answerlist = []
for i in range (0,lengthmodified): #Outter for loop runs an amount of times equal to the variable "length".
prestringresult = 0
templist = []
for y in range (x,x + length): #Fills list with ids for new line
templist.append(y)
for d in range (0,lengthmodified): #Ignores an id from each line, increasing by one with each line, …
Run Code Online (Sandbox Code Playgroud) checksum ×10
java ×3
python ×3
crc ×2
adler32 ×1
boost ×1
bytearray ×1
c++ ×1
cryptographic-hash-function ×1
cryptography ×1
encryption ×1
hex ×1
liquibase ×1
map ×1
maven ×1
maven-2 ×1
md5 ×1
networking ×1
packet ×1
pom.xml ×1
sql-server ×1
tcp ×1
xor ×1