# Output of a Linear Shift Register given Plaintext and intial state

Given an initial state $S_0 = (0101)$ and plaintext $P = 1010101011$ I need to find the ciphertext.

The method to solve this was not taught in my coursework, and the information I have found online does not seem to apply to this.

Can anyone explain the steps needed to solve this?

• each of the four (about) square boxes $a_j$ initially (at $t=0$) holds one of the four bits of $S_0$ (in reading order, unless otherwise stated);
• information follows arrows (almost) instantly, except when getting into a square box where that is delayed until $t$ has grown by $1$ (in time unit or clock period); notice this implies that the content of the left square box is also (with negligible delay) on the arrowhead going straight down and the one going right-down;
• there are three implicit short arrows between the four square boxes, oriented as the rightmost arrowhead;
• each $\oplus$ symbol performs the exclusive-OR of all the ingoing arrows, and outputs that result to outgoing arrow, with no significant delay;
• the plaintext bits are made available one by one (starting at $t=0$, and in reading order, unless otherwise stated) on the input side of the arrow marked "plaintext";
• the ciphertext bits are what's at the arrowhead marked "Cipher-text" (with the same convention as for plaintext).

You can now manually compute what there is in each of the boxes, arrowheads, "plaintext", "Cipher-text", at any integer value of $t\ge0$ (or, more precisely, shortly after). Assuming increasing time matches reading order, you might want to format this as a table with $t$ increasing from left to right, so that the lines with "plaintext" and "Cipher-text" will contain the plaintext and ciphertext in reading order.

• I guess I don't fully understand as in my working the bit at a0 will never change, only the bit in a3, as each is XORed with the previous bit and the result is inserted in a3. This means the plaintext is always XORed with the bit in a0 which has never changed. Jun 15, 2016 at 7:48
• @Dawson: read the third bullet (in combination to the second); that tells $a_1$ gets copied into $a_0$ when $t$ increases to the next integer.
– fgrieu
Jun 15, 2016 at 10:06

If this can code can help you understanding the Linear Shift Register. (^ represents Exclusive OR)

        byte[] register = new byte[] { 0, 1, 0, 1 };
byte[] plain = new byte[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 1 }; ;
byte[] cipher = new byte[plain.Length];

for (int i = 0; i < plain.Length; i++)
{
//plaintext ^ state a0
cipher[i] = (byte)(plain[i] ^ register[0]);

//Temporary storing Result of a0 ^ a3
byte temp = (byte)(register[0] ^ register[3]);

//Shifting states one index Left
register[0] = register[1];
register[1] = register[2];
register[2] = register[3];

//Setting new state a3
register[3] = temp;
}