Jump to content
Sign in to follow this  

Bit Chaining

Recommended Posts

More of a scrap really, this is an encryption method that I learned a while ago. I finally decided to put it into code. :nuke:

First let me explain how bit chaining works. You take the ascii value of the first two characters in a string and BitXOR() them together. Take the resulting value and xor it with the third character. Take that value and xor it with the next and so on... To decrypt it just use that process in reverse. This method does NOT encrypt the last character of the string because it needs that value intact for decryption. Change one character in the string and all the characters to the right of it change in the encrypted version.

This is the base for many other forms of encryption. It is weak by itself but strong when paired with other methods. Get enough methods together and make it unique enough and you have your own encryption algorithm.

An example comes included with the code. The first parameter is whether you want to encrypt (1) or decrypt (0). Here's the code:

Func _BitChain( $bEncrypt, $sData )
    Local $arr = StringSplit($sData, "")
    If $bEncrypt Then
        Local $last = BitXOR(Asc($arr[1]), Asc($arr[2])), $ret = Chr($last)
        For $i = 1 to $arr[0] - 1
            $last = BitXOR($last, Asc($arr[$i]))
            $ret &= Chr($last)
        $ret &= $arr[$arr[0]]
        Local $ret = $arr[$arr[0]]
        For $i = 1 to $arr[0] - 2
            $ret = Chr(BitXOR(Asc($arr[$arr[0] - $i - 1]), Asc($arr[$arr[0] - $i]))) & $ret
    Return $ret

$str = "abcdefghijklmnopqrstuvxyz"
$enc = _BitChain(1, $str)
$dec = _BitChain(0, $enc)
MsgBox(0, Hex(BinaryString($enc)) & "::" & StringLen($enc), $dec)

I hope you like it! :P

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...