如何在 Java 中旋转 128 位数

How to rotate 128 bit number in Java

我正在尝试实现一个使用 128 位密钥的密码。密钥计划的一部分是将密钥向右旋转 29 位,但我不确定该怎么做,因为 Java 中没有可以容纳整个密钥的单一数据类型。我将它存储在两个多头中,一个用于上半部分,一个用于下半部分。这是我认为应该有效但没有成功的位数学:

keyLower >>>= 29;
keyLower |= keyUpper << 35;
keyUpper >>>= 29;
keyUpper |= keyLowerCopy << 29;

谁能帮帮我?

看看BigInteger

Immutable arbitrary-precision integers. [...] Semantics of shift operations extend those of Java's shift operators to allow for negative shift distances. A right-shift with a negative shift distance results in a left shift, and vice-versa. The unsigned right shift operator (>>>) is omitted, as this operation makes little sense in combination with the "infinite word size" abstraction provided by this class.

最后一行有错别字:

//                          vv
keyUpper |= keyLowerCopy << 29;

看起来应该是 << 35