This script implements a secure chat client that enables two users to communicate over a network using AES-256 encryption. It is designed to encrypt and decrypt messages in real time and provides a mechanism for deterministic key generation.
- The script loads an OpenAI API key from a .env file. If the key is available, the script initializes an OpenAI client.
- It uses the OpenAI language model (LLM) to deterministically generate a 32-byte encryption key (expressed as 64 hexadecimal characters) based on the username and a shared context. This key is then used for AES encryption/decryption.
- If the LLM is not available (e.g., no API key or errors during key generation), the script falls back to using SHA-256 for key generation.
- The client can either start a server to wait for a connection or connect to an existing chat server. Messages are always encrypted using a constant conversation key derived from a shared context, ensuring both parties can decrypt each other's messages.
- The decryption process attempts multiple methods (using the conversation key, peer key, user key, and a SHA-256 fallback) to maximize the success of message decryption. After multiple failures, it automatically switches to SHA-256.
- Key Generation: The LLM is queried to generate a deterministic 32-byte encryption key. A specific system prompt ensures that the output is exactly 64 hexadecimal characters. This allows for a unique yet consistent key per user based on their username.
- Fallback Mechanism: If LLM key generation fails or an API key is not provided, the application falls back to using a standard SHA-256 hash mechanism.
- Run the script.
- Choose whether to start a new chat (server) or join an existing one.
- Enter your username and optionally force SHA-256 for key generation.
- Type messages to send encrypted communications.
This web application is built using Flask and Flask-SocketIO to facilitate a real-time group chat. It provides an interactive user interface for participants to exchange messages quickly and efficiently over the web.
- The Flask backend serves HTML/JavaScript to clients and manages web routes.
- Socket.IO is used to establish real-time, bidirectional communication between the server and connected clients.
- The server processes incoming messages and broadcasts them to all connected users, ensuring a smooth and interactive chat experience.
- The LLM is integrated to enhance message processing capabilities. It can be used to:
- Generate creative or context-aware responses that add a human-like touch to the conversation.
- Assist in dynamically transforming messages, such as adding personalized flair or performing lightweight encryption/decryption tasks.
- Provide an entertaining twist in the way messages appear, making the chat experience more engaging.
- Run the Flask server hosting the chat app (typically via a command like
flask runor using a production server such as Gunicorn). - Open the app in a web browser, where you can join the chat lobby.
- Exchange messages with other participants in real time, with AI-driven features enhancing the conversation.
- Socket Communication: Uses TCP sockets for reliable messaging
- AI Model: Uses GPT-4o for both encryption and decryption
- Deterministic Processing: Uses temperature=0, fixed seed values, and other parameters to ensure consistent encryption/decryption
- Contextual Security: The AI uses the sender's username to maintain encryption context
- End-to-End Process: Messages are:
- Written by you
- Encrypted by AI
- Sent over the network
- Received by the other user
- Decrypted by AI
- Displayed to the recipient
This approach has both advantages and limitations:
- No fixed encryption algorithm that could be systematically broken
- Each message may be encrypted differently
- Without access to OpenAI's specific model and parameters, decryption is difficult
- Deterministic parameters ensure the same message is encrypted/decrypted consistently
- Depends on OpenAI's availability and API
- Encryption/decryption has some latency due to API calls
- Security relies on OpenAI's handling of requests and responses
- Python 3.6+
- OpenAI API key
openai,python-dotenvpackages
The script uses several techniques to make encryption and decryption as deterministic as possible:
- Temperature Setting: Set to 0 to minimize randomness in AI responses
- Seed Values: Deterministic seeds based on username and message content
- Additional Parameters:
top_p=1: Ensures all tokens are considered for samplingfrequency_penalty=0andpresence_penalty=0: Prevents the model from avoiding repetition
These settings help ensure that:
- The same message from the same user will be encrypted the same way each time
- The same encrypted message will be decrypted to the same original text
Note that while these settings maximize determinism, OpenAI models may still have some inherent variability.
Tinder.py is a playful, socket-based dating app client that simulates a Tinder-like experience. Users can either run the script to wait for incoming matches as a server or initiate a connection to another client. The app exchanges user profiles and chat messages, creating a fun interactive environment complete with humorous flirty interactions.
- Profile Creation: Users are prompted to create a profile with their name, age, bio, and interests. This profile is exchanged with a match when a connection is established.
- Connection Setup: Depending on the selected mode, the script either starts a server to listen for a match or connects to another peer's server.
- Message Exchange: Once matched, the clients exchange messages over a socket connection. The message exchange includes the transmission of a JSON packet containing the sender's name and message content.
- Real-time Communication: The app uses threading to continuously listen for incoming messages and process them in real-time.
The OpenAI language model plays a key role in adding personality and humor to the communication. The LLM is leveraged in the following scenarios:
-
AI Context Setup: During initialization, the app primes the AI with the user's dating profile and context, setting a playful tone for subsequent interactions.
-
Message "Encryption": When a user sends a message, the script uses the LLM to "encrypt" the text. This is not true encryption but a creative transformation where the AI intentionally tweaks the message in amusing, flirty ways. Occasionally, it may add random emojis or alter the wording to produce humorous misunderstandings.
-
Message "Decryption": When a message is received, the LLM is again called upon to "decrypt" the message back into a more understandable form, often maintaining the flirty and fun tone. The decryption process may also add a twist by replacing message openings with playful flirty starters selected randomly from a pre-defined list.
- Profile Setup: Run the script and follow the prompts to create your dating profile.
- Choose a Mode: Decide whether to wait for incoming matches (server mode) or swipe right and attempt to connect to someone else (client mode).
- Start Chatting: Once a match is made, start sending messages. The LLM will intermittently modify your messages to keep the conversation light, humorous, and engaging.
- Exiting: Type 'unmatch' to end the conversation and close the connection.
Enjoy the blend of real-time chatting with AI-driven playful interactions, making your dating app experience uniquely fun and entertaining!