Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 从字节到字的转换_C_Word_Bit Manipulation_Keccak - Fatal编程技术网

C 从字节到字的转换

C 从字节到字的转换,c,word,bit-manipulation,keccak,C,Word,Bit Manipulation,Keccak,在花了相当长的时间试图理解这个方法的功能之后,我仍然不知道它做了什么。据我所知,stateAsBytes应该包含诸如“\xA1\X32\X89\XB2”之类的十六进制字符串,stateAsWords[I%5][I/5]|=(无符号长)(stateAsBytes[I*(64/8)+j])它所做的是将1600字节的数组视为小尾端64位值数组,并将它们重新组织为五个stateAsWords数组作为本机64位字: "index" of the 64 bit value

在花了相当长的时间试图理解这个方法的功能之后,我仍然不知道它做了什么。据我所知,stateAsBytes应该包含诸如“\xA1\X32\X89\XB2”之类的十六进制字符串,
stateAsWords[I%5][I/5]|=(无符号长)(stateAsBytes[I*(64/8)+j])它所做的是将1600字节的数组视为小尾端64位值数组,并将它们重新组织为五个
stateAsWords
数组作为本机64位字:

                 "index" of the 64 bit value 
                    from the stateAsBytes 
                         buffer

    stateAsWord[0]: 0, 5, 10, 15, 20
    stateAsWord[1]: 1, 6, 11, 16, 21
    stateAsWord[2]: 2, 7, 12, 17, 22
    stateAsWord[3]: 3, 8, 13, 18, 23
    stateAsWord[4]: 4, 9, 14, 19, 24
按位分配只是从little endian缓冲区逐字节构建本机64位字

请注意,您发布的代码假定
unsigned long
是64位类型,因此它存在一些可移植性问题,特别是它不能在大多数32位目标上工作,也不能在Windows(甚至64位Windows)上工作

                 "index" of the 64 bit value 
                    from the stateAsBytes 
                         buffer

    stateAsWord[0]: 0, 5, 10, 15, 20
    stateAsWord[1]: 1, 6, 11, 16, 21
    stateAsWord[2]: 2, 7, 12, 17, 22
    stateAsWord[3]: 3, 8, 13, 18, 23
    stateAsWord[4]: 4, 9, 14, 19, 24