XOR – how to build a simple encryption scheme with inContact

by inContact Team on 10-19-2009 04:17 PM

Have you ever wanted to encrypt a message or word?  One simple way of creating your own encryption algorithm is to use the XOR operation.  The magic of the XOR is that when you XOR two numbers or characters to each other, you will get a new character or number as the result – it is effectively ‘encrypted’.  You can then ‘decrypt’ your results and restore the original value by performing a second XOR to reverse the encryption.

 

Say you want to encrypt the word ‘APPLE’ and you use the ‘$’ sign as your encryption key. You would perform an XOR operation on each letter of the word ‘APPLE’ in this fashion:

 

A XOR $

P XOR $

P XOR $

L XOR $

E XOR $

 

You would get the encrypted value of ‘ettha’.

 

To decrypt ‘ettha’ you would simply reverse the operation as shown.

 

e XOR $

t XOR $

t XOR $

h XOR $

a XOR $

 

You would be rewarded with the word ‘APPLE’.

 

**Be sure to NEVER use an encryption character as a key that might appear in your messages that you are trying to encrypt.  That character will be lost. 

 

Using XOR, you can create a set of encryption keys that you determine.  In this fashion, it is possible to perform simple encryption within a script and store that encrypted value within your contacts – just be certain you don’t lose the encryption key.  The trick to performing an XOR operation is that you must use VB script in a SHELL action.  An example is shown below.

 

TLEN = Len(P2)

           

            For x = 1 To TLEN

                        TVAL = Mid$(P2, x, 1)

                        TVALINT = Asc(TVAL)

                        TVALINT = TVALINT Xor Asc(P1)

                        P3 = P3 & Chr(TVALINT)

            Next x

 

Assign P3, "EVAL2"

 

In this example we pass the word or message to be encrypted into the SHELL action as the variable ‘P2’ and our encryption key is in the value ‘P1’.   We then parse each character of P2 and perform an XOR action against P1 and reconstruct the new encrypted message in the variable P3.  P3 can then be stored as a published variable within the contact. 

 

InContact provides its users with a powerful array of programming tools, including Boolean operations like AND, OR and XOR.  These can be employed to build truth tables or even create simple encryption schemes.

 

 

Follow us on...
About the Author
  • I am the Director of Network Systems, and have been working in the telecommunications industry for 24 years. I have been the lead engineer, Network Operations Manager or Director of Network Operations for most of that time. I am now working with a new team within inContact called SHIELD whose primary role is to improve the customer experience. The specific objective is to improve the overall uptime and usability of the inContact suite of products. I will be writing about inContact, with information and suggestions that I believe will find practical application to how you use the inContact products. I look forward to hearing from you all.
Announcements
Let us know how we can help you: ProductManagement@inContact.com
Labels