Announcement

Collapse
No announcement yet.

An algo for making messy random strings.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Theo Gottwald
    replied
    I definitely like all your Coding Hutch, keep it coming.

    Leave a comment:


  • Steve Hutchesson
    replied


    Theo, you could code a genuinely fast one but why bother, the string are just not long enough. Think of a 256 character table and a fast random but would you see the difference on a 1k string ?

    Leave a comment:


  • Theo Gottwald
    replied
    Haha, this is really sort of Fake-ASM-Coding Hutch.
    If you write "GOTO" there will be no difference because it will also compile to "JMP".
    And the rest is just basic.
    Especially the line "SRC$=SRC$+CHR$()" will be limiting the speed of the subprogramm.
    This is where you need to make changes to speed things up.

    Leave a comment:


  • Steve Hutchesson
    replied
    Hi Stuart,

    This one should keep everyone happy, it excludes the ascii 0 and filters out numbers, upper and lower case and the output looks truly disgusting, exactly how I wanted this string data to look like.
    Code:
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
        #include "\basic\include\win32api.inc"
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
    FUNCTION PBmain as LONG
    
        LOCAL lcnt as DWORD
    
        lcnt = 1000
    
      lbl:
        StdOut randstr
        ! sub lcnt, 1
        ! jnz lbl
    
        waitkey$
    
    End FUNCTION
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
    FUNCTION randstr() as STRING
    
        #REGISTER NONE
    
        LOCAL var  as DWORD
        LOCAL ccnt as DWORD
        LOCAL rnm  as DWORD
    
        ! db &H0F,&H31
        ! db &H0F,&HC8
        ! mov var, eax
    
        randomize var                       ' seed the PB rnd function
    
        src$ = ""                           ' allocate an empty basic string
    
        ccnt = rnd(11,71)                   ' make output variable length
        ! mov esi, ccnt
    
      lbl:
        rnm = rnd(1,255)
    
        If rnm > 47 and rnm < 58 Then       ' no numbers
          ! jmp lbl
        End If
    
        If rnm > 64 and rnm < 91 Then       ' no upper case
          ! jmp lbl
        End If
    
        If rnm > 96 and rnm < 123 Then      ' no lower case
          ! jmp lbl
        End If
    
        src$ = src$ + chr$(rnm)
    
        ! sub esi, 1
        ! jnz lbl
    
        FUNCTION = src$
    
    End FUNCTION
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    Leave a comment:


  • Steve Hutchesson
    replied
    Its a nice enough box to use, I have de-trashed most of the junk in Win10 64 and have most of the software loaded, it ingested another 4 tb WD red HDD and there is not much more to add to it. I may do a mod in the future of adding an NVMe drive in one of the PCI slots but I am tired of throwing money at it so there is no hurry. The board was the expensive bit, I got the Xeon from a vendor in China for about 1/10th the original cost.

    Leave a comment:


  • David Roberts
    replied
    Originally posted by Steve
    Its an empty argument for the following CPUID instruction.
    Gotcha!

    here is your penance
    Strewth!

    A 12/24 with 30MB cache. Wow, that is some kit.

    Leave a comment:


  • Steve Hutchesson
    replied
    Stuart,

    Sorry to be a bit slow, I had to find your post again. You are shifting from a basic dynamic string to a zero terminated string which is different to how its used. This test piece shows that basic string remains the length specified in the function call. Now if you come back to what the algo is used for in an application, a different string every time the app is run for both class names and private message strings, even if the string is interpreted as zero length, it does the job and will be different next time it is run.
    Code:
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
        #include "\basic\include\win32api.inc"
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
    FUNCTION PBmain as LONG
    
        LOCAL lcnt as DWORD
    
        lcnt = 0
    
      lbl:
        StdOut format$(len(randstr(128)))
        ! add lcnt, 1
        ! cmp lcnt, 1000
        ! jbe lbl
    
        waitkey$
    
    End FUNCTION
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
    FUNCTION randstr(ByVal ccnt as DWORD) as STRING
    
        #REGISTER NONE
    
        LOCAL var as DWORD
        LOCAL cnt as DWORD
    
        ! db &H0F,&H31
        ! db &H0F,&HC8
        ! mov var, eax
    
        randomize var
    
        src$ = ""
    
        cnt = 0
        ! mov esi, ccnt
    
      lbl:
        src$ = src$ + chr$(rnd(0,255))
        ! add cnt, 1
        ! cmp cnt, esi
        ! jne lbl
    
        FUNCTION = src$
    
    End FUNCTION
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    Leave a comment:


  • Steve Hutchesson
    replied
    David,

    Its an empty argument for the following CPUID instruction.
    If a value entered for CPUID.EAX is less than or equal to the maximum input value and the leaf is not supported on
    that processor then 0 is returned in all the registers.
    Now for all the waffle I have had to listen to, here is your penance, the video on building my latest Xeon box. https://www.youtube.com/watch?v=DV29EOEi6Mc

    Leave a comment:


  • David Roberts
    replied
    BTW, folks, Steve's post #9 reads the Time Stamp eleven times and in that case bswap comes into its own.

    Leave a comment:


  • David Roberts
    replied
    Repost of post #11 re post #9.

    Steve, question: What is 'mov rax, 100 ; out of range number' for?

    Leave a comment:


  • David Roberts
    replied
    Originally posted by Yours truly
    I say machine code because at the time I did not have an assembler and typed in hex code.
    ! db &H0F,&H31 ==> rdtsc
    ! db &H0F,&HC8 ==> bswap eax

    Not sneaky enough, Steve.

    You mentioned 'whining' and 'acronym' again. If you are trying to wind me up you will have to do better than that.

    ... it does what it is supposed to do, nothing else.
    So does RtlGenRandom( szClassName, 64 ).

    Leave a comment:


  • Steve Hutchesson
    replied
    He he,

    Here is yet another variation that may slow down the whining. Add another acronym, it may sound profound.
    Code:
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
    FUNCTION randstr(ByVal ccnt as DWORD) as STRING
    
        #REGISTER NONE
    
        LOCAL var as DWORD
        LOCAL cnt as DWORD
    
        ! db &H0F,&H31
        ! db &H0F,&HC8
        ! mov var, eax
    
        randomize var
    
        src$ = ""
    
        cnt = 0
        ! mov esi, ccnt
    
      lbl:
        src$ = src$ + chr$(rnd(0,255))
        ! add cnt, 1
        ! cmp cnt, esi
        ! jne lbl
    
        FUNCTION = src$
    
    End FUNCTION
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    > I looked at your post #16 and it did not do a lot for me.

    I can promise you the algo design, simple as it is was not designed to "do a lot" for anyone, it does what it is supposed to do, nothing else.

    Leave a comment:


  • David Roberts
    replied
    Originally posted by Steve
    You appear to have missed what the posted algo does
    As John Wayne would say: "The hell I did!"

    how many unintelligible acronyms have I heard out of you over the last few years ?
    Unintelligible acronyms? None. If ever I use an acronym, like NIST for example, I would write National Institute of Standards and Technology (NIST) and then use NIST thereafter. I think you meant something else - not acronyms. Perhaps you meant metaphor. I am from Yorkshire, England, and we are very metaphorical. Have a conversation with a Yorky and it is like talking to a poet. Having said that, you'd probably end up scratching your head until the cows come home.

    your whining seems to have missed the rest of the mnemonics
    Whining? Your perception is shot to pieces.

    Now the only reason I can think of is that both you and Stuart are suffering lockdown boredom ...
    If that is the only reason I suggest that you go for a walk in the park and give it a bit more thought.

    I looked at your post #16 and it did not do a lot for me.

    as long as you don't look at the macro.
    I don't have a major issue with your idea - never did have. It is just another tool in the toolbox. As I keep saying I use a CPRNG to seed a PRNG. I use an API - so what? If two pieces of code are below the noise floor it matters not which is the fastest.


    Leave a comment:


  • Steve Hutchesson
    replied
    WTF?
    Using CHR$(0 to 255) to generate a Windows class name (NULL-TERMINATED) string?
    WTF,
    The most you can lose is one trailing zero and remember, its being written to a basic dynamic string that can contain ascii zeros.


    Leave a comment:


  • Steve Hutchesson
    replied
    Stuart,

    > WIth a register that is rotating through the 2^32 values in the DWORD about every 2 seconds and a single request for a seed for the RNG, what is the "sequential" aspect you are so concerned about?

    You have misunderstood BSWAP. It does not rotate the register, it reverses the byte order.

    00112233 becomes 33221100

    Leave a comment:


  • Stuart McLachlan
    replied
    OK, I finally looked at the algorithm link.

    WTF?
    Using RND(0 to 255) to generate a Windows class name (NULL-TERMINATED) string?

    1 in 256 times, you generate a NULL string.
    I'll leave it up to others to work out how many times you end up with a 1,2 or 3 character string

    Added: Ok, I decided to do it myself;
    '
    Code:
    #COMPILE EXE
    FUNCTION PBMAIN() AS LONG
        LOCAL x,y AS LONG
        LOCAL q AS QUAD
        LOCAL s AS STRING
        LOCAL sWinName AS STRINGZ*65
        LOCAL hTxt AS DWORD
        DIM aLen(0 TO 64) AS LONG
        TIX q
        RANDOMIZE LO(DWORD,q)
        FOR x = 1 TO 10000
            s=""
            FOR y = 1 TO 64
                s+=CHR$(RND(0,255))
            NEXT
            sWinName = s
            INCR aLen(LEN(sWinName))
         NEXT
        s="Len  Count" & $LF
        FOR x = 0 TO 3
            s += STR$(x) & $TAB & STR$(aLen(x)) & $LF
        NEXT
        ? s
    
    END FUNCTION
    '

    Leave a comment:


  • Steve Hutchesson
    replied
    Here is a variation that should keep you happy as long as you don't look at the macro.
    Code:
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
      MACRO Dont_Call_This_Reseeding
        MACROTEMP nvar
        LOCAL nvar as DWORD
        ! rdtsc
        ! bswap eax
        ! mov nvar, eax
        randomize nvar
      END MACRO
    
    FUNCTION randstr(ByVal ccnt as DWORD) as STRING
    
        #REGISTER NONE
    
        LOCAL cnt as DWORD
    
        Dont_Call_This_Reseeding
    
        src$ = ""
    
        cnt = 0
        ! mov esi, ccnt
    
      lbl:
        src$ = src$ + chr$(rnd(0,255))
        ! add cnt, 1
        ! cmp cnt, esi
        ! jne lbl
    
        FUNCTION = src$
    
    End FUNCTION
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    Leave a comment:


  • David Roberts
    replied
    Thanks, Dale. I have had this jpg on my desktop since I joined FreeBASIC.

    Click image for larger version

