简体   繁体   English

如何在Java中执行按位排列

[英]how to perform bitwise permutation in java

I'm implementing DES also in java and i am confused first as to how to get plain text into its corresponding 64 bit binary blocks and them permuting it using permutation tables. 我也在Java中实现DES,对于如何将纯文本转换为其对应的64位二进制块以及如何使用置换表对其进行置换,我首先感到困惑。

eg. 例如。 I want to get 000001010011100101110111000001000100100011010001010110 from 0123456789ABCDEF, how would I do this? 我想从0123456789ABCDEF获取000001010011100101110111000001000100100011010001010110,我该怎么做?

Afterwards i want to permute 000001010011100101110111000001000100100011010001010110 using the table 之后我想使用表格置换000001010011100101110111111000001000100100011010001010110

private static final byte[] IP = { 
        58, 50, 42, 34, 26, 18, 10, 2,
        60, 52, 44, 36, 28, 20, 12, 4,
        62, 54, 46, 38, 30, 22, 14, 6,
        64, 56, 48, 40, 32, 24, 16, 8,
        57, 49, 41, 33, 25, 17, 9,  1,
        59, 51, 43, 35, 27, 19, 11, 3,
        61, 53, 45, 37, 29, 21, 13, 5,
        63, 55, 47, 39, 31, 23, 15, 7
    };

You need to understand the relationship between the Initial Permutation and the Left and Right Blocks you're loading: 您需要了解初始置换与正在加载的左右块之间的关系:

Big   MSB7     Input Block (64 bits)                    
End   Bit                                      Left  Register (32 bits)
2------6-------58 50 42 34 26 18 10  2             1  2  3  4  5  6  7  8
4------4-------60 52 44 36 28 20 12  4             9 10 11 12 13 14 15 16
6------2-------62 54 46 38 30 22 14  6            17 18 19 20 21 22 23 24
8------0-------64 56 48 40 32 24 16  8            25 26 27 28 29 30 31 32

                                               Right Register (32 bits)
1------7-------57 49 41 33 25 17  9  1             1  2  3  4  5  6  7  8
3------5-------59 51 43 35 27 19 11  3             9 10 11 12 13 14 15 16
5------3-------61 53 45 37 29 21 13  5            17 18 19 20 21 22 23 24
7------1-------63 55 47 39 31 23 15  7            25 26 27 28 29 30 31 32

Input Byte      8  7  6  5  4  3  2  1

An Input Block is eight 8 bit bytes (64 bits) that's going into two 32 bit blocks (Left and Right). 输入块是八个8位字节(64位),分为两个32位块(左和右)。 IBM used a big endian bit-in-byte representation. IBM使用大字节序表示。

The Input Block would be numbered 1 through 64 with 1 through 8 representing the first byte and 1 the MSB of that byte. 输入块的编号为1到64,其中1到8代表第一个字节,1代表该字节的MSB。

The odd bits go to the Right Block, the even bits go to Left Block. 奇数位进入右块,偶数位进入左块。

The Input Byte numbers and bits-in-types representations shown above can be used to map input bytes to Left and Right Block representations. 上面显示的“输入字节数”和“类型中的位数”表示可用于将输入字节映射到“左”和“右”块表示。

For your example your input bytes are comprised of two hex digits and are 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD and 0xEF. 以您的示例为例,您的输入字节由两个十六进制数字组成,分别为0x01、0x23、0x45、0x67、0x89、0xAB,0xCD和0xEF。 The first byte provides input block bits 1 through 8, the second 9 through 16, the third 17 through 24, the fourth 25 through 32, the fifth 33 through 40, the sixth 41 through 48, the seventh 49 through 56 and the eighth input block bits 57 through 64. 第一个字节提供输入块位1到8,第二个9到16,第三个17到24,第四个25到32,第五个33到40,第六个41到48,第七个49到56和第八个输入块位57到64。

The actual effect is to serially load eight 8 bit shift registers, four each comprising the Left and Right Registers from an 8 bit interface in a hardware implementation. 实际的效果是在硬件实现中从8位接口串行加载8个8位移位寄存器,每个4个寄存器包含左寄存器和右寄存器。 For round operations the Left and Right Registers are also capable of being parallel loaded or parallel read as well as serially shifted out for the Inverse Initial Permutation (which reverses the odd/even relationship). 对于舍入运算,左寄存器和右寄存器还能够并行加载或并行读取,以及可以串行移出以用于反向初始置换(这将反转奇/偶关系)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM