我正在尝试在 c# 中实现 Speck 32/64 block 密码,我被困在加密解密算法中。我知道我应该根据算法将纯文本拆分为 2 个单词
x,y = plaintext words
--------------------------- key expansion --------------------------
for i = 0..T-2
[i+m-1] ← (k[i] + S−α
[i]) ⊕ i
k[i+1] ← S
β k[i] ⊕ `[i+m-1]
end for
---------------------------- encryption ----------------------------
for i = 0..T-1
x ← (S−α x + y) ⊕ k[i]
y ← S
βy ⊕ x
end for
References
The SIMON and SPECK Families of Lightweight Block Ciphers https://eprint.iacr.org/2013/404
我的问题是明文应该是字符串然后我转换成二进制或什么并在上面的算法中使用它? 算法没有说明明文类型,有加密示例
Key: 1918 1110 0908 0100
Plaintext: 6574 694c
Ciphertext: a868 42f2
最佳答案
SPECK 32/64 密码需要 4 个字节作为输入。
Plaintext: 6574 694c
表示
byte[] plaintext = new byte[] {0x65, 0x74, 0x69, 0x4C};
其中每个字节都使用 0x
前缀指定为十六进制值。
您将在第一步中划分明文:
byte[] x = new byte[] {plaintext[0], plaintext[1]};
byte[] y = new byte[] {plaintext[2], plaintext[3]};
注意:使用一些更巧妙的数组操作来加速您的密码,上面的示例仅用于教育目的。
注释 2:将输入作为 uint
处理可能是一个很好的方法,它可能比带有一点按位魔术的数组快得多:
uint plaintext = 0x6574694C;
ushort x = (ushort) (plaintext >> 16);
ushort y = (ushort) plaintext;
关于c# - 尝试实现 Speck32/64 分组密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34413606/