Name:	Registers.jpg
Views:	130
Size:	47.6 KB
ID:	801425

    Stuart:

    It is funny how the brain works. We don't buy into a statement. We don't buy into another statement. Another statement comes along and we buy into it.

    The BSWAP is superfluous in this use case
    You have persuaded me.

    Leave a comment:


  • Steve Hutchesson
    replied
    > What bias? I cannot be bothered to search for it but you introduced the '! rdtsc, ! bswap eax' combo quite a while ago and reintroduced it again only recently. You then use it again in the opening post's link. That is what I meant with "flogging the death out of ...".

    You appear to have missed what the posted algo does, it seeded the PB randomize so that the following loop could produce a sequence of random characters. It used the old PB rnd so it was easier to understand and was very simple code.

    The seeding is small, fast and extremely difficult to duplicate yet there are many bigger, slower techniques that could be use, get the result from GetTickCount and BSWAP it but that involves an API call. There are many other methods but I doubt they are that small or as fast as the RDTSC BSWAP combination.

    Now as far as "flogging to death", how many unintelligible acronyms have I heard out of you over the last few years ?

    As far as the choice of mnemonics, your whining seems to have missed the rest of the mnemonics.
    Code:
      MOV
      ADD
      CMP
      JNE
    I can assure you I HAVE flogged all of these but not to death, just mercilessly for years and there are many others.

    Now the only reason I can think of is that both you and Stuart are suffering lockdown boredom, can't you find a good movie to watch, roll on down to your local pub and do injustice to a few pints, go for a walk in the park or something productive ?

    Leave a comment:


  • Stuart McLachlan
    replied
    Originally posted by David Roberts View Post
    Using bswap made sense to me, destroying the sequential aspect of rdtsc, and I could not understand the objections to it.
    WIth a register that is rotating through the 2^32 values in the DWORD about every 2 seconds and a single request for a seed for the RNG, what is the "sequential" aspect you are so concerned about?

    Unless you are re-seeding the RNG repeatedly in a very short time frame there is no "sequential aspect".. The BSWAP is superfluous in this use case



    Leave a comment:

Working...
X