Background: The cipher used here exploits the fact that ((m*n1 mod p)*n2 mod p) = ((m*n2 mod p)*n1 mod p).Let m be a message block that A wants to send to B. Someone chooses a number p. A chooses a number nA such that there is a number invA where A: for all m, ((m*nA mod p)*invA mod p) = m.B chooses a number nB such that there is a number invB where B: for all m, ((m*nB mod p)*invB mod p) = m.A encrypts: that is, sends (m*nA mod p) to B. B encrypts and sends ((m*nA mod p)*nB mod p) to A. A applies invA to obtain (((m*nA mod p)*nB mod p)*invA mod p) which is the same as (((m*nA mod p)*invA mod p)*nB mod p) which is the same as (m*nB mod p). This is sent to B who applies invB to get ((m*nB mod p)*invB mod p) which is the same as m. Instructions: Enter a key for A in the textfield labeled "A:" and a key for B in the textfield labeled "B:". The number p referred to above is in the textfield called "modulus:". Enter a plaintext sentence in the textfield labeled "Plaintext of A:" then hit return. If the keys have inverses they will appear in textfields labeled "inv:". Otherwise, "--" will appear. If inverses exist, the encrypted messages will be shown in the appropriate textfields. Source code: BetterDoubleLock.java |