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 / EC09
IoTPSUT IoT Engineering StudioPrincess Sumaya University for Technology · Dr. Mohammad Alja’afreh
ESSENTIAL LABORATORY · EC09 · IoT SECURITY AND PRIVACY
IoT Security and Privacy

RSA — Keys, modular exponentiation and encryption

Construct RSA public/private exponents from number theory, implement square-and-multiply, and verify encryption/decryption on bounded integer examples.

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

Scope and objectives

Scope of the experiment

Construct RSA public/private exponents from number theory, implement square-and-multiply, and verify encryption/decryption on bounded integer examples.

The focus of this experiment is to derive textbook RSA parameters and modular exponentiation. Students then calculate and verify numerical encryption and decryption, and explain small-key and unpadded-RSA limitations. 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

  • Derive textbook RSA parameters and modular exponentiation.
  • Calculate and verify numerical encryption and decryption.
  • Explain small-key and unpadded-RSA limitations.
  • 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 derive textbook RSA parameters and modular exponentiation, calculate and verify numerical encryption and decryption, and explain small-key and unpadded-RSA limitations.

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 explain small-key and unpadded-RSA limitations. 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 PyCryptodome — AES-CTR, hashing and hash-chain PRNG.

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 RSA — Keys, modular exponentiation and encryption

Construct RSA public/private exponents from number theory, implement square-and-multiply, and verify encryption/decryption on bounded integer examples.

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: Construct RSA public/private exponents from number theory, implement square-and-multiply, and verify encryption/decryption on bounded integer examples.

  1. Complete the analytical preparation below before programming. Show the intermediate mathematical calculations.
  2. Square-and-multiply implementation — complete its numbered steps and record the requested evidence.
  3. RSA key generation — complete its numbered steps and record the requested evidence.
  4. RSA peer exchange and validation — complete its numbered steps and record the requested evidence.

Reference check: n=2077; φ=1980; e=7 is permitted and d=283; 12 encrypts to 1481 and decrypts to 12.

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. Square-and-multiply implementation — 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 · EC09 · RSA — Keys, modular exponentiation and encryption

RSA key construction and verification — Choose primes / p=31, q=67; Modulus / n=2077; Totient / φ=1980; Exponents / e=7, d=283; Encrypt/decrypt / m=12; modular powers
Scientific concept map: Primes p,q — n=pq; Totient — (p−1)(q−1); Public exponent — gcd(e,φ)=1; Private exponent — d=\(e^{-1}\) mod φ; Modular power — Encrypt / decrypt.

RSA key construction

For distinct primes p and q, form n=pq and φ(n)=(p−1)(q−1). Select e coprime to φ(n), then compute d=\(e^{-1}\) mod φ(n). The public pair is (n,e); d and the primes remain private. Never reuse classroom primes in a deployed system.

Modular exponentiation

Compute c=m^e mod n and recover m=c^d mod n for integer messages 0≤m<n. Square-and-multiply reads exponent bits, repeatedly squares and conditionally multiplies, reducing modulo n after each step. This avoids constructing huge intermediate powers.

Security boundary

Textbook RSA is deterministic and does not provide secure general-purpose encryption. Practical designs use standardized padding such as OAEP for encryption; signing uses a separate signature construction. In this lab, the small and large integers are public calculation fixtures.

Prerequisites: EC08 and earlier foundations as applicable.

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

Engineering diagrams

RSA key construction and exponentiation.
RSA key construction and exponentiation.

Scientific foundations and worked examples

Number-theoretic key construction

For p=11,q=3, n=33 and φ=20. The permitted nontrivial e values in [2,19] are 3,7,9,11,13,17,19. Choosing e=3 gives d=7 because 3×7≡1 modulo 20. Encrypt M=8 as \(8^{3}\) mod 33=17; decrypt \(17^{7}\) mod 33=8. For general RSA the exponent inverse may also be computed modulo λ(n), the least common multiple of p−1 and q−1. Classroom integer messages must satisfy 0≤M<n.

Square-and-multiply worked examples

Scan exponent bits from left to right, starting with r=1. For each bit square r modulo n; if the bit is 1, multiply by the base modulo n. For \(5^{20}\) mod 35, 20=10100₂ and successive residues are 5,25,10,30,25. For \(275^{131}\) mod 277, 131=128+2+1; the powers at 128 and 2 are 155 and 4, so the final residue is 145. This takes O(log e) modular multiplications rather than O(e) naive multiplications.

Why mathematical RSA is not a deployed protocol

The raw RSA map is deterministic and multiplicatively structured. Secure encryption requires a standardized encoding such as OAEP and signatures use a distinct standardized scheme such as PSS. Modulus size, random key generation, private-key storage and side-channel protections are essential in production. Never use the small classroom keys for protection.

Engineering principles · additional worked teaching example

Textbook RSA chooses distinct primes p,q, n=pq and e coprime to φ=(p−1)(q−1). For p=3,q=11,e=3, φ=20, d=7 since 3×7=21≡1. Raw RSA is deterministic and lacks secure encoding; practical encryption uses OAEP.

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

RSA uses n=pq, φ=(p−1)(q−1), gcd(e,φ)=1 and ed≡1 mod φ. Toy primes are for hand calculations only. For p=5,q=11,e=3,d=27.

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

RSA key equations

Distinct primes p,q determine the modulus n; e is public and d private. Textbook m is an integer in [0,n). Small raw RSA is solely an arithmetic teaching model; real encryption uses a vetted padding scheme.

\[\begin{aligned}n&=pq,&\varphi(n)&=(p-1)(q-1)\\\gcd(e,\varphi(n))&=1,&ed&\equiv1\pmod{\varphi(n)}\\c&=m^e\bmod n,&m&=c^d\bmod n\end{aligned}\]

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.

RSA — Keys, modular exponentiation and encryption: operation pathwayToy primesp=5, q=11Modulus and totientn=55, φ=40Public exponente=3Private exponentd=27; 3×27=81≡1 mod40Read the active operation, then inspect the accumulated state.

Step 1 of 4 · Toy primes

Toy primes

Toy primes
p=5, q=11

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
What is RSA modulus?

Product of two primes.

Why must e be coprime to the totient?

To permit a modular inverse for the private exponent.

What does square-and-multiply do?

Efficient modular exponentiation.

Why avoid textbook RSA?

It lacks secure padding and is deterministic.

What is the RSA modulus?

n=pq for two primes.

What is φ(n) for distinct primes p and q?

(p−1)(q−1).

What condition must e meet?

gcd(e,φ(n))=1, with e in the permitted range for the teaching construction.

How is d calculated?

The modular inverse of e modulo φ(n) in this lab.

What is textbook RSA encryption?

c=m^e mod n.

What is textbook RSA decryption?

m=c^d mod n.

Why must the integer message be smaller than n?

RSA operates on residues modulo n.

How does square-and-multiply process an exponent?

Square the running value and multiply for set exponent bits under the chosen convention.

Why not use raw RSA in production?

It is deterministic and lacks secure randomized encoding.

What scheme is used for secure RSA encryption in the capstone?

RSA-OAEP with an appropriate hash.

Take p=5, q=11 and e=3. Is e valid?

λ(55)=lcm(4,10)=20; gcd(3,20)=1, so e is invertible modulo λ(n). These tiny primes are teaching values only.

Why reduce after each square or multiplication?

Modular reduction preserves the final residue while avoiding huge intermediate integers.

Why is textbook RSA unsafe for encrypting arbitrary real messages?

It is deterministic and lacks a secure encoding. Use a standardized padding scheme such as OAEP for encryption.

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