Skip to main content
IoT
PSUT Engineering StudioPrincess Sumaya University for Technology
Student Edition
Cyber Defense StudioIoT Security and PrivacyExperimentsWorkspaces
Home / IoT Security and Privacy / Cryptography Engineering
IoTPSUT IoT Engineering StudioPrincess Sumaya University for Technology · Dr. Mohammad Alja’afreh
CRYPTOGRAPHY ENGINEERING · CR04 · DES
IoT Security and Privacy

DES · S-box row and column

Each 6-bit input \(b_{1}\)…\(b_{6}\) maps to four output bits.

CR04 · Laboratory mentorAsk about the current operation and its intermediate values.
CR04 · Academic orientation

Scope and objectives

Scope of the experiment

A DES S-box maps six input bits to four output bits. The outer bits select one of four rows; the middle bits select one of sixteen columns. Eight distinct tables break linear relationships; the S-box is public, not a secret key.

The focus of this experiment is to partition a six-bit DES S-box input into row and column indices. Students then calculate four-bit output using the selected S-box table, and compare different boxes and explain nonlinear substitution. The Concepts view explains the operation before the practical work; the Simulation view is used to examine reference and changed inputs, not to substitute for actual measurements.

Learning objectives

  • Partition a six-bit DES S-box input into row and column indices.
  • Calculate four-bit output using the selected S-box table.
  • Compare different boxes and explain nonlinear substitution.
  • Record the relevant inputs, intermediate states and final verification result before changing the reference configuration.
  • Compare the reference calculation or decision with an independent implementation or authorized observation; state any discrepancy and the applicable model boundary.

Expected learning outcomes

On completion, students can partition a six-bit DES S-box input into row and column indices, calculate four-bit output using the selected S-box table, and compare different boxes and explain nonlinear substitution.

Required deliverables

Submit the derivation or state trace for the named operation, the exact reference and changed configurations, the associated simulator or practical evidence, and a short validation statement addressing compare different boxes and explain nonlinear substitution. Separate predicted values from observations.

Prerequisite knowledge and related learning

Use the curriculum sequence and the Concepts section for prerequisite terminology. After completion, continue to DES · PC-1, rotations and PC-2.

Environment and experimental methodology

A standard browser and the experiment-specific Python implementation or Colab notebook. Where the practical uses a protocol model, model results are distinguished from actual local cryptographic operations.

Begin with a manual prediction, record the baseline, change one independent condition at a time, and compare the resulting trace or measurements with the original prediction. Record observations and uncertainty separately from reference values. Follow the experiment’s specific procedure, safety limits, and acceptance checks.

01 · Experiment overview

CR04 · DES · S-box row and column

Each 6-bit input \(b_{1}\)…\(b_{6}\) maps to four output bits. Row = 2b₁+\(b_{6}\); column = binary \(b_{2}\)…\(b_{5}\). The eight boxes differ. A nonlinear substitution is not a permutation of all 64 inputs.

Before starting

Environment: standard computer, browser and Python/WSL.

Simulation: Editable JavaScript calculation

Technical scope: Classroom computation on a standard computer. Educational cipher code is not a production security implementation.

Complete the six stages in order. Use the same experiment inputs when comparing manual, browser and Python results.

02 · Concepts and mathematical foundations

Each 6-bit input \(b_{1}\)…\(b_{6}\) maps to four output bits. Row = 2b₁+\(b_{6}\); column = binary \(b_{2}\)…\(b_{5}\). The eight boxes differ. A nonlinear substitution is not a permutation of all 64 inputs.

Learning objectives

Calculate the named operation, inspect its intermediate values, reproduce the result in Python, and explain one controlled change. Prerequisites: binary/hexadecimal arithmetic; complete preceding labs in the same topic where applicable.

Before starting

Environment: standard computer, browser and Python/WSL.

Simulation: Editable JavaScript calculation

Technical scope: Classroom computation on a standard computer. Educational cipher code is not a production security implementation.

Nonlinear substitution

