Diffie Hellman encryption method

The Diffie-Hellman is a method for two users to exchange information that is encrypted. The method was proposed in 1976. It is the base for many methods used in VPN, SSH, PGP and other PKI systems.
The method is called asymmetric key exchange, because anyone can encrypt messages using the public key of the recipient but only the holder of the private key used to generate the public key can decrypt. The security depends on the secrecy of the private key and the use of large numbers that make brute force decryption very difficult.

Encrypt and decrypt a number

  1. Select the shared numbers.
  2. Select the private key and share the public key.
    Let's look at two users, Alice and Bob.
  3. Compute the super key for encoding and decoding.
  4. Use the superkey to encrypt and decrypt.
    Alternatively, the encryption and decryption can be done in a simpler way by computing
    If the number is t=36, and the superkey is x, to encrypt compute
    encrypted=(t+x)%p
    To decrypt the number encrypted do
    decrypted=(encrypted-x)%p
    Only the users who have the same superkey can encrypt and decrypt.
Try the python code diffie.py to encrypt a number.

Encrypt and decrypt a word

Encrypt and decrypt a sentence

Copyright: © 2017, 2018 by the Regents of the University of Minnesota
Department of Computer Science and Engineering. All rights reserved.
Comments to: Maria Gini