Simple XOR Encryption With a Picaxe

Goeytex

Senior Member
Encryption may sometimes be wanted when you need to obscure data from possible snooping. This might be applicable, for example, with a wireless link that sends sensitive data. While certainly not as secure as highly advanced methods, XOR encryption is fast, simple and effective, and is well-suited to the Picaxe with its limited math capabilities.

With XOR encryption there is a single Key. The data to be encrypted is XOR'd with the key. To decrypt back to the original data, the encrypted data is XOR'd with the same key. Below is demo - test code.

For more info ...> http://en.wikipedia.org/wiki/XOR_cipher

Code:
'********************************
'** XOR ENCRYPTION DEMO - TEST **
'********************************

#Picaxe 20X2
#no_data

Symbol key = $FA1C  '16-bit value
Symbol data1 = w0 
Symbol encrypted_data = w1
Symbol decrypted_data = w2

do
   for data1 = 0 to 65535 step 7
   
      sertxd ("Data = ",#Data1,cr,lf)
      
      gosub encrypt  
      sertxd ("Encrypted Data = ",#encrypted_data,cr,lf) 
      
      gosub decrypt
      sertxd ("Decrypted Data = ",#decrypted_data,cr,lf)
      
      sertxd (cr,lf) 
   pause 1000
   next
loop

encrypt:
encrypted_data  =  data1 XOR KEY
return

decrypt:
decrypted_data = encrypted_data XOR KEY
return
 
Top