re implementing a diffie hellman key exchange you should probably use numbers much larger than bits also you may want to include some randomly generated bitstrings in your protocol this way if someone should find the shared key you and another person use on one day they won t be able to guess it for the next day ie a sends g a mod p and random string r b sends g b mod p and random string r both find g a mod p b mod p shared key then both calculate session key hash r shared key r also you will want to make sure that you re getting the right public key value g a mod p someone with the power to intercept and change messages can oterwise spoof you by sending both of you his public key and then acquiring a session key with each of you john
