Hack Forums
[Shell] Generating specific string - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] Generating specific string (/showthread.php?tid=6129725)



Generating specific string - absojedi - Dec 26, 2020

I need some tips on how to generate random strings with that contain only ^[A-Z1-9] (Yes, 1-9, without 0)

I can do this in the online generators, but I need to have this format A1B2C3.... etc letter,number,letter,number

Is there a fast way to do this with Fedora terminal? Should I install something?


RE: Generating specific string - Hackoo - Dec 27, 2020

(Dec 26, 2020 03:35 PM)absojedi Wrote:  I need some tips on how to generate random strings with that contain only ^[A-Z1-9] (Yes, 1-9, without 0)

I can do this in the online generators, but I need to have this format A1B2C3.... etc letter,number,letter,number

Is there a fast way to do this with Fedora terminal? Should I install something?

Perhpas a solution in vbscript that i have in my mind but still no tested yet ?
So you want to generate and validate someting like this combination of strings :
B5A3Z4R8H2...
And How long must be this output string ?


RE: Generating specific string - Emre_ - Dec 27, 2020

You can generate a random password with this batch script.


Code
@echo off & cls

setlocal enabledelayedexpansion

:Start
Cls
Echo.
Echo.


Set /p len="Password Length: "

Cls

set "alp=a A b B c C d D E e f F g G h H I I j J k K l L m M n N p P q Q r R s S t T u U v V w W x X y Y z Z 0 1 2 3 4 5 6 7 8 9"
set "cnt=0"
for %%a in (%alp%) do (
    set "rn.!cnt!=%%a"
    set /a "cnt+=1"
)
for /l %%i in (1,1,1) do (
set "pssw="
for /l %%a in (1,1,%len%) do (
    set /a "rand=!random! %% cnt"
    for %%b in (!rand!) do set "pssw=!pssw!!rn.%%b!"
)
Echo.
Echo Your random password is:  !pssw!
)

Echo.
Pause
Goto :Start



RE: Generating specific string - absojedi - Dec 27, 2020

(Dec 27, 2020 10:45 AM)Hackoo Wrote:  Perhpas a solution in vbscript that i have in my mind but still no tested yet ?
So you want to generate and validate someting like this combination of strings :
B5A3Z4R8H2...
And How long must be this output string ?

It should be 10 chars long, but I already got it. I found this bash script
Code
#!/bin/bash
function generate { local length=$1; local letters=ABCDEFGHIJKLMNOPQRSTUVWXYZ; local numbers=123456789; for i in $(seq 1 "$length") ; do if (( i % 2 != 0)); then echo -n "${letters:RANDOM%${#letters}:1}"; else echo -n "${numbers:RANDOM%${#numbers}:1}"; fi; done; echo; }