[Back] This is a simple Homomorphic Cipher and involves an odd integer (p) and two random numbers (q and r). We encrypt a single bit (m) with \((p \times q) + 2 \times r + m\). Then we take mod p, and then mod 2, and we get the message back:

## Simple Homomorphic Cipher |

## Theory

This is one of the simplest ciphers, where we can add and multiply the ciphers. First we get an odd number (p) and two random numbers (q and r), and encrypt a single bit (m) with:

\(c = p \times q + 2 \times r +m \)

If 2r is smaller than p/2, we cipher with mod p we get:

\(d = (c \mod p) \mod 2\)

We have basically added noise to the value with the q and r values.

## Code

The following is an outline:

import random import sys p=1001 m=0 if (m<>0) and (m<>1): print 'M must be a 0 or a 1' q=random.randint(3, 10) r=random.randint(3, 10) print 'P:\t\t',p print 'q:\t\t',q print 'r:\t\t',r c = p*q + 2*r +m print 'Cipher:\t\t',c d = (c % p) %2 print 'Decipher:\t',d