1 · Principles and purpose

A DES S-box maps six input bits to four output bits. The outer bits select one of four rows; the middle bits select one of sixteen columns. Eight distinct tables break linear relationships; the S-box is public, not a secret key.

2 · Mathematical and algorithmic foundations

For integer v in 0…63, row=2·bit5+bit0; column=(v>>1)&15. Lookup \(S_{i}\)[row,column], then encode in exactly four bits including leading zeros.

3 · Worked teaching example

For input 011000, outer bits 00 select row 0 and inner bits 1100 select column 12. S1 gives 5=0101. The table, not an ordinary arithmetic formula, defines this transformation.

Verified default trace · 4 intermediate states

Given parameters (teaching example):

{
  "box": "1",
  "input": "0x2C"
}
StageComputed values
1{ "step": "Input", "bits": "101100" }
2{ "step": "Outer bits", "bits": "10", "index": 2 }
3{ "step": "Inner bits", "bits": "0110", "index": 6 }
4{ "step": "Lookup", "box": 1, "row_index": 2, "column": 6, "output": "0010" }

Recorded result

{
  "output": "0010",
  "decimal": 2
}

Captured earlier local execution. Randomized values and timing can differ; compare the invariant.

4 · Verification and experimental interpretation

Step through the following visualization and compare the named operation with the corresponding computed state. Check the mathematical invariant, inverse operation or protocol acceptance condition. Change one input at a time; distinguish a measured output from a prediction.

Mathematical representation and interpretation

DES substitution and round processing

A six-bit input selects one of four rows using its outer bits and one of sixteen columns using its inner bits. S_j is the selected DES substitution table; v is a four-bit result.

\[r=2b_1+b_6,\qquad c=8b_2+4b_3+2b_4+b_5,\qquad v=S_j[r,c]\]

Input 011011 selects row 1 and column 13; use the selected table to read the output.

Concept animation · DES S-box selection

Explore the teaching example independently of the simulator. Each step reveals an operation, data relationship or calculated state. The Simulation view has separate editable inputs.

DES · S-box row and column: DES S-box selectionS1 receives 6 bits101100Outer bits → row 2 · Inner bits → column 6012345678910111213141501441312151183106125907101574142131106121195382411481362111512973105031512824917511314100613Follow the selected row and column.

Step 1 of 4 · Split six-bit input

Split six-bit input

Input
101100

Teaching example only; inspect live calculations or real practical evidence separately.

Shared research workbenches · network designer & advanced studies
Concurrent-device simulation & Monte Carlo research
Distributed digital twin · topology, protocol & battery research

03 · Interactive simulation

Baseline diagram loaded. Interactive engine initializing…

Verified baseline reference — use the live workstation below to explore steps and compare inputs.
CR04 calculated stateDES S-box · outer bits select row, inner bits select column101100Row = b1 || b610 = 2Column = b2…b50110 = 6S1[2,6]2 → 00106-bit input → table lookup → 4-bit output

Edit the fields and choose Recompute. Use step controls to inspect real calculated states. Hexadecimal byte fields are written without 0x; numeric fields accept decimal or 0x notation.

Calculated result

{
  "output": "0010",
  "decimal": 2
}
All intermediate trace rows

Guided simulation activity

Use the baseline inputs shown above. Predict a result, advance one operation at a time, inspect the intermediate state, then change only the parameter specified in the Experiments view. Export the trace and compare it with your manual derivation.

Continue to practical experiments →

04 · Experiments and engineering investigations

Analytical preparation — before Python

Each 6-bit input \(b_{1}\)…\(b_{6}\) maps to four output bits. Row = 2b₁+\(b_{6}\); column = binary \(b_{2}\)…\(b_{5}\). The eight boxes differ. A nonlinear substitution is not a permutation of all 64 inputs.

Predict the baseline result before revealing the calculated state. A controlled comparison changes the named input while keeping the other conditions fixed. Record an observed value separately from an expected value.

Part A · Independent theoretical exercises

