Password Generator Help

Started by Frank Brübach, August 01, 2024, 08:51:30 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

Hi Charles..

Thx for your Last Update..

I have built a Password Generator but I have this rnd() Problem again.. perhaps you can Help to Fux IT.. I have tried rnd irnd Rand but without success..

' password generator, oxygen
'
uses console

sys seed=0X12345678

Function Rnd(sys z1,z2) as sys
    pushad
    sys  rand
    mov  eax,z2
    sub  eax,z1
    inc  eax
    imul edx,seed,0x8088405
    inc  edx
    mov  seed,edx
    mul  edx
    add  edx,z1
    mov  rand,edx
    popad
    Return rand
End Function


function rand(sys z1,z2) as sys
mov eax,z2
sub eax,z1
inc eax
imul edx,seed,0x8088405
inc edx
mov seed,edx
mul edx
add edx,z1
return edx
end function
'seed=12345 : print rand 1,100 '39


  'ABS RANDOMISER
  '
  function arnd() as float
  ========================
  int v1,v2
  return Abs(Rnd(v1,v2) )
  end function


  function irnd(int z1, z2) as int
  ================================
  mov    eax,z2
  sub    eax,z1
  inc    eax
  imul   edx,Seed,0x8088405
  inc    edx
  mov    Seed,edx 'store new seed
  mul    edx 'multiply eax by edx
  return edx+z1
  end Function

'------------------------------------------------
' Function to generate a pronounceable password
'
function GeneratePassword() as string
    string vowels = "aeiouy"
    string consonants = "bcdfghjklmnpqrstvwxz"
    string consonantPairs = "blbrchclcrdrffflfrglgrgwklkrmrplprpwqurwshslsmsnstvlvr"
    string password = ""
    string part = ""
    int i

'    RANDOMIZE TIMER

    for i = 1 to 3 'RND, RAND
        if irnd(1,10) > 0.5 then ' rnd()
            part = mid(consonants, int(irnd(1,10) * len(consonants)) + 1, 1)
        else
            part = mid(consonantPairs, int(irnd(1,10) * len(consonantPairs)) + 1, 2)
        end if
        part = part + mid(vowels, int(irnd(1,10) * len(vowels)) + 1, 1)
        if irnd(1,10) > 0.5 then
            part = part + mid(consonants, int(irnd(1,10) * len(consonants)) + 1, 1)
        else
            part = part + mid(consonantPairs, int(irnd(1,10) * len(consonantPairs)) + 1, 2)
        end if
        password = password + part
        if i < 3 then
            password = password + "-"
        end if
    next

    return password
   
end function

    string generatedPassword
    generatedPassword = GeneratePassword()
    mbox "Generated Password: " + generatedPassword
    print "Generated Password: " + generatedPassword

wait
printl " push any key to exit"
wait


Charles Pegge

#1
Hi Frank,

This is my take, using bytes to simplify the code. It is quite easy to change the construction.

uses corewin
uses console

quad seed
QueryPerformanceCounter(@seed)

  'from chaos.inc
  function irnd(int z1, z2) as int
  ================================
  '
  'returns integer between z1 and z2
  '
  mov    eax,z2
  sub    eax,z1
  inc    eax
  imul   edx,Seed,0x8088405
  inc    edx
  mov    Seed,edx 'store new seed
  mul    edx 'multiply eax by edx
  return edx+z1
  end Function


function NewPassword() as string
================================
string s=nuls 6 'fixed length
string vc="aeiouy" '6
string cc="bcdfghjklmnpqrstvwxz" '20
string uc="BCDFGHJKLMNPQRSTVWXZ" '20
string nc="0123456789" '10
byte b at strptr s
QueryPerformanceCounter(@seed) 'randomize seed
'
'6 characters fixed length
b=asc(uc,irnd(1,20) ) 'upper consonant
@b++
b=asc(vc,irnd(1,6) ) 'vowel
@b++
b=asc(cc,irnd(1,20) ) 'consonant
@b++
b=asc(vc,irnd(1,6) ) 'vowel
@b++
b=asc(cc,irnd(1,20) ) 'consonant
@b++
b=asc(nc,irnd(1,10) ) 'number
@b++
return s
end function

print "Random passwords:" cr
print "permutations: " 20*6*20*6*20*10 cr cr
int i
for i=1 to 10
  print NewPassword() cr
next
wait

Frank Brübach

#2
Good morning and thank you Charles..

