Sign in to follow this  
Followers 0
iamtheky

shuffling and unshuffling

8 posts in this topic

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

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)

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

Share this post


Link to post
Share on other sites



How about this simple solution?

#include <Array.au3>
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
Global $aCount1 = $aCount
_ArrayDisplay($aCount, "Before")

_ArrayShuffle($aCount)
_ArrayDisplay($aCount, "After Shuffling")
_Unshuffle($aCount)
_ArrayDisplay($aCount, "After Unshuffling")

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

Func _Unshuffle(ByRef $aIn)
    $aIn = $aCount1
EndFunc   ;==>_Unshuffle

The _Unshuffle function is just _ArraySwap with a new name. :)


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

unshuffle's inputs only being the keyfile and the shuffled text file.  All in the same script I would just show the $bitArray again :)


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

Share this post


Link to post
Share on other sites

hi boththose

I think in "unshuffle.au3" _ArraySearch ($ aKey, $ i) it is not necessary

you can simply and quickly decode in this way:

for $i = 0 to ubound($aTxt) - 1

       ; $match = _ArraySearch($aKey , $i)
       ; $unwrap[$i] = $aTxt[$match]

       $unwrap[$aKey[$i]] = $aTxt[$i]

next
1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

That is too easy, many thanks for the help!  Now onto *conditions and masking large data sets with obscure keys.

Edited by boththose

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

Share this post


Link to post
Share on other sites

That is too easy, many thanks for the help!  Now onto *conditions and masking large data sets with obscure keys.

 

:blink:


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

All part of a much larger steganography effort.  I can set hidden data, I can now jumble that data. I figure set enough bogus elements in the key file, likewise some bogus elements in the data and the result would be a pretty healthy attempt at hiding in plain sight.


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

Share this post


Link to post
Share on other sites

Probably would have helped immensely if you had explained the purpose of the script(s) rather than asking if there was a better way to unshuffle the array. Not to mention, a simple substitution cipher could probably be broken in a matter of seconds with enough text to work with.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  
Followers 0