Back to Project Back

Grain-128 Manual Calculation Guide

8-Bit Mode Manual Flow

📝 Step 1: Input 1 Character (8 Bits)

Enter a single character to see its exact step-by-step manual derivation

Manual Calculation Mode: Rather than processing 16 bytes at once, this guide focuses on 1 character (8 bits) so you can follow along on paper and present it in your viva!
Character 'H'
ASCII: 72 | Hex: 0x48 | Binary: 01001000
1 Character → 8 Bits

🔢 Step 2: Convert Character to 8-Bit Binary

Character ASCII Code → 8-bit binary vector (P[7] to P[0])

For character 'H': ASCII code = 72 (Hex: 0x48). Converting to 8-bit binary yields 01001000.
Bit Index P[7] (MSB) P[6] P[5] P[4] P[3] P[2] P[1] P[0] (LSB)

🔑 Step 3: Extract Tap Values from Initial Seeds (L & N)

Read required bit indices from 128-bit LFSR (L) and NFSR (N) registers

Grain-128 specifies exact tap positions in the registers. Look up these bit indices in initial seed L = 0xACE1... and N = 0x1234...:
📘 LFSR State Taps (s array) for State S0
s124 = 1 | s102 = 0 | s81 = 1 | s63 = 1 | s57 = 0 | s34 = 0
📙 NFSR State Taps (b array) for State S0
b125 = 0 | b118 = 0 | b112 = 0 | b91 = 0 | b87 = 1 | b82 = 1 | b79 = 0 | b63 = 0 | b54 = 0 | b39 = 1 | b38 = 0

⚙️ Step 4: Compute Non-Linear h(x) & Keystream Byte Z[7:0]

Select any bit below to inspect its h(x) filter terms and derivation

Select Bit to Inspect (Z[7] down to Z[0]):

🔬 Step-by-Step Keystream Derivation for Z[7] (State S0)

1. h(x) Non-Linear Filter Function Formula
h(x) = (s124 · s102) ⊕ (s81 · s63) ⊕ (s57 · b118) ⊕ (b87 · b79) ⊕ (s124 · s57 · b39)
2. Evaluate 5 AND-Product Terms & h(x) Result
Term 1: (1·0) = 0 | Term 2: (1·1) = 1 | Term 3: (0·0) = 0 | Term 4: (1·0) = 0 | Term 5: (1·0·1) = 0
h(x) = 0 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 0 = 1
3. Computed Keystream Bit Z[k] (h(x) ⊕ 8 Linear Taps)
Z = h(x) ⊕ s34 ⊕ b125 ⊕ b112 ⊕ b91 ⊕ b82 ⊕ b63 ⊕ b54 ⊕ b38
Z[7] = 1 ⊕ 0 ⊕ 0 ⊕ 0 ⊕ 0 ⊕ 0 ⊕ 0 ⊕ 0 ⊕ 0 = 1
Full 8-Bit Keystream Byte Z[7:0] = 10000000 (0x80)

🔒 Step 5: Bitwise XOR Encryption (C = P ⊕ Z)

Bit-by-bit XOR table of 8 Plaintext bits with 8 Keystream bits

Apply XOR rule: 0 ⊕ 0 = 0, 1 ⊕ 1 = 0, 1 ⊕ 0 = 1, 0 ⊕ 1 = 1.
Bit Position Plaintext Bit (P) Keystream Bit (Z) XOR Calculation Ciphertext Bit (C)

🔴 Step 6: Ciphertext Result

8-bit encrypted byte generated from character

0xC8
11001000
Original Plaintext Character
'H' (0x48 = 01001000)
→
Encrypted Ciphertext Byte
0xC8 (11001000)

🟢 Step 7: Bitwise XOR Decryption (P = C ⊕ Z)

Apply exact same keystream to recover original character

XOR is self-inverse: (P ⊕ Z) ⊕ Z = P. XORing Ciphertext C with Keystream Z recovers Plaintext P!
Bit Position Ciphertext Bit (C) Keystream Bit (Z) XOR Calculation Recovered Bit (P)
✅
Decryption Successful!
Recovered Plaintext Byte: 0x48 (01001000)
'H'