Hello all... I am back! Wooohooo

Lets say I have a string 'Hello' and I convert the string to either dec or hex:
x = dec
y = hex

then it would be:
xxxxx or yyyyy

How would I mix and match the format with dec and hex randomly?

xyyyy etc..

Make sense?

Posted on 2003-05-09 20:24:49 by Gunner


string1 db "xxxxxx", 0
string2 db "yyyyyy", 0

invoke strlen, offset string1
mov ecx, eax
invoke strlen, offset string2
cmp ecx, eax
jbe @f
mov ecx, eax
@@:dec ecx
invoke rand ;most any rand-like proc will do
test eax, 1
jz SK
mov al, byte ptr [string1+ecx]
mov byte ptr [string2+ecx], al
SK:test ecx, ecx
jnz @b

; string2 = mixed-up string[/size]
Posted on 2003-05-09 20:52:39 by iblis
The problem I see is reversing the procedure afterwards:

If I was thinking about doing this though I could not see why, I would consider that the maximum {dig}its in Hex would be 2 and in Decimal would be 3. so each character would have 3 digits if the first character number is "H" it would designate Hex follows if not it is treated as a decimal number. That's just a quick solution off the top of my head.
Posted on 2003-05-09 20:55:59 by donkey
Yes like Donkey said, careful what you're trying to do. If you just want to randomly mix letters together for no reason, that's fine. If you want to be able to decrypt the string at some point you need to set up a mechanism to do so.
Posted on 2003-05-09 20:58:32 by iblis
This is the same question as shuffling a deck of cards (asked on the board already).

Posted on 2003-05-09 21:11:40 by bitRAKE
Afternoon, Gunner.

I started to reply, then decided to get working code up-n-running.

Attached is a test proggy showing one way of randomizing a string.

The randomizing procs were grabbed after a quick search of this board. It's one supplied by resistance_is_futile. All that was needed to make the procs useable, was to save/restore edi/esi in his procs.

Posted on 2003-05-09 22:44:44 by Scronty
Hello.... oHell <lol!>
Posted on 2003-05-10 12:12:22 by NaN
If I remember correctly, one of the 'right ways' to shuffle an array is to loop through it, exchanging each element with a randomly chosen one of the ones left .. i.e.:

for (int i = 0; i < size; ++i) swap(array[i], array[random(i, size)]);

where random(a, b) returns a number between a and b - 1 (both inclusive).

This gives the desired even probability distribution, and only requires size calls to random (as opposed to 1000 ;-).

I did a quick hack on Scronty's code to see if I could get it to work .. so please forgive me if I broke it.
Posted on 2003-05-10 13:12:15 by Jibz