DEV Community

Cover image for How to send a secret Whats app message from terminal using Gecko Driver

How to send a secret Whats app message from terminal using Gecko Driver

Arun krishna
To explore and implement emerging trends in Information Technology. Software Developer. Very much open to new domains depending upon the work.
Updated on ・4 min read

This code is for educational purposes only and the author is not responsible for any consequences resulted. Please do not try it if you do not agree for the condition.

Hello everyone,
In this post I will be showing how I have sent an encrypted secret whatsapp message.


  • Gecko web driver
  • Python 3.X
  • pycryptodome library
  • cryptography library
  • colorama library

Firstly the architecture of the system is as shown in the below figure
Alt Text

In this post I will demonstrate with AES algorithm. Similarly you can try with different encryption algorithms. And we are going to use Gecko driver to send the message automatically. The primary goal is encrypting and communicating the sensitive data in whatsapp.The encryption of AES used here is EAX mode.

This mode is difficult in encryption because it doesnot use UTF-8 encoding. It utilizes Windows-1252 encoding which is difficult for any external compilers to decode the message.

First let's install the required libraries. Write the 3 libraries pycryptodome
in text file named requirements.txt
Now install them using pip command

pip install -r requirements.txt

Put the Gecko driver in the directory where you are going to execute the code.
All the pre-requisites are done let's dive into the coding part

Import the libraries

import base64
import binascii
import binhex
import os
import string
import sys
from random import choice
import smtplib
import os
import hashlib

Let's display an error message if any libraries are missing

    from colorama import Fore, Style, init
    from Crypto.Cipher import AES
    from Crypto.Random import random
    from cryptography.fernet import Fernet
except ImportError:
        "ERROR: Missing required libraries.\n"
        "Install dependencies with: pip install -r requirements.txt"

colorList = [Style.BRIGHT + Fore.RED, Style.BRIGHT , Style.BRIGHT + Fore.YELLOW, Style.BRIGHT + Fore.BLUE, Fore.GREEN ,Fore.MAGENTA, Style.BRIGHT + Fore.CYAN, Style.BRIGHT + Fore.WHITE]

Here I am using colorama library to change the colours for every execution.

Let's get the required input

def get(datatype):
        (message) = {
            "plaintext": ("Enter plaintext message"),
            "encoded": ("Enter encoded message"),
            "encrypted": ("Enter encrypted message"),
            "filename": ("Specify filename"),
            "passwordfilename": ("Specify  passwordfilename"),
            "password": ("Enter encryption password"),
            "Select": ("Choose any one"),
    except KeyError:
        message = datatype
    return input(f"\n{message}: {Style.RESET_ALL}").encode()

In my previous post I have mentioned about Xpath and automation. We are going to use similar concept here with whatsapp too. First let us write the bot script and store it in

from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from time import sleep
import chardet

driver = webdriver.Firefox()

fileLocation= "Path/AESKEY.txt"
with open(fileLocation,"r") as file:
    for line in file:

fileLocation= "Path/AES.txt"
with open(fileLocation,"r") as file:
    for line in file:
        for word in line.split(" "):

# No special characters and spaces in enc

We are going to store the key required to decrypt the message in AESKEY.txt file and the encrypted message in AES.txt file. This bot reads the file and then sends the message. You can send some instruction message as shown below.
Alt Text

Now let's get into the encryption part.

def aes_enc_auto():
    """Encrypt with AES."""
    keypass = random_key(16)
    data = get("plaintext")
    filename = get("filename").decode()
    cipher =, AES.MODE_EAX)
    ciphertext, tag = cipher.encrypt_and_digest(data)
    with open(filename, "wb") as outfile:
        _ = [outfile.write(item) for item in (cipher.nonce, tag, ciphertext)]

    kn = "AESKEY"
    passwordfilename = os.path.join(save_path, kn+".txt") 
    with open(passwordfilename, "wt") as outfile:
        _ = [outfile.write(item) for item in (keypass)]
    print("AES encrypted message and key files are saved")

First we get the plain text from the terminal and it is stored after getting encrypted. Then gecko driver comes into action and sends the content to receiver.

The above encrypted message can be decrypted by using below code.

def aes_dec_auto():
    """Decrypt with AES."""
    filename = get("filename")
    keypass = get("password")
    with open(filename, "rb") as infile:
        nonce, tag, ciphertext = [ for x in (16, 16, -1)]
    cipher =, AES.MODE_EAX, nonce)
    data = cipher.decrypt_and_verify(ciphertext, tag).decode()
    show("plaintext", data)

Finally let's finish the main function

# Main Function
def main():
        while True:
                + Fore.GREEN + "Choose from the following options, or press Ctrl-C to quit:\n\n"
                + Style.RESET_ALL
            for index, option in enumerate(MENU_OPTIONS, 1):
                print(Style.BRIGHT + f"{index}: {' ' if index < 10 else ''}" f"{option.__doc__}" + Style.RESET_ALL)
            choice = get("Select")
                MENU_OPTIONS[int(choice) - 1]()
            except (IndexError,UnboundLocalError):
                print("Unknown option." + Style.RESET_ALL)
            # except ValueError:
            #     print("Invalid option."+ "Enter the number of your selection."+ Style.RESET_ALL)

    except (KeyboardInterrupt,UnboundLocalError):
        print("\n{}Program Terminated\n{}Have A Nice Day{}".format(Fore.RED,Style.BRIGHT,Style.RESET_ALL))


if __name__ == "__main__":

In my below repository I have implemented the above concept with various hashing and encryption algorithms. Please drop a star if you like it.

GitHub logo Chitturiarunkrishna / Encryption

Explanation is available in this link


The main aim of this project is to send an encrypted secret message.I am going to use Gecko driver which is supported by Mozilla Firefox and send the encrypted messages. For adaptability this project can even work with Selenium which supports Google chrome.

Discussion (0)