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'