WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Encrypt a Line of Text - Simple Explanation


Question:

I need to encrypt a line of text in an ini file. And decrypt it before processing....

I have seen the various resources in the 'database'. Can someone explain to me how basic encryption is done. What are the basic principles? (I am talking about very simple stuff. 'Newbie' comments appreciated.

Answer:

eXclusive OR operations result in a very basic transformation of the data that is reversible by performing the eXclusive OR operation again using the same passkey against the cipher text.

It works like this:

To Encrypt:

CipherText = PlainText XOR PassKey
To Decrypt:
PlainText = CipherText XOR PassKey

The XOR truth table is as follows, with the columns being Input A, Input B and the result of A XOR B:

0 0 0
0 1 1
1 0 1
1 1 0
If you apply this to the bits in each byte of the plain text & passkey that are being operated on together in an XOR operation, you get the basix XOR-based transformation that makes your plain text unreadable to the casual observer. It's very weak in terms of encryption strength and easily broken but it does keep casual observers from simply gleaning the meaning of the cipher text via a casual glance at it.

Simple Excryption UDFs

Basic steps:

  1. Simple encryption of text can be accomplished by placing the text in a binary buffer
  2. The passphrase is truncated or extended to be the same length as the data and placed in another binary buffer.
  3. The binary buffers are XOR'ed together. This is the real encryption part. Longer passphrases are better.

Note: the XOR operation may result in NULL bytes, and the data can no longer be handled as a string as it is. Therefore the resulting XOR'ed string information is read out of the binary buffer as a hex string.

The decryption udf just reverses the process.

#DefineFunction CRYPT(data,passphrase)

    len=StrLen(data)
    passphrase=StrFix(passphrase,passphrase,len)

    BBA=BinaryAlloc(len)
    BBB=BinaryAlloc(len)

    BinaryPokeStr(bba,0,data)
    BinaryPokeStr(bbb,0,passphrase)

    BinaryXor(bba,0,bbb,0,len)
    data2=BinaryPeekHex(bba,0,len)

    Return data2
#EndFunction

#DefineFunction DECRYPT(code,passphrase)
    len=StrLen(code)/2
    passphrase=StrFix(passphrase,passphrase,len)

    BBA=BinaryAlloc(len)
    BBB=BinaryAlloc(len)

    BinaryPokeHex(bba,0,code)
    BinaryPokeStr(bbb,0,passphrase)

    BinaryXor(bba,0,bbb,0,len)
    data=BinaryPeekStr(bba,0,len)

    Return data
#EndFunction

passphrase="Your large pony has brown hair."

data="this might be my passoword"

code=CRYPT(data,passphrase)
orig=DECRYPT(code,passphrase)

Message(orig,code)

Article ID:   W17006
File Created: 2007:07:03:14:27:34
Last Updated: 2007:07:03:14:27:34