Implement a toy additively-homomorphic encryption scheme over integers — similar in spirit to Paillier but stripped down for clarity, not security. Verify on 50 randomly generated test cases that the homomorphic correctness equation $\mathrm{Dec}(\mathrm{Enc}(a) \boxplus \mathrm{Enc}(b)) = a + b \pmod N$ holds. Then measure the ciphertext expansion ratio (bytes per ciphertext divided by bytes per plaintext) and write a paragraph explaining why that ratio is the single number that makes HE expensive to deploy at scale.
pickle.dumps or your own int.to_bytes(byte_length, 'big') — do not use sys.getsizeof (that includes Python object overhead and lies).secrets.randbits or random.SystemRandom().getrandbits for the randomness — random.random() is not appropriate even in a toy scheme.A test run should look something like:
random seed: 0xdeadbeef
[01/50] a=42, b=99 -> Enc(a)+Enc(b) decrypts to 141 (expected 141) PASS
[02/50] a=12345, b=67890 -> Enc(a)+Enc(b) decrypts to 80235 (expected 80235) PASS
...
[50/50] a=2147483120, b=128 -> Enc(a)+Enc(b) decrypts to 2147483248 (expected 2147483248) PASS
50/50 tests passed.
Ciphertext expansion at three plaintext sizes:
N = 2^8 plaintext = 1 byte ciphertext = 16 bytes expansion = 16x
N = 2^16 plaintext = 2 bytes ciphertext = 16 bytes expansion = 8x
N = 2^32 plaintext = 4 bytes ciphertext = 16 bytes expansion = 4x
…followed by your 1-page analysis. (Real lattice-HE schemes have expansion 1000x–100000x, not 4x — your toy scheme is ridiculously efficient because it's insecure. The write-up should explain why a real HE scheme has to be so much fatter: it has to add cryptographically-meaningful noise sampled from a high-dimensional discrete Gaussian, plus auxiliary key material for relinearization.)
AddPlaintextCT operation: — homomorphic addition with a plaintext (no second encryption needed). Show that this is cheaper than ciphertext-ciphertext addition.MulCTbyPlaintext: . Show that this works in your toy scheme. Why does it work for multipliers but not for ciphertext-ciphertext multiplication?phe