How to scramble words with random characters ? (1 Viewer)

smig

Registered User.
Local time
Today, 19:30
Joined
Nov 25, 2009
Messages
2,209
Hello

I want to scramble words with random characters - replace any character in the word with a random character (Hebrew)
It can be a total random as I don't need to restore the original ones.

Any idea ?

Thanks
Tal
 

JHB

Have been here a while
Local time
Today, 18:30
Joined
Jun 17, 2012
Messages
7,732
Do you have a table with words?
Do you want to pick a word and then scramble it or ..??
How many letters in a word should be replaced?
 

smig

Registered User.
Local time
Today, 19:30
Joined
Nov 25, 2009
Messages
2,209
Do you have a table with words?
Do you want to pick a word and then scramble it or ..??
How many letters in a word should be replaced?
Yes, I have a table with words (Names) and I want to pick a word (Name can have few words) and scramble it - replace all characters with random ones (Hebrew). Result will be unreadable words :D

I'm on my mobile so I can't get to my PC. However I have a copy on GDrive, not sure if this method of sharing will work... If not, let me know.

Scramble
https://drive.google.com/file/d/0B8a1BEePabsxyzVEzNDRIYjBjRDA/view?usp=drivesdk

Sent from my SM-G925F using Tapatalk
Thanks.
This is nice but not what I need.
What I need is to replace the name's letters with random ones.

I only need an idea for a function that will repalce a character with a random one - pick a random Hebrew character.
I know how to pick a random number but not a random Char :confused:
No need for the full process.
 
Last edited by a moderator:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:30
Joined
Jul 9, 2003
Messages
16,244
Yes, I know what you mean, scrambling the existing letters is not good enough, as it could be possible to recreate the original word.

Sent from my SM-G925F using Tapatalk

Edit... Could be on 8 out of 10 cats does count down!
 
Last edited:

JHB

Have been here a while
Local time
Today, 18:30
Joined
Jun 17, 2012
Messages
7,732
..
I know how to pick a random number but not a random Char :confused:
No need for the full process.
Can't you use the [FONT=Arial, helvetica, sans-serif]CHR(RandomNo)?[/FONT]
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:30
Joined
Feb 28, 2001
Messages
26,999
I know how to pick a random number but not a random Char

Ah, but you do. You just don't realize that you do.

First, what is a string? Just a sequence of individual characters associated with each other by being part of a string variable. Each character is just a number in a byte (normal fonts) or word (Unicode fonts). BUT until they are expressed via a font-based display mechanism, they are just numbers in a sequence of variables identifiable from each other by a positional number and all of them are of type CHARACTER.

Take a look at your Hebrew Character font using Font Viewer. When you hover on a proper character, you see a character number in the tool tip. Usually, the letters of any font are arranged to avoid gaps. I don't know what Font you are using, but I found Hebrew in the Unicode "Narkisim" Font on my system. In that font, Alef is character x05D0, Bet is x05D1, ..., Shin is x05E9, and Tav is x05EA. That is a span of 27 characters in that font - with no gaps. The special diacritical markers for vowel sounds are outside that range.

For that font, your functional character range is the 27 values from x05D0 (1488 decimal) to x05EA (1514 decimal). Not that different from ASCII, really, where upper-case A is x041 (65 decimal) and Z comes 25 letters after A.

For this situation, you want to use the random number generator to build a number from 1488 to 1514, a span of 27. Something like "RndNum = FIX(RND(27)) + 1488" because of course Rnd(x) gives you a random number from 0 to x-1.

All you need to do then is take the original string and do a "Mid(X, pos, size) = Chr(RndNum)" and you have obscured the original character. The only wrinkle is whether you had a non-Unicode font for your Hebrew characters because that contributes to whether you have bytes or words for each character. But normally Access should take care of that fine point for you. And the reason you use CHR(x) is simple. It is a type conversion, just like CLng(x) gives you X in a longword. Chr(x) gives you x in a character.
 

smig

Registered User.
Local time
Today, 19:30
Joined
Nov 25, 2009
Messages
2,209
Thanks

The Hebrew Ascii is at 128-154 Decimal
If I try to put
Code:
        RndNum = Fix(Rnd(27)) + 1488
        Debug.Print Chr(RndNum)
I get an "Invalid procedure call or Argument" error, on the Debug.Print line
If I replace the 1488 with 128 I get a Euro signs, but I get them all times for all characters, seems the Rnd does not work.
What am I doing wrong here ?

*** Edit ***
I forgot to Randomize :banghead:
But still can't find the correct characters
 
Last edited:

smig

Registered User.
Local time
Today, 19:30
Joined
Nov 25, 2009
Messages
2,209
Solved :)

Hebrew Characters seems to hide in Chr(224) to Chr(250) :banghead:

This will work for me.
Code:
Public Function fnScrambleWord(strWord) As String

Dim RndNum As Long
Dim i As Long

fnScrambleWord = ""

If Trim(strWord & "") <> "" Then
    For i = 1 To Len(strWord)
        If Mid(strWord, i, 1) <> " " Then
            Randomize
            RndNum = Int((250 - 224 + 1) * Rnd + 224)
            fnScrambleWord = fnScrambleWord & Chr(RndNum)
        Else
            fnScrambleWord = fnScrambleWord & Mid(strWord, i, 1)
        End If
    Next i
End If

End Function
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:30
Joined
Feb 28, 2001
Messages
26,999
The actual codes you need to use depend on the font you use. I have no doubt that Hebrew characters appear in more than one font file, and there is no reason to expect them all to be the same values in each font file. So it doesn't surprise me to know that the offsets were different because the font was different.

Glad you could make it work.
 

smig

Registered User.
Local time
Today, 19:30
Joined
Nov 25, 2009
Messages
2,209
The actual codes you need to use depend on the font you use. I have no doubt that Hebrew characters appear in more than one font file, and there is no reason to expect them all to be the same values in each font file. So it doesn't surprise me to know that the offsets were different because the font was different.

Glad you could make it work.
What the font file has to do with Access table? :confused:
Still, you gave me the right direction :)

Sent from my m2 note using Tapatalk
 

Users who are viewing this thread

Top Bottom