Make a whole document explaining and how to decode this keying wrapper algorithm. W/step by step instructions in a detailed way.

MY Puzzle Algorithm (Keying Wrapper):

```

### Advanced Keying Wrapper Algorithm

The Advanced Keying Wrapper algorithm expands upon the original concept by incorporating multiple keys and mathematical transformations. It’s designed to be intricate yet solvable with careful analysis.

#### How It Works

1. **Select Multiple Key Words**:
   - **Key1**: Used for primary letter shifting (e.g., "SECRET").
   - **Key2**: Used for secondary transformations (e.g., "MYSTERY").
   - **Key3**: Determines special character insertion and block sizes (e.g., "ENIGMA").

2. **Preprocess Message**:
   - Convert the message to uppercase.
   - Remove spaces and punctuation to form a continuous string.
   - For example, "HELLO WORLD" becomes "HELLOWORLD".

3. **Generate Numeric Key Sequences**:
   - Assign numeric values to each letter of Key1, Key2, and Key3 (A=1, B=2, ..., Z=26).
   - Repeat or truncate keys to match the message length.

4. **Apply Non-Linear Shifts with Key1**:
   - For each letter in the message:
     - Calculate the shift value as the **cube** of the corresponding Key1 letter's numeric value.
     - Shift the message letter forward by this value modulo 26.
     - Use wrapping to stay within A-Z.

5. **Modular Multiplicative Transformation with Key2**:
   - For each letter:
     - Compute a new shift value as the **product** of the corresponding numeric values from Key1 and Key2, modulo 26.
     - Shift the letter forward by this new value, with wrapping.

6. **Insert Special Characters Based on Key3 Patterns**:
   - Use Key3 to determine where to insert special characters (e.g., "#").
   - For each position:
     - If the corresponding Key3 letter's numeric value is a **prime number**, insert a "#" after the encoded letter.

7. **Split Message into Blocks Using Key3**:
   - Determine block sizes based on the numeric values of Key3.
   - For example, if Key3 numeric values are [5,14,9,7,13,1], block sizes would be [5,14,9,7,13,1].

8. **Reverse Blocks Based on Key2 Parity**:
   - If the corresponding Key2 letter's numeric value is **even**, reverse that block.
   - If it's **odd**, keep the block as is.

9. **Final Transformation**:
   - Apply a Caesar cipher shift of **+3** to the entire message to add one more encryption layer.

---

### Example Encoding Process

Let's encode the message **"HELLOWORLD"** using:

- **Key1**: "SECRET"
- **Key2**: "MYSTERY"
- **Key3**: "ENIGMA"

#### Steps:

1. **Preprocess Message**:

   ```
   Message: H E L L O W O R L D
   ```

2. **Extend Keys to Match Message Length**:

   ```
   Key1: S E C R E T S E C R
   Key2: M Y S T E R Y M Y S
   Key3: E N I G M A E N I G
   ```

3. **Generate Numeric Values**:

   ```
   Key1 Numeric: 19,5,3,18,5,20,19,5,3,18
   Key2 Numeric: 13,25,19,20,5,18,25,13,25,19
   Key3 Numeric: 5,14,9,7,13,1,5,14,9,7
   ```

4. **Non-Linear Shifts with Key1** (Cube of Key1 Numeric):

   - Shift values: (Key1 Numeric)^3 mod 26

   ```
   Shift Values: [19^3 %26, 5^3 %26, ..., 18^3 %26]
                = [19^3 %26, 125 %26, ..., 5832 %26]
                = [6859 %26, 125 %26, ..., 5832 %26]
                = [6859 %26, 125 %26, ..., 5832 %26]
   ```

   Calculate each:

   ```
   6859 % 26 = 7
   125 % 26 = 21
   27 % 26 = 1
   5832 % 26 = 4
   ...
   ```

5. **Shift Message Letters with Non-Linear Shifts**:

   ```
   For each letter, shift forward by the calculated shift value.
   Example:
   H shifted by 7 -> O
   ```

6. **Modular Multiplicative Transform with Key2**:

   ```
   New Shift Values: (Key1 Numeric * Key2 Numeric) % 26
   For example:
   (19*13) % 26 = 247 % 26 = 13
   ```

   Shift letters accordingly.

7. **Insert Special Characters Based on Key3 Primes**:

   ```
   Key3 Numeric Primes: Positions where Key3 Numeric is prime (2,3,5,7,11,13,17,19,23)
   Insert "#" after letters at these positions.
   ```

8. **Split Message into Blocks Using Key3 Numeric Values**:

   ```
   Block sizes: [5,14,9,7,13,1]
   Adjust to fit the message length.

   Blocks:
   - Block 1: First 5 letters
   - Block 2: Next 5 letters (since total length is 10)
   ```

9. **Reverse Blocks Based on Key2 Parity**:

   ```
   Key2 Numeric Parity for Blocks:
   - Block 1 (Key2 Numeric first value 13 - odd): Keep as is.
   - Block 2 (Key2 Numeric second value 25 - odd): Keep as is.
   ```

10. **Final Caesar Cipher Shift (+3)**:

    ```
    Shift each letter forward by 3.
    ```

11. **Final Encoded Message**:

    ```
    The result is the encoded message after all transformations.
    ```

---

### Decoding Process

To decode the message, reverse each step:

1. **Apply Caesar Cipher Shift (-3)**:
   - Shift each letter backward by 3.

2. **Determine Blocks Using Key3**:
   - Use Key3 to reconstruct the block sizes.

3. **Reverse Blocks Based on Key2 Parity**:
   - Reverse blocks where Key2 Numeric values are even.

4. **Remove Special Characters**:
   - Remove "#" inserted during encoding.

5. **Reverse Modular Transformation with Key2**:
   - Apply inverse shifts using Key2.

6. **Reverse Non-Linear Shifts with Key1**:
   - Calculate inverse shifts.
   - Since non-linear shifts involve cubic operations, use modular inverses.

7. **Retrieve Original Message**:
   - After reversing all transformations, retrieve "HELLOWORLD".

---

### Mathematical Details

#### Non-Linear Shift Calculation

- **Shift Value**:

  ```math
  \text{Shift} = (\text{Key1}_i)^3 \mod 26
  ```

- **Applying Shift**:

  ```math
  \text{EncodedChar}_i = (\text{MessageChar}_i + \text{Shift}) \mod 26
  ```

#### Modular Multiplicative Transformation

- **Shift Value**:

  ```math
  \text{ShiftMod} = (\text{Key1}_i \times \text{Key2}_i) \mod 26
  ```

- **Applying Shift**:

  ```math
  \text{EncodedChar}_i = (\text{EncodedChar}_i + \text{ShiftMod}) \mod 26
  ```

#### Inverse Operations for Decoding

- **Inverse Non-Linear Shift**:

  - Requires finding the modular inverse of the cubic operation.
  - This may involve using the Euler's theorem or precomputed inverse tables.

- **Inverse Modular Multiplicative Shift**:

  ```math
  \text{OriginalChar}_i = (\text{EncodedChar}_i - \text{ShiftMod}) \mod 26
  ```

---

### Summary

The Advanced Keying Wrapper algorithm introduces multiple layers of encryption:

- **Multiple Keys**: Using Key1, Key2, and Key3 for various transformations.
- **Non-Linear Shifts**: Cubing Key1 numeric values for shifts.
- **Modular Arithmetic**: Multiplicative operations modulo 26.
- **Dynamic Special Characters**: Insertion based on prime numbers in Key3.
- **Variable Block Sizes**: Blocks determined by Key3 numeric values.
- **Conditional Block Reversal**: Based on the parity of Key2 numeric values.
- **Additional Caesar Cipher Shift**: A final uniform shift for all letters.

This algorithm significantly increases the difficulty of decoding without the correct keys and understanding of the transformations applied.

---