Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


XOR Pad Type Encryption

Keywords:   XOR Pad type encryption

This is called a "pad" type encryption. You MUST preserve the "keyfile." If you do not have the key file, then there is ABSOLUTELY no way to recover the data. It should be a sort of compressed file. ZIPS, JPG's and MP3 seems to work pretty good.

The key file should be larger than the data file you wish to encrypt.

;Encrypt

datafile="C:\BizDocs\Incoming\bigdlg.txt"
protfile="C:\BizDocs\Incoming\bigdlg.prot"

datafilesize=FileSize(datafile)

bbdata=BinaryAlloc(datafilesize)
bbkey=BinaryAlloc(datafilesize)

BinaryRead(bbdata,datafile)
for xx=1 to datafilesize
   BinaryPoke(bbkey,xx-1, (datafilesize+xx) mod 255)
next
BinaryXOR(bbdata,0,bbkey,0,datafilesize)

BinaryWrite(bbdata,protfile)
BinaryFree(bbdata)
BinaryFree(bbkey)

Message(protfile,"File encrypted")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;Decrypt

protfile="C:\BizDocs\Incoming\bigdlg.prot"
outputfile="C:\BizDocs\Incoming\bigdlg.new"

datafilesize=FileSize(protfile)

bbdata=BinaryAlloc(datafilesize)
bbkey=BinaryAlloc(datafilesize)

BinaryRead(bbdata,protfile)
for xx=1 to datafilesize
   BinaryPoke(bbkey,xx-1, (datafilesize+xx) mod 255)
next

BinaryXOR(bbdata,0,bbkey,0,datafilesize)

BinaryWrite(bbdata,outputfile)
BinaryFree(bbdata)
BinaryFree(bbkey)

Message(outputfile,"File decrypted")

Article ID:   W15292