Jump to content

Random Mouse moves from true random data


Chika95
 Share

Recommended Posts

#cs
Random Mouse Mover

Purpose: To inject true randomness into encryption programs that use mouse movements to seed CSPRNG

How:
    Reads in the first XXXX bytes of a File
    Reads the dimensions of the window you want to stay in
    Takes the random bytes and generate random mouse movements
        The first byte is how far it will move in the X direction
        The second byte is how far it will move in the y direction
        the third byte is the direction
        the forth byte is the speed
        repeat

Notes:
Go to Random.org, download integers from 0-255 in hex format, use a hex editor to create a file with true random data and use this as your random file
It's currently set up for the Truecrypt Volume Creation Wizard window
Take focus off window to quit program while mouse is moving
Program was done quick and dirty, I should have created sub functions, got rid of my debug code, etc, but I wrote this for myself, feel free to clean it up
        
#ce
#include<Array.au3>
$FileLocation = "Y:\randomfile"
$NumberOFBytes = 100 ;The larger this is the longer the mouse will move
$NameOFWindowToMoveRandomlyIn = "TrueCrypt Volume Creation Wizard" ;The window for the mouse to stay in
$CenterMouse = 1 ;Recenter mouse if it moves out of bounds?  If not, move back to the last position
$PercentOFMinWindowWidthToMove = 0.15 ;Set higher to move further, lower to move less, affects X and Y Distance


dim $Array[$NumberOFBytes +1][6] ;make sure this number is 1 + $NumberOFBytes

$FileHandle = FileOpen ($FileLocation,16) ;Read only, Force Binary
$RandomData = fileread($FileHandle,$NumberOFBytes) ;Read in the entire number of bytes requested 
$RandomData = StringTrimLeft($RandomData, 2) ;Trim the 0x from the left side of the hex string


$WindowPosition = WinGetPos($NameOFWindowToMoveRandomlyIn)
$TopLimit = $WindowPosition[1]
$BottomLimit = $WindowPosition[1] + $WindowPosition[3]
$LeftLimit = $WindowPosition[0]
$RightLimit = $WindowPosition[0] + $WindowPosition[2]

;Determine which is smaller the width oft he height, and use 5% of that as your maximum move
    IF $WindowPosition[2]< $WindowPosition[3] then 
        $MaxRandomNumber = round($PercentOFMinWindowWidthToMove *  $WindowPosition[2],0)
    else
        $MaxRandomNumber = round($PercentOFMinWindowWidthToMove *  $WindowPosition[3],0)
    EndIf


;--------------------------------
;Fill in the first 2 columns of an array with the random data
    $Array[0][0] = $NumberOFBytes & " Random Bytes(hex)" ;Set the UBOIUND to the 0th dimension
    $Array[0][1] = $NumberOFBytes & " Random Bytes(Dec)"
for $i = 1 to $NumberOFBytes
    
    $Array[$i][0] = Stringleft($RandomData, 2) ;Read in the left two hex numbers
    $Array[$i][1] = dec($Array[$i][0]) ;Put the Dec equivalent in the next column
    $RandomData = StringTrimLeft($RandomData, 2) ;Trim the string of the previously read hex number
    
next
FileClose($FileHandle)
;---------------------
;Fill in the names oft he top of the coloumns (Used for _Array_Display
$Array[0][2] = "Move X Position"
$Array[0][3] = "Move Y Position"
$Array[0][4] = "Sign"
$Array[0][5] = "Speed"

for $i = 1 to $NumberOFBytes-3 step 4
    
     $Array[$i][2] = round($Array[$i][1]/255 * $MaxRandomNumber,0)   ;Move This many places X
     $Array[$i][3] = round($Array[$i+1][1]/255 * $MaxRandomNumber,0) ;Move This many places Y
     $Array[$i][4] = int($Array[$i+2][1]/255*4) + 1 ;Move This many places Y
     $Array[$i][5] = int($Array[$i+3][1]/255*20) + 5 ;Speed
    
next

;_ArrayDisplay($Array)
;;------------------------------------------------------
Winactivate($NameOFWindowToMoveRandomlyIn)

    $MousePosition = MouseGetPos()
    MouseMove($WindowPosition[0] + $WindowPosition[2]/2, $WindowPosition[1] + $WindowPosition[3]/2, 0) ;CenterMouse

for $i = 1 to $NumberOFBytes-3 step 4
    
    IF $NameOFWindowToMoveRandomlyIn <> WinGetTitle("") then exitloop ;Quit if you alt-tab
        
    $MousePositionBefore = MouseGetPos()
    $X = $Array[$i][2]
    $Y = $Array[$i][3]
    $Speed = $Array[$i][5]
    ;$Speed = 1
    Select ;Move the mouse
        Case $Array[$i][4] = 1
            Mousemove($MousePositionBefore[0] + $X, $MousePositionBefore[1] + $Y, $Speed)
        Case $Array[$i][4] = 2
            Mousemove($MousePositionBefore[0] - $X, $MousePositionBefore[1] - $Y, $Speed)
        Case $Array[$i][4] = 3
            Mousemove($MousePositionBefore[0] - $X, $MousePositionBefore[1] + $Y, $Speed)
        Case $Array[$i][4] = 4
            Mousemove($MousePositionBefore[0] + $X, $MousePositionBefore[1] - $Y, $Speed)
        EndSelect
        
        ;If you are out of the bounds of the window recenter yourself, or move back to the last position
        $MousePositionAfter = MouseGetPos()
        IF ($MousePositionAfter[0] > $RightLimit OR $MousePositionAfter[0] < $LeftLimit) OR ($MousePositionAfter[1] > $BottomLimit OR $MousePositionAfter[1] < $TopLimit) Then
            IF $CenterMouse = 1 Then
                MouseMove($WindowPosition[0] + $WindowPosition[2]/2, $WindowPosition[1] + $WindowPosition[3]/2, $Array[$i][5]) ;ReCenterMouse
            Else
                mousemove($MousePositionBefore[0],$MousePositionBefore[1],$Array[$i][5] )
            EndIf
            
        EndIf;
next


exit

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...