Skip to content

Repository files navigation

Secure Chat Client (script.py)

Overview

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.

How It Works

  • 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.

Role of the LLM

  • 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.

Usage

  1. Run the script.
  2. Choose whether to start a new chat (server) or join an existing one.
  3. Enter your username and optionally force SHA-256 for key generation.
  4. Type messages to send encrypted communications.

AI Chat Web Application (ai_chat.py)

Overview

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.

How It Works

  • 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.

Role of the LLM (Language Learning Model)

  • 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.

Usage

  1. Run the Flask server hosting the chat app (typically via a command like flask run or using a production server such as Gunicorn).
  2. Open the app in a web browser, where you can join the chat lobby.
  3. Exchange messages with other participants in real time, with AI-driven features enhancing the conversation.

Technical Details

  • 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:
    1. Written by you
    2. Encrypted by AI
    3. Sent over the network
    4. Received by the other user
    5. Decrypted by AI
    6. Displayed to the recipient

Security Considerations

This approach has both advantages and limitations:

Advantages

  • 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

Limitations

  • 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

Requirements

  • Python 3.6+
  • OpenAI API key
  • openai, python-dotenv packages

Advanced Configuration

Ensuring Deterministic Behavior

The script uses several techniques to make encryption and decryption as deterministic as possible:

  1. Temperature Setting: Set to 0 to minimize randomness in AI responses
  2. Seed Values: Deterministic seeds based on username and message content
  3. Additional Parameters:
    • top_p=1: Ensures all tokens are considered for sampling
    • frequency_penalty=0 and presence_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 Dating App Client (tinder.py)

Overview

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.

How It Works

  • 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.

Role of the LLM (Language Learning Model)

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.

Usage

  1. Profile Setup: Run the script and follow the prompts to create your dating profile.
  2. Choose a Mode: Decide whether to wait for incoming matches (server mode) or swipe right and attempt to connect to someone else (client mode).
  3. 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.
  4. 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!

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages