Skip to main content
IoT
PSUT Engineering StudioPrincess Sumaya University for Technology
V21.6.5 · Student / connected
Cyber Defense StudioIoT Security and PrivacyExperimentsWorkspaces
Home / IoT Security and Privacy / EC04
IoTPSUT IoT Engineering StudioPrincess Sumaya University for Technology · Dr. Mohammad Alja’afreh
ESSENTIAL LABORATORY · EC04 · IoT SECURITY AND PRIVACY
IoT Security and Privacy

Modular arithmetic II — Euclid, totient, Affine and Hill

Compute greatest common divisors and modular inverses, evaluate powers efficiently, and apply number theory to classical ciphers.

Design experiment & verify evidence →
EC04 · Laboratory mentorAsk about the current experiment, its algorithms or Python notebook.
Ask Dr. MohammadAdaptive practice
EC04 · Academic orientation

Scope and objectives

Scope of the experiment

Compute greatest common divisors and modular inverses, evaluate powers efficiently, and apply number theory to classical ciphers.

The focus of this experiment is to calculate gcd, Bézout coefficients and Euler totient. Students then derive invertible Affine and Hill transformations under stated moduli, and verify inverse recovery and reject noninvertible keys. 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

  • Calculate gcd, Bézout coefficients and Euler totient.
  • Derive invertible Affine and Hill transformations under stated moduli.
  • Verify inverse recovery and reject noninvertible keys.
  • 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 calculate gcd, Bézout coefficients and Euler totient, derive invertible Affine and Hill transformations under stated moduli, and verify inverse recovery and reject noninvertible keys.

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 verify inverse recovery and reject noninvertible keys. Separate predicted values from observations.

Prerequisite knowledge and related learning

Review the foundational terminology in Concepts and confirm readiness using the existing setup instructions. After completion, continue to Stream ciphers — Polynomials and LFSRs.

Environment and experimental methodology

The included teaching workstation and the listed Python/Colab or WSL implementation. Historical and small-number constructions are instructional, not deployment recommendations.

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.

How to investigate Modular arithmetic II — Euclid, totient, Affine and Hill

Compute greatest common divisors and modular inverses, evaluate powers efficiently, and apply number theory to classical ciphers.

Analytical investigation means collecting an observation, identifying the mechanism, using a calculation or state trace to explain it, and checking your conclusion against evidence. Controlled comparison means changing one independent variable, holding the remaining relevant conditions constant, and measuring a dependent variable against a baseline. Experimental validation means comparing a predicted result to a reproducible observation or assertion; agreement inside a model does not certify hardware. Evidence-based reasoning connects a specific observation to a theoretical rule and states uncertainty, not merely an opinion. Performance characterization records a named metric and its units across conditions; sensitivity analysis changes one parameter across several values. A threat assessment links an asset, threat, consequence and evidence to a mitigation.

Experiment-specific guided practice

Objective: Compute greatest common divisors and modular inverses, evaluate powers efficiently, and apply number theory to classical ciphers.

  1. Complete the analytical preparation below before programming. Show the intermediate mathematical calculations.
  2. Euclidean and extended Euclidean algorithms — complete its numbered steps and record the requested evidence.
  3. Totient and modular powers — complete its numbered steps and record the requested evidence.
  4. Affine encryption and decryption — complete its numbered steps and record the requested evidence.

Reference check: gcd(12456,7272)=72; inverse(7,26)=15; the second Hill key has determinant 8 and is not invertible mod 26.

Model boundary: Fictional educational inputs. Browser algorithms and reference programs; no hardware or live-network measurements. Supplied starter notebooks may be incomplete; trace playback is recorded execution, not arbitrary Python running in browser.

Independent task and submission evidence

2. Euclidean and extended Euclidean algorithms — complete its numbered steps and record the requested evidence. Record the named input, prediction, actual output and one limitation; restore the original condition and repeat.

Before execution write the independent variable and its levels, dependent observation with units where applicable, baseline, controlled variables, measurement method and expected result. For a state machine use state/event/output rather than inventing a numeric metric. Record failures and repeat the baseline. A weak conclusion is “it works”; a supported conclusion names the changed setting, observed value/state, corresponding rule and one limitation.

TrialChanged settingFixed settingsPredicted resultActual observation / unitsEvidence / uncertainty
A: baselineReferenceRecordPredictRecordRecord
B: one changeRecordSame as APredictRecordRecord
A: repeatRestoreSame as APredictRecordRecord

Completion: submit the filled table, relevant simulator screenshot or terminal/notebook output, reasoning with units/assumptions, and one limitation. Preserve the independent assessment questions; this guide does not fill their answers.

Scientific concepts and engineering principles

Scientific architecture · EC04 · Modular arithmetic II — Euclid, totient, Affine and Hill

Euclid and modular inverse — Operands / 26 and 7; Divide / 26=3·7+5; 7=1·5+2; Continue / 5=2·2+1; Back substitute / 1=3·26−11·7; Inverse / 7⁻¹ mod 26 = 15
Scientific concept map: Integer pair — a,b; Euclid — Remainder sequence; Bézout — ax+by=gcd; Inverse — If gcd=1; Affine / Hill — Modular transform.

GCD and inverse

Euclid reduces (a,b) to (b,a mod b) until the second operand is zero. Extended Euclid additionally computes integers s,t with sa+tb=gcd(a,b). The inverse of a modulo m exists exactly when gcd(a,m)=1; in that case s mod m is the inverse.

Totient and modular powers

