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?
yxyxx
xyyxy
xyyyy etc..
Make sense?
Thanks
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?
yxyxx
xyyxy
xyyyy etc..
Make sense?
Thanks
pseudo-ish:
[size=12].data
string1 db "xxxxxx", 0
string2 db "yyyyyy", 0
.code
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
ret
; string2 = mixed-up string[/size]
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.
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.
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.
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
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.
Cheers,
Scronty
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.
Cheers,
Scronty
Hello.... oHell <lol!>
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.:
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.
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.