Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

shuffling and unshuffling

$
0
0

Is there a better way to output and/or read back in, a jumbled mess and its key.  The following is a simple alphabet example of the effect, my major concern is the _arraysearch in the unshuffle and the time penalty I would take on a larger data set.

 

_ArrayShuffle credit belongs to Malkey I believe

 

shuffle.au3

AutoIt         
Global $bitarray[26] = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] Global $aCount[ubound($bitArray)] For $i = 0 to ubound($bitArray) - 1 $aCount[$i] = $i Next _ArrayShuffle($aCount) $fBits = fileopen("aaa.txt" , 2) for $i = 0 to ubound($bitArray) - 1     If $i = ubound($bitArray) - 1 Then         filewrite($fBits , $bitarray[$aCount[$i]])     Else         filewrite($fBits , $bitarray[$aCount[$i]] & "|")     Endif Next fileclose($fBits) $fKey = fileopen("aaa.key" , 2) for $i = 0 to ubound($bitArray) - 1     If $i = ubound($bitArray) - 1 Then         filewrite($fKey , $acount[$i])     else         filewrite($fKey , $acount[$i] & "|")     Endif Next fileclose($fKey) Func _ArrayShuffle(ByRef $aArray)     SRandom(@AutoItPID)     For $i = UBound($aArray) - 1 To 0 Step -1 ; 0-based array         $j = Random(0, $i, 1)         $Temp = $aArray[$j]         $aArray[$j] = $aArray[$i]         $aArray[$i] = $Temp     Next EndFunc   ;==>_ArrayShuffle

unshuffle.au3

#Include <Array.au3> $sTxt = fileread("aaa.txt") $aTxt = stringsplit($sTxt , "|" , 2) $sKey = fileread("aaa.key") $aKey = stringsplit($sKey , "|" , 2) Global $unwrap[ubound($aTxt)] for $i = 0 to ubound($aTxt) - 1        $match = _ArraySearch($aKey , $i)        $unwrap[$i] = $aTxt[$match]    next _ArrayDisplay($unwrap)

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>