Converting a Decimal Number to Binary Methods


  1. Method 1: Divide by 2 Shortcut (Most Common and Easiest)

    1. This is the method most people use mentally or on paper.
    2. Steps:
      1. Divide the number by 2.

        1. Write down the remainder (it will be 0 or 1).
        2. Use the quotient (the result of the division) and repeat the steps until the quotient becomes 0.
        3. The binary is the remainders read from bottom to top.
      2. Example: Convert 13 to binary

        Division Quotient Remainder
        13 ÷ 2 6 1
        6 ÷ 2 3 0
        3 ÷ 2 1 1
        1 ÷ 2 0 1
      3. When the quotient is 0, stop.

      4. Now read remainders from bottom to top:

        1. → 1101
      5. So, 13 (decimal) = 1101 (binary)


  2. Method 2: Tip for Small Numbers (Head Method):

    1. You can memorize powers of 2:

      Power of 2 Value
      2⁷ 128
      2⁶ 64
      2⁵ 32
      2⁴ 16
      8
      4
      2
      2⁰ 1
    2. Example: Convert 19 to binary using powers of 2

      1. 19 ≥ 16 → 1
      2. 19 - 16 = 3
      3. 8 > 3 → 0
      4. 4 > 3 → 0
      5. 2 ≤ 3 → 1 → 3 - 2 = 1
      6. 1 = 1 → 1
    3. Write it:

      1. 16 8 4 2 1
      2. 1 0 0 1 110011

Vernam Cipher in Cryptography


  1. What is Vernam Cipher?

    1. The Vernam Cipher is a symmetric key cryptographic technique invented in 1917 by Gilbert Vernam.
    2. It’s also known as the One-Time Pad Cipher when the key is truly random and as long as the message.
    3. In simple words:
      1. It hides a message by combining it with a secret random key using the XOR operation (Exclusive OR).
    4. Key Principles
      1. Plaintext (P): The original message we want to protect.
        1. Example: HELLO
      2. Key (K): A random set of letters/numbers (same length as plaintext).
        1. Example: XMCKL
      3. Ciphertext (C): The encrypted message.
        1. Example: Something unreadable like EQNVZ.

  2. Vernam Cipher (Using XOR)

    Bit P Bit K Result (C = P ⊕ K)
    0 0 0
    0 1 1
    1 0 1
    1 1 0

    So, XOR flips bits when the key bit = 1, and keeps bits the same when the key bit = 0.


  3. How it Works (Step by Step)

    1. Assign numbers to alphabets (A=0, B=1, …, Z=25).
    2. Convert both the Plaintext and the Key to numbers.
    3. Combine them using XOR (⊕).
    4. Convert the numbers back to alphabets → that gives you the Ciphertext.
    5. To decrypt, apply the same key again → you get back the original plaintext.
    6. Alphabet to Number Mapping
      1. Here’s the full mapping table:

        A = 0 (00000)   B = 1 (00001)   C = 2 (00010)   D = 3 (00011)
        E = 4 (00100)   F = 5 (00101)   G = 6 (00110)   H = 7 (00111)
        I = 8 (01000)   J = 9 (01001)   K = 10 (01010)  L = 11 (01011)
        M = 12(01100)   N = 13(01101)   O = 14(01110)   P = 15(01111)
        Q = 16(10000)   R = 17(10001)   S = 18(10010)   T = 19(10011)
        U = 20(10100)   V = 21(10101)   W = 22(10110)   X = 23(10111)
        Y = 24(11000)   Z = 25(11001)
        
      2. Each letter is represented in 5 bits.


  4. Example 1

  5. Example 2:

  6. Summary