CS Master

Unit 3: Data & Encryption (Chapters 12, 13, 14 & 15)

Chapter 12: Binary

1. Why Binary?

Computers use transistors that act as switches (On=1, Off=0). This is why they use binary. Analogue signals are continuous, while digital signals are discrete (fixed values).

2. Two's Complement & Shifts

  • Two's Complement: Represents negative numbers. Flip all bits and add 1 (e.g., +45 is 00101101, so -45 is 11010011).
  • Logical Shift: Left shift multiplies by 2 per place (fills with 0s). Right shift divides by 2 (fills with 0s).
  • Arithmetic Shift: Used for signed numbers. Right shift fills with the MSB (Most Significant Bit) to preserve the sign.

3. Hexadecimal

Base-16 system (0-9, A-F). Easier for humans to read than binary. 1 hex digit = 4 bits (a nibble).

🎮 Game: Binary to Denary

🎮 Game: Hex Converter

Chapter 13: Data Representation

1. Text (ASCII & Unicode)

  • ASCII: 7-bit (128 chars) or 8-bit Extended. 'A'=65, 'a'=97 (difference is 32).
  • Unicode: 2 or 4 bytes. Used for universal standard (all languages).

2. Images (Bitmap)

  • Pixel: Smallest single point of colour.
  • Resolution: Number of pixels per inch (Width x Height).
  • Colour Depth: Number of bits per pixel (e.g., 24-bit true colour = 16.7M colours).
  • File Size: Width × Height × Colour Depth (bits). Divide by 8 for bytes.

3. Sound

  • Sampling: Snapshots of an analogue wave.
  • Sample Rate: Samples per second (e.g., 44.1 kHz). Higher rate = better fidelity.
  • Bit Depth: Bits per sample (e.g., 16-bit).
  • File Size: Sample Rate × Bit Depth × Duration (secs) × Channels.

🎮 Game: ASCII Decoder

🎮 Game: Image Size Calculator

Calculate the file size in bytes. (Width × Height × Depth) / 8.

Chapter 14: Compression

1. Storage Units

  • Decimal (SI): 1 KB = 1000 bytes, 1 MB = 1,000,000 bytes.
  • Binary (IEC): 1 KiB = 1024 bytes, 1 MiB = 1024 KiB.

2. Types of Compression

  • Lossless: No data is lost. Original file can be restored perfectly. Essential for text and code. (e.g., ZIP, PNG).
  • Lossy: Some data is permanently removed to significantly reduce size. Acceptable for images and audio where the human eye/ear won't notice. (e.g., JPEG, MP3).

3. Run-Length Encoding (RLE)

A lossless algorithm that replaces runs of repeating characters with a count and the character. Example: aaaabbbcc becomes 4a3b2c.

🎮 Game: RLE Encoder

Encode the string below. Use the format count + letter (e.g., 4a2b).

Chapter 15: Encryption

1. Encryption Concepts

  • Symmetric: Same key to encrypt and decrypt (used in HTTPS for bulk data).
  • Asymmetric: Public key to encrypt, Private key to decrypt (used to share the symmetric key).

2. Caesar Cipher

Shifts letters by a set number of places. Key of +3 turns 'A' into 'D'.

3. Vigenère Cipher

Polyalphabetic cipher using a keyword. The keystream (repeated keyword) shifts each letter by a different amount.

4. Rail Fence Cipher

Transposition cipher. Writes the plaintext in a zigzag pattern across a set number of rows (the key), then reads row by row.

🎮 Game: Caesar Cipher Decoder

🎮 Game: Encryption Quiz