Learned again new Things with oxygen.. often I am surprised whats possible

My Take below, but Theres only left a few of my Code..

' password generator, oxygen, part two, frank
'
uses console
uses corewin

quad seed=0X12345678
QueryPerformanceCounter(@seed)

  function irnd(int z1, z2) as int
  ================================
  '
  'returns integer between z1 and z2
  '
  mov    eax,z2
  sub    eax,z1
  inc    eax
  imul   edx,Seed,0x8088405
  inc    edx
  mov    Seed,edx 'store new seed
  mul    edx 'multiply eax by edx
  return edx+z1
  end Function

'------------------------------------------------
' Function to generate a pronounceable password
'
function GeneratePassword() as string
    string st=nuls 6 'fixed length
    string vowels = "aeiouy"
    string consonants = "bcdfghjklmnpqrstvwxz"
    string consonantPairs = "blbrchclcrdrffflfrglgrgwklkrmrplprpwqurwshslsmsnstvlvr"
    'string password = ""
    'string part = ""
    string nuc="0123456789" '10
    int i   
    byte pw at strptr st

' randomize timer
QueryPerformanceCounter(@seed) 'randomize seed

pw=asc(consonantPairs,irnd(1,20) ) 'upper consonant
@pw++
pw=asc(vowels,irnd(1,6) ) 'vowel
@pw++
pw=asc(consonants,irnd(1,20) ) 'consonant
@pw++
pw=asc(vowels,irnd(1,6) ) 'vowel
@pw++
pw=asc(consonants,irnd(1,20) ) 'consonant
@pw++
pw=asc(nuc,irnd(1,10) ) 'number
@pw++


'    RANDOMIZE TIMER

''    for i = 1 to 10 '3 'RND, RAND
''        if irnd(1,10) > 0.5 then ' rnd()
''            part = mid(consonants, int(irnd(1,10) * len(consonants)) + 1, 1)
''        else
''            part = mid(consonantPairs, int(irnd(1,10) * len(consonantPairs)) + 1, 2)
''        end if
''        part = part + mid(vowels, int(irnd(1,10) * len(vowels)) + 1, 1)
''        if irnd(1,10) > 0.5 then
''            part = part + mid(consonants, int(irnd(1,10) * len(consonants)) + 1, 1)
''        else
''            part = part + mid(consonantPairs, int(irnd(1,10) * len(consonantPairs)) + 1, 2)
''        end if
''        password = password + part
''        if i < 3 then
''            password = password + "-"
''        end if
''    next

'    return password
     return st
   
end function

print "Random passwords: " cr
print "permutations: " 20*6*20*6*20*10 cr cr
int i
for i=1 to 10
  print generatePassword() cr
next

wait
printl " push any key to exit"
wait

And have built this Code for freebasic too Looks Like this one and Works perfect

Freebasic
' FreeBASIC Password Generator,  Frank bruebach, 01-08-2024

#include "windows.bi"

' Function to generate a pronounceable password
FUNCTION GeneratePassword() AS STRING
    DIM AS STRING vowels = "aeiouy"
    DIM AS STRING consonants = "bcdfghjklmnpqrstvwxz"
    DIM AS STRING consonantPairs = "blbrchclcrdrffflfrglgrgwklkrmrplprpwqurwshslsmsnstvlvr"
    DIM AS STRING password = ""
    DIM AS STRING part = ""
    DIM AS INTEGER i

    RANDOMIZE TIMER

    FOR i = 1 TO 3
        IF RND > 0.5 THEN
            part = MID(consonants, INT(RND * LEN(consonants)) + 1, 1)
        ELSE
            part = MID(consonantPairs, INT(RND * LEN(consonantPairs)) + 1, 2)
        END IF
        part = part + MID(vowels, INT(RND * LEN(vowels)) + 1, 1)
        IF RND > 0.5 THEN
            part = part + MID(consonants, INT(RND * LEN(consonants)) + 1, 1)
        ELSE
            part = part + MID(consonantPairs, INT(RND * LEN(consonantPairs)) + 1, 2)
        END IF
        password = password + part
        IF i < 3 THEN
            password = password + "-"
        END IF
    NEXT

    RETURN password
END FUNCTION

' Main function
FUNCTION show() AS INTEGER
    DIM AS STRING generatedPassword = GeneratePassword()
    MessageBox(0, generatedPassword, "Generated Password", MB_OK)
    RETURN 0
END FUNCTION

' Entry point
show()