For n>1 with distinct prime divisors p, φ(n)=n∏(1−1/p). Square-and-multiply evaluates a^e mod m while keeping intermediate values bounded. Euler’s theorem applies when gcd(a,m)=1; Fermat’s little theorem is its prime-modulus special case.

Affine and Hill ciphers

Affine encryption uses y=ax+b mod m. Hill encryption maps a column vector x to Kx mod m. Reversibility requires a unit multiplier or an invertible matrix; for a 2×2 key, gcd(det K,m)=1. A noninvertible key can produce forward outputs but cannot uniquely recover arbitrary inputs.

Prerequisites: EC03 and earlier foundations as applicable.

EC04 engineering diagram
Algorithm structure and data flow. Use the simulation to inspect the corresponding numerical transformations.

Engineering diagrams

Remainders and Bézout coefficients underpin the inverse.
Remainders and Bézout coefficients underpin the inverse.

Scientific foundations and worked examples

Euclidean and extended Euclidean derivation

Repeated division gives 12456=1×7272+5184; 7272=1×5184+2088; 5184=2×2088+1008; 2088=2×1008+72; 1008=14×72. Thus gcd=72. Bézout coefficients satisfy sa+tb=gcd(a,b). For 7 and 26: 26=3×7+5, 7=5+2, 5=2×2+1; back substitution gives 1=3×26−11×7. The inverse is 15 modulo 26. An inverse of 8 modulo 26 does not exist.

Totient, modular powers and coprimality

For n=∏\(p_{i}\)^\(e_{i}\), φ(n)=n∏(1−1/\(p_{i}\)). For instance φ(24)=24(1−1/2)(1−1/3)=8. Repeated squaring gives powers using modular reduction at each multiplication: \(3^{2}\)≡2, \(3^{4}\)≡4, \(3^{8}\)≡2 modulo 7. If gcd(b,c)=1 and a|(b+c), any common prime divisor of a and b would also divide c, a contradiction; similarly for a and c. If each of a and b is coprime to c then their product is coprime to c.

Affine and Hill transformations

With A=0 and modulus 26, affine encryption is y=ax+b; inverse is x=\(a^{-1}\)(y−b). For a=5,b=2, \(a^{-1}\)=21. Hill encryption operates on column vectors y=Kx mod 26; the inverse is det(K)⁻¹ adj(K). The matrix [[3,4],[2,5]] has determinant 7, so it is invertible; [[4,2],[8,6]] has determinant 8 and is not invertible modulo 26. A successful forward multiplication does not prove that decryption is possible.

Engineering principles · additional worked teaching example

A modular inverse exists iff gcd(a,m)=1. For 7 mod26, 26=3×7+5,7=1×5+2,5=2×2+1; back-substitution yields 1=3×26−11×7, hence inverse15. Affine/Hill keys must be invertible in their modulus.

From theory to experiment

Predict the reference result before operating the workbench; check the actual intermediate state, units and constraints. The existing simulation, implementation and procedure below are distinct sources of evidence.

Worked engineering reasoning and boundary conditions

Euclid replaces (a,b) by (b,a mod b). An affine cipher needs gcd(a,26)=1; Hill matrices require invertible determinant. Example: 7·15=105≡1 mod 26.

Use the diagram to follow the calculation or state progression. Keep the teaching configuration separate from the independent exercise values; compare observations with the actual model and implementation.

Mathematical representation and interpretation

Bézout identity and modular inverse

The Euclidean divisions produce the gcd. Back-substitution yields integer coefficients x,y; x reduced modulo n gives the inverse if the gcd is one.

\[\gcd(a,n)=ax+ny,\qquad ax\equiv1\pmod n\quad\text{when }\gcd(a,n)=1\]

For 7 and 11: 11=7+4, 7=4+3, 4=3+1; 1=2(11)−3(7), so \(7^{-1}\)≡8 modulo 11.

Concept animation · operation pathway

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.

Modular arithmetic II — Euclid, totient, Affine and Hill: operation pathwayEuclid26=3×7+5Continue7=1×5+2;5=2×2+1Back-substitute1=3×26−11×7Normalize−11 mod 26=15Read the active operation, then inspect the accumulated state.

Step 1 of 4 · Euclid

Euclid

Euclid
26=3×7+5

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

Interactive flashcards

Self-rated study progress is stored locally, not used for official grades.

Browse all explanations
When does a modular inverse exist?

When gcd(a,m)=1.

What does Euclid compute?

The greatest common divisor by successive remainders.

When is an Affine key valid?

Its multiplier is invertible modulo alphabet size.

When can a Hill matrix be inverted?

Its determinant is a unit modulo the alphabet size.

What does Euclid's algorithm calculate?

The greatest common divisor using repeated remainders.

What is the inverse of 3 modulo 26?

9, because 3×9 ≡ 1 mod 26.

What does extended Euclid additionally return?

Coefficients satisfying ax+by=gcd(a,b).

What is Euler's totient of a prime p?

p−1.

What is φ(15)?

8.

Why use square-and-multiply?

It computes modular powers efficiently using exponent bits.

What condition must the Affine multiplier satisfy?

It must be coprime to the alphabet size.

When is a Hill matrix invertible modulo m?

When gcd(det(K),m)=1.

How do you verify a Hill inverse?

Multiply the matrices modulo m and obtain the identity matrix.

Find the inverse of 7 modulo 26.

7×15=105=4×26+1, so the inverse is 15.

Can the affine coefficient 13 be used with alphabet size 26?

Not for reversible encryption. gcd(13,26)=13; the map is not bijective.

A Hill matrix has determinant 2 modulo 26. Can it be inverted?

No. gcd(2,26)≠1. A modular inverse of the determinant does not exist.

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