Louna Akkad
Louna Akkad

Reputation: 55

trying to implement Speck32/64 block Cipher

I am trying to implement Speck 32/64 block Cipher in c# I'm stuck at encryption decryption algorithm. i know that i should split the plain text in to 2 word according to algorithm

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

my question is the plaintext should be string then i convert to binary or what and use it in the above algo? the algorithm didnot say the type of plaintext and there is example encryption

Key: 1918 1110 0908 0100
Plaintext: 6574 694c
Ciphertext: a868 42f2

Upvotes: 2

Views: 1449

Answers (1)

vojta
vojta

Reputation: 5661

SPECK 32/64 cipher expects 4 bytes as the input.

Plaintext: 6574 694c

means

byte[] plaintext = new byte[] {0x65, 0x74, 0x69, 0x4C};

where each byte is specified as hexadecimal value using the 0x prefix.

You will divide the plaintext in the first step:

byte[] x = new byte[] {plaintext[0], plaintext[1]};
byte[] y = new byte[] {plaintext[2], plaintext[3]};

Note: use some more clever array manipulation to speed up your cipher, the example above is for educational purposes only.

Note 2: handling input as a uint might be a good approach, it could be much faster than arrays with a little of bitwise magic:

uint plaintext = 0x6574694C;
ushort x = (ushort) (plaintext >> 16);
ushort y = (ushort) plaintext;

Upvotes: 1

Related Questions