Jump to content

burying bits in random spots in an .rtf


Recommended Posts

I am exploring my list of wants for an old stego script.  The following allows you to select a jpg and an rtf, converts the jpg to 1s and 0s, converts those 1s and 0s to no-width spaces, and buries them at the end of an .rtf

Can you randomize the bits' locations within the rtf?  I was thinking such that you would need to output an index of sorts as the key to reading them back, but will certainly entertain any stabs at improvement.

Pic2Bin_and_bury.au3

#Include <Array.au3>
#include <String.au3>
#include <Constants.au3>

$picfile = fileopendialog("select file to be buried" , @ScriptDir , "jpg (*.jpg)" , 3)
fileclose($picfile)

$Fname = fileopendialog("select place to bury" , @scriptdir , "rtf (*.rtf)" , 3)
fileclose($Fname)

tooltip("Working" , 0 , 0)

$pic = fileopen ($picfile , 16)

$Fread = fileread($pic)

fileclose ($pic)

$bits = _BytesToBits(Binary($Fread))

Func _BytesToBits($bBinary)
    Local $byte, $bits="", $i, $j, $s
    For $i = 1 To BinaryLen($bBinary)
        $byte = BinaryMid($bBinary, $i, 1)
        For $j = 1 To 8
            $bits &= BitAND($byte, 1)
            $byte = BitShift($byte, 1)
        Next
    Next
    $s = StringSplit($bits, "")
    $bits = ""
    For $i = $s[0] To 1 Step -1
        $bits &= $s[$i]
    Next
    Return $bits
EndFunc

$bitArray = stringsplit($bits , "")


tooltip("Writing" , 0 , 0)


$file = fileopen($Fname , 33)

filesetpos($file , 0 , 2)

For $i = 1 to $bitArray[0]

If $bitArray[$i] = "1" Then
filewrite ($file , chrw(8203))
ElseIf $bitArray[$i] = "0" Then
filewrite ($file , chrw(8204))
Endif


Next

fileclose($file)

Here is the script to read them back out and reveal the jpg.

whitespace.au3

#Include <Array.au3>
#Include <String.au3>


If fileexists(@ScriptDir & "\hiddenpic.jpg") Then filedelete(@ScriptDir & "\hiddenpic.jpg")

$file = fileopendialog("Select File" , @ScriptDir , "RTF (*.rtf)" , 3)
fileclose($file)

tooltip("Working" , 0 , 0)

$file = fileopen($file , 16)

$read = fileread ($file)

;~ msgbox(0, '' , $read)

$Aresult = StringRegExp ($read , "0B20|0C20" , 3)

;~ _ArrayDisplay($Aresult)

$Sresult = _ArrayToString($Aresult , "")

$rep1s = stringregexpreplace($Sresult , "0B20" , "1")
$rep0s = stringregexpreplace($rep1s , "0C20" , "0")
$repArray = stringsplit($rep0s , "")

;~ _ArrayDisplay($repArray)

Func _BitsToBytes($sBits)
    Local $bBytes = Binary(''), $iLen = StringLen($sBits)
    Local $iCnt = 0, $iVal = 0
    For $i = 1 To $iLen
        $iCnt += 1
        $iVal = BitShift($iVal, -1)
        If "1" = StringMid($sBits, $i, 1) Then
            $iVal = BitOR($iVal, 1)
        EndIf
        If $iCnt = 8 Then
            $iCnt = 0
            $bBytes &= BinaryMid($iVal, 1, 1)
            $iVal = 0
        EndIf
    Next
    If $iCnt Then $bBytes &= BinaryMid(Binary(BitShift($iVal, -8+$iCnt)), 1, 1)
    Return $bBytes
EndFunc

Global $j
Global $byte

$file = "0x"

for $k = $repArray[0] to 1 step - 1
    $byte&=$repArray[$k]
    $j+=1
    If $j = 8 then
    $byte = _stringreverse($byte)
    $int = _BitsToBytes($byte)
    $int = stringtrimleft($int , 2)
    $file&= $int
    $j = 0
    $byte=''
    Endif
next

;~ msgbox (0, '' , $file)

$pic = fileopen (@ScriptDir & "\hiddenpic.jpg" , 26)

$Fread = filewrite($pic , $file)

fileclose ($pic)

shellexecute(@ScriptDir & "\hiddenpic.jpg")

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...