CPSC 110-08: Computing on Mobile Phones
Spring 2012

Color Crypto

A Crypto System Using Diffie-Hellman Key Exchange

This app implements a simple cipher system that allows Alice and Bob to communicate "securely" using a shared secret key. The color-based Diffie-Hellman Key Exchange method is used to create the shared key. Messages are encrypted as strings of colors using a simple substitution cipher. Alice's and Bob's public keys are stored on a "public key server", implemented with a TinyWebDb. Messages are transmitted through the TinyWebDb.

Here's how it works:

  1. When the app starts a secret key is created for the user, say Alice, whose name is entered into the "Me:" filed.
  2. Alice (or Bob) publishes her public key to the key server (a TinyWebDb).
  3. For Alice to send a message to Bob:
    1. The App retrieves Bob's public key from the key server.
    2. The App combines Alice's private key and Bob's public key to create a shared secret key.
    3. The App encrypts the message using the shared key and "sends" it to Bob (posts it on TinyWebDb).
  4. For Alice to receive a message from Bob:
    1. The App retrieves Bob's public key from the key server.
    2. The App combines Alice's private key and Bob's public key to create a shared secret key.
    3. The App retrieves the message (stored on the TinyWebDb) and decrypts it using the shared key.

Scroll down for additional details.
ScreenshotQR Code
qrcode

Android Package: ColorCrypto.apk
App Inventor Source Code: ColorCrypto.zip

Encryption Scheme

To create a shared secret key, a Diffie-Hellman Key Exchange is performed by combining the sender's private key and the receiver's public key, both of which are 1 of the 16 million colors.

The secret key is used with a simple substitution cipher, in which letters of the alphabet are replaced by colors, using the following algorithms:

To encrypt (msg, key): 
    Set colorLst to empty_list
    For each letter in msg:
        Set color to shiftColorMod255( letterToNum(letter), key )
        Add color to colorList
    Return colorList


To decrypt (colorList, key): 
    Set msg to ""
    For each color in colorList:
        Set letter to numToLetter (reverseShiftColorMod255( color, key ) )
        Add letter to msg
    Return msg

The letterToNum() function maps 'a' to 0, 'b' to 1, etc., while the numToLetter performs the reverse mapping.

The shiftColorMod255(color1, color2) adds each color's RGB values mod 255, while the reverseShiftColorMod255(color1, color2) performs the reverse operation.