The same keystream undoes toy XOR encryption when the ciphertext is unchanged.

highlighted = computed this step

XOR again returns the message

Decrypting this toy ciphertext means XOR with the same keystream again. That property is why a later bit flip can be controlled.

same keystream=1\text{same keystream}=1
Decrypt by XOR againToy XOR encryption and decryption are recomputed from pinned bytes.Plaintext48 bits / 6 bytes0x7061793d3130byte 0byte 1byte 2byte 301110000011000010111100100111101byte 4byte 50011000100110000byte-00x70byte-10x61byte-20x79byte-30x3dbyte-40x31byte-50x30Keystream48 bits / 6 bytes0x0f1e2d3c4b5abyte 0byte 1byte 2byte 300001111000111100010110100111100byte 4byte 50100101101011010byte-00x0fbyte-10x1ebyte-20x2dbyte-30x3cbyte-40x4bbyte-50x5aCiphertext48 bits / 6 bytes0x7f7f54017a6abyte 0byte 1byte 2byte 301111111011111110101010000000001byte 4byte 50111101001101010byte-00x7fbyte-10x7fbyte-20x54byte-30x01byte-40x7abyte-50x6aToy XOR rows - changed byte 4rowvaluecheckplaintext7061793d3130pinned byteskeystream0f1e2d3c4b5apinned bytesciphertext7f7f54017a6aplaintext xor keystreamtarget plaintext7061793d3930attacker targetattack mask000000000800plaintext xor targetmodified ciphertext7f7f5401726aciphertext xor maskdecrypted modified7061793d3930modified ciphertext xor keystream

The round trip

Ciphertext XOR keystream returns the original message bytes 0x7061793d3130.

plaintext=0x7061793d3130\text{plaintext}=0x7061793d3130
Decrypt by XOR againToy XOR encryption and decryption are recomputed from pinned bytes.Plaintext48 bits / 6 bytes0x7061793d3130byte 0byte 1byte 2byte 301110000011000010111100100111101byte 4byte 50011000100110000byte-00x70byte-10x61byte-20x79byte-30x3dbyte-40x31byte-50x30Keystream48 bits / 6 bytes0x0f1e2d3c4b5abyte 0byte 1byte 2byte 300001111000111100010110100111100byte 4byte 50100101101011010byte-00x0fbyte-10x1ebyte-20x2dbyte-30x3cbyte-40x4bbyte-50x5aCiphertext48 bits / 6 bytes0x7f7f54017a6abyte 0byte 1byte 2byte 301111111011111110101010000000001byte 4byte 50111101001101010byte-00x7fbyte-10x7fbyte-20x54byte-30x01byte-40x7abyte-50x6aToy XOR rows - changed byte 4rowvaluecheckplaintext7061793d3130pinned byteskeystream0f1e2d3c4b5apinned bytesciphertext7f7f54017a6aplaintext xor keystreamtarget plaintext7061793d3930attacker targetattack mask000000000800plaintext xor targetmodified ciphertext7f7f5401726aciphertext xor maskdecrypted modified7061793d3930modified ciphertext xor keystream

No authentication yet

So far, there is no separate tag checking whether the ciphertext was changed.

authentication tag=0\text{authentication tag}=0
Decrypt by XOR againToy XOR encryption and decryption are recomputed from pinned bytes.Plaintext48 bits / 6 bytes0x7061793d3130byte 0byte 1byte 2byte 301110000011000010111100100111101byte 4byte 50011000100110000byte-00x70byte-10x61byte-20x79byte-30x3dbyte-40x31byte-50x30Keystream48 bits / 6 bytes0x0f1e2d3c4b5abyte 0byte 1byte 2byte 300001111000111100010110100111100byte 4byte 50100101101011010byte-00x0fbyte-10x1ebyte-20x2dbyte-30x3cbyte-40x4bbyte-50x5aCiphertext48 bits / 6 bytes0x7f7f54017a6abyte 0byte 1byte 2byte 301111111011111110101010000000001byte 4byte 50111101001101010byte-00x7fbyte-10x7fbyte-20x54byte-30x01byte-40x7abyte-50x6aToy XOR rows - changed byte 4rowvaluecheckplaintext7061793d3130pinned byteskeystream0f1e2d3c4b5apinned bytesciphertext7f7f54017a6aplaintext xor keystreamtarget plaintext7061793d3930attacker targetattack mask000000000800plaintext xor targetmodified ciphertext7f7f5401726aciphertext xor maskdecrypted modified7061793d3930modified ciphertext xor keystream

Summary

Toy XOR encryption hides bytes only while the ciphertext is unchanged. The next chapter changes a ciphertext byte on purpose.

changed bytes so far=0\text{changed bytes so far}=0
Decrypt by XOR againToy XOR encryption and decryption are recomputed from pinned bytes.Plaintext48 bits / 6 bytes0x7061793d3130byte 0byte 1byte 2byte 301110000011000010111100100111101byte 4byte 50011000100110000byte-00x70byte-10x61byte-20x79byte-30x3dbyte-40x31byte-50x30Keystream48 bits / 6 bytes0x0f1e2d3c4b5abyte 0byte 1byte 2byte 300001111000111100010110100111100byte 4byte 50100101101011010byte-00x0fbyte-10x1ebyte-20x2dbyte-30x3cbyte-40x4bbyte-50x5aCiphertext48 bits / 6 bytes0x7f7f54017a6abyte 0byte 1byte 2byte 301111111011111110101010000000001byte 4byte 50111101001101010byte-00x7fbyte-10x7fbyte-20x54byte-30x01byte-40x7abyte-50x6aToy XOR rows - changed byte 4rowvaluecheckplaintext7061793d3130pinned byteskeystream0f1e2d3c4b5apinned bytesciphertext7f7f54017a6aplaintext xor keystreamtarget plaintext7061793d3930attacker targetattack mask000000000800plaintext xor targetmodified ciphertext7f7f5401726aciphertext xor maskdecrypted modified7061793d3930modified ciphertext xor keystream