Complete each question before running the simulator or Python. Show calculations or protocol traces. The teaching example is a method, not a substitute for the assigned values.

01 · Application and derivation

Application and derivation · Independent work

For S1 inputs 011011 and 101100, identify the outer bits and inner bits, convert to row/column indices, then use the S1 table to derive the four output bits. Repeat with S2 and explain why the same input can yield a different output.

02 · Lookup analysis

Lookup analysis · Independent work

For S1 input 111111, derive row, column and output. What is the effect of toggling only the first bit?

Required evidence: state the expected invariant or acceptance condition; record hand-derived results, compare with the simulator or Python trace, and explain the first discrepancy. Do not report a predicted value as a measurement.

Expanded independent theoretical exercise bank

Progress from calculation and interpretation to diagnosis and controlled engineering design. Complete the questions without opening the simulation first; show intermediate steps.

Intermediate · Alternate configuration

Independent theoretical exercise · CR04-01

For the separate teaching-test configuration box: 1; input: 0x2D, predict decimal using the relevant operation or decision rule. Show intermediate work and state whether this is a deterministic result.

Intermediate · Interpret a computation state

Independent theoretical exercise · CR04-02

A teaching trace for DES · S-box row and column contains step: Outer bits; bits: 10; index: 2. Explain the role of index (recorded value 2) and identify the rule or input that determines it. Distinguish an intermediate state from the final result.

Advanced · Identify a terminal invariant

Independent theoretical exercise · CR04-03

The first teaching trace contains step: Input; bits: 101100; the last contains step: Lookup; box: 1; row_index: 2; column: 6; output: 0010. Identify one distinction between the initial operation and completion. What additional condition must hold to use the result?

Challenging · Controlled algorithm verification

Independent theoretical exercise · CR04-04

Plan a comparison of box: 1; input: 0x2C with box: 1; input: 0x2D. Record the dependent value output, identify the changed factor(s), and describe the verification and failure criterion without claiming a real security measurement.

Part B · Guided simulation and practical procedure

Before starting — tools and setup

Standard computer; extract the WSL toolkit into a new directory. For the browser activity, use the integrated workstation. Editable browser calculation

Install Python dependencies only if required by the selected toolkit README. Use its requirements file and virtual environment instructions.

Open complete, verified WSL commands in Part C ↓

01

Compute a DES S-box output

  1. Use the exact baseline input below and write a prediction.
  2. Use S1 and input 0x2C (101100). Extract outer bits 10 and inner bits 0110. Locate row 2, column 6; write the four-bit output.
  3. Save the trace and compare it with the reference output.

Experimental inputs

Experimental reference · json
{"box":"1","input":"0x2C"}
Verified baseline reference (check after predicting)
Experimental reference · json
{"output":"0010","decimal":2}

For S1(0x2C), row=2, column=6, output=0010. Check every lookup against the standard table.

Evidence to record

S-box, input six bits, row, column, decimal lookup and four-bit result.

Run baseline →
02

Part D · Controlled investigation

  1. Keep S1 and compare inputs 0x00, 0x2D and 0x3F. Then keep 0x2C and switch to S2.
  2. Record the conditions held fixed: the other parameter
  3. Collect S-box, input six bits, row, column, decimal lookup and four-bit result. Compare the first differing intermediate step and explain the relationship.
TrialInput configurationPredictionObservedVerification
1{"box":"1","input":"0x2C"}
2{"box":"1","input":"0x2D"}

Use the table as a recording template; enter your own measured values in the field below or reproduce it in your report.

Return to simulation →
03

Part E/F · Independent Python verification and deliverables

  1. Download the notebook or toolkit and run the default example.
  2. Reproduce at least one changed input; compare the intermediate values with the browser where supported.
  3. Complete the independent assessment below without copying the worked baseline. Explain discrepancies and distinguish mathematical results from security claims.
Additional investigation instructions

A controlled comparison changes one independent input while holding other inputs fixed, then measures its effect on the dependent output. A baseline is the unmodified run. Evidence-based reasoning means citing the actual observed values, not merely asserting that an algorithm is secure.

  1. Run the supplied default values and record the first and final state.
  2. Predict the effect before changing anything. Change input 0x2C to 0x2D; then box 1 to 2. First verified alternate: {"input": "0x2D"}.
  3. Keep the other parameter.
  4. Measure six input bits, row, column, four output bits.
  5. Restore the baseline and repeat with another valid input. Locate the first differing calculation.
  6. Submit a comparison table, a trace JSON or screenshots of relevant steps, and a short conclusion with an explicit limitation.
TrialChanged inputFixed conditionsPredictionMeasured valueReason / limitation
BaselineNoneDefaultStudent predictionRecord traceExplain
Trial 1Specified changeUnchanged inputsStudent predictionRecord traceExplain

Part C · Python, Google Colab and WSL

The standalone implementation uses the same synthetic baseline and calculations as the browser. In Colab, download the notebook, open Colab and upload it using File → Upload notebook. Run all cells in order.

WSL / Linux execution workflow

Use Ubuntu or Kali WSL, not PowerShell. Download the toolkit above to your computer. If Python, venv or unzip is missing, install these prerequisites once (requires administrator permission and network access).

Optional prerequisites · bash
sudo apt update
sudo apt install -y python3 python3-venv unzip

In WSL, enter the actual downloaded ZIP path when prompted (for example, a file under /mnt/c/Users/…/Downloads). Extract to a new, dedicated directory. If this directory already exists from a previous extraction, use the existing verified toolkit or choose a clean directory rather than overwriting it.

Step 1 · Extract · bash
read -r -p "Full path to PSUT_V22_9_9_Cryptography_WSL.zip: " ZIP
DEST="$HOME/psut-crypto-v22.9.9"
if [ -f "$ZIP" ] && [ ! -e "$DEST" ]; then
    mkdir "$DEST" && unzip "$ZIP" -d "$DEST"
else
    echo "Check ZIP path and use a fresh destination."
fi

Create the isolated environment in the extracted toolkit root, activate it, then enter this experiment’s actual folder. Install only its declared dependencies. A comment-only requirements file requires no third-party packages.

Step 2 · Activate and install · bash
cd ~/psut-crypto-v22.9.9
python3 -m venv .venv
source .venv/bin/activate
cd CR04
ls
python -m pip install -r requirements.txt

Execute the default run and save the genuine program output. Then run the supplied regression test and the baseline fixture through the explicit input interface.

Step 3 · Run and verify · bash
python lab.py | tee my-results.json
python test_lab.py
python lab.py --params example-input.json
python -m json.tool my-results.json

To change inputs, copy example-input.json, edit the copy in a text editor and run the command below. The original fixture is preserved.

Step 4 · Change an input · bash
cp example-input.json my-input.json
# Edit my-input.json with your preferred editor.
python lab.py --params my-input.json

These scripts terminate normally. Use Ctrl+C to stop a long-running calculation if needed. When finished, leave the isolated virtual environment; no global service cleanup is required for these local examples.

Step 5 · Finish · bash
deactivate

Declared dependencies: # Standard library only for core experiment

Expected terminal output — captured local execution

This excerpt contains the actual first trace step and final result from python lab.py, followed by the actual regression test output. Full stdout is in CR04/verified-output.txt inside the toolkit. Timing, random signatures, keys, certificate fields and implementation-dependent sizes can vary; compare the invariant and record your own observations.

Verified execution excerpt · text
{
  "first_step": {
    "step": "Input",
    "bits": "101100"
  },
  "result": {
    "output": "0010",
    "decimal": 2
  }
}

Test script output:
PASS

Check the output JSON and the test exit status. An assertion error means the expected invariant was not met. If Python reports a missing module, activate the environment and install the experiment’s requirements file; if a file is missing, check pwd and ls.

Inspect the documented Python implementation
Documented Python implementation · python
# ============================================================
# CR04 | Educational implementation and trace functions
# Copyright © 2026/2027 Dr. Mohammad Alja’afreh
# PSUT IoT Engineering Studio | Educational, synthetic inputs
# ============================================================
def row(label,**values): return {'step':label,**values}

# Standard DES lookup table: S
S=[[14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13], [15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9], [10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12], [7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14], [2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3], [12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13], [4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12], [13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]]

# Use outer input bits for row and middle four bits for column.
def dsbox(n,b):
    r=((b>>5)<<1)|(b&1); c=(b>>1)&15
    return r,c,S[n][16*r+c]

def n(s): return int(s,0)

def b(s): return bytes.fromhex(s)

def pack(result,trace): return {'result':result,'trace':trace}

EXTRA = {}

def run(p):
    i=n(p['box']); v=n(p['input'])
    if not 1<=i<=8 or not 0<=v<64: raise ValueError('Box 1–8, input 0–63')
    r,c,o=dsbox(i-1,v); bits=f'{v:06b}'
    return pack({'output':f'{o:04b}','decimal':o},[row('Input',bits=bits),row('Outer bits',bits=bits[0]+bits[-1],index=r),row('Inner bits',bits=bits[1:5],index=c),row('Lookup',box=i,row_index=r,column=c,output=f'{o:04b}')])

PARAMS = {'box': '1', 'input': '0x2C'}
EXPECTED = {'output': '0010', 'decimal': 2}
ALT = {'box': '1', 'input': '0x2D'}
ALT_EXPECTED = {'output': '0001', 'decimal': 1}

if __name__ == "__main__":
    import argparse, json
    parser=argparse.ArgumentParser(description="CR04 synthetic cryptography exercise")
    parser.add_argument("--params", help="JSON parameter override file")
    parser.add_argument("--test", action="store_true")
    args=parser.parse_args()
    if args.test:
        assert run(PARAMS)["result"] == EXPECTED
        assert run(ALT)["result"] == ALT_EXPECTED
        print("CR04 default and changed input passed")
    else:
        parameters=PARAMS if not args.params else {**PARAMS,**json.load(open(args.params))}
        print(json.dumps(run(parameters),indent=2))
Verified default result
Reference result · json
{
  "output": "0010",
  "decimal": 2
}

05 · Interactive flashcards

Recall before revealing. Review and mastery ratings remain on this device.

Browse all explanations
Which two bits determine the row?

The first and last bits, not the first two.

What is the dependent variable in this lab?

six input bits, row, column, four output bits

What must remain controlled?

the other parameter

What input settings define the baseline for this experiment?

box = 1; input = 0x2C

What is the first intermediate state in the baseline?

step: Input; bits: 101100

What check must you reproduce before varying the inputs?

For S1(0x2C), row=2, column=6, output=0010. Check every lookup against the standard table.

Which observations belong in your experimental record?

S-box, input six bits, row, column, decimal lookup and four-bit result.

06 · Knowledge assessment

Formative check

Which experimental design best isolates the effect of the specified input?

Responses are for instructor review; no grading key is provided here.

Independent assessment

For S-box 3, calculate outputs for 0x11 and 0x31 using the first/last bit rule. Explain which index changes and why the two output values need not differ by one bit. Use an additional valid trial, a calculation or a counterexample to support your reasoning. Submit evidence from both runtimes and explain what the experiment does not establish.

Part F · Engineering evidence record

Record the baseline, prediction, changed input, observed result, discrepancy and limitation. Save locally or export with the displayed result. This is not an official submission.

All Cryptography Engineering labsNext laboratory · CR05 →

How to investigate · CR04

Independent variable: input 0x2C to 0x2D; then box 1 to 2.

Controlled variables: the other parameter.

Dependent evidence: six input bits, row, column, four output bits.

Weak conclusion: “The output changed.” Stronger reasoning: cite both measured values, name the transformation responsible, and state why the observation does or does not generalize.

Dr. Mohammad · CR04

Offline, deterministic, current-step tutoring. No external AI service or real hardware access.