CPSC 110-08: Computing on Mobile Phones
A color in App Inventor is represented by a number composed of the three RGB (Red, Green, Blue) primary color numbers plus the Alpha value, which is a measure of the color's transparency. Each of these four components is an integer in the range 0 to 255.
(If you are interested in seeing how App Inventor translates colors into numbers see this explanation.)
For the purpose of cipher we will just consider the three RGB values. That will give us 255 × 255 × 255 = 16,581,375 different colors, each of which can be a secret key for our cipher.
A cipher based on a color key would not be a secure cipher by today's standards. It would be an easy matter to search through all 16,581,375 possible keys. But it would make for an interesting exercise in making and breaking ciphers.
This demo illustrates a simple cipher system that uses color as keys. Scroll down for more details.
Android Package: ColorCipher.apk
|App Inventor Source Code: ColorCipher.zip|
Alice and Bob share one of the 16 million colors as secret key which they use to encrypt and decrypt messages. A key that can be used both to encrypt and decrypt messages is known as a symmetric key.
Using this key, we devise a simple substitution cipher, in which letters of the alphabet are replaced by colors:
To encrypt a letter into a color:
In App Inventor blocks, here is how a letter is encrypted, where letterNum is the letter's number (0 to 25) and both key and SCALING_FACTOR are colors:
To decrypt a color into a letter, we perform the encrypt operations in reverse:
In App Inventor blocks, here is how a letter is encrypted, where colorNum is color encryption of the letter and key1, and SCALING_FACTOR are both colors: