EG Information
Training Missions
Knowledge Bank
|
|
Enigma Group's Code Bank
paswdgenBy: toast - Date Submitted: 2009-04-04 04:31:24 #!/bin/bash # random password generator by typedeaF # This program has no "real" value other than introducing some bash concepts and putting them to use. # to strip the comments: cat this.file | grep -v '^# ' # Sets the maximum size of the password the script will generate MAXSIZE=50 # Holds valid password characters. # Put the non alph-numeric in single quotes so the program knows that it is part of the array and not a seperate part of the program. # Example if the # is not in a set of single or double quotes it will comment out any part of the line after the # symbol and will not reconize the characters as part of the array. array0=( q w e r t y u i o p a s d f g h j k l z x c v b n m Q W E R T Y U I O P A S D F G H J K L Z X C V B N M 1 2 3 4 5 6 7 8 9 0 '!' '@' '$' '%' '^' '&' '#' '*' '(' ')' '+' '-' '=' '|' '/' '<' '>' '~' '`' ':' ';' '[' ']' '{' '}' '|' ',' '.' '?' '_') # Used in conjunction with modulus to keep random numbers in range of the array size MODNUM=${#array0[*]} # Keeps track of the number characters in the password we have generated pwd_len=0 # Bash's command substitution syntax to store the results of the tput command term_clear=$(tput clear) # Stores the number of lines or rows on the terminal display max_lines=$(tput lines) # Stores the number of columns on the terminal display max_cols=$(tput cols) # Finds the appropriate spot to indent for horizontally centered output indent=$(( ((max_cols / 2)) - ((MAXSIZE / 2)) )) # Finds the vertical center of the terminal. line_num=$(( max_lines / 2 )) # Clear the screen echo $term_clear # The outer while loop starts at 0 and loops till MAXSIZE, creating a passwd char each iteration. # The shells $RANDOM variable creates a semi-random unsigned number. This is our entropy. =x # x simply holds some random unsigned int that will be used to make the character scramble. # 500 was choosen for speed and nothing else. Leave out the mod 500 if you want or change it. # The inner loop displays the password characters. Tput keeps the cursor in the proper position. # Mod MODNUM keeps the random number inside the size of the array so it doesnt over index. while [ $pwd_len -lt $MAXSIZE ] do x=$(($RANDOM%500)) y=0 while [ $y -lt $x ] do ((y++)) index=$(($RANDOM%$MODNUM)) tput cup $line_num $(( indent + pwd_len )) echo -n "${array0[$index]}" done ((pwd_len++)) done # Place the cursor at the bottom of the screen --where is usually at. tput cup $max_lines 0 exit 0
|
| Return to
bash category list |
|
|
Who's Online
487 Guests, 100 Users ckryptix, TheRetech, Diznablo, Nicid1, Ios, viper0i0, rabbidmind, Nasrudin, CollapsingWalls, mehtaparag, bitstrike, jnony, C, Nusquam-Redono-Sapientia, bazcrown, saifulfaizan, The End, Ultraminor, psychomarine, st3alth, themastersinner, pgmrlink, login, lionaneesh, ishkur88, mahraja, Mac, chekifr, gandalf88, Vap0r, t0ast, tantrum6226, BnE, Distorted, Psiber_Syn, Ausome1, invas10n, oldgoat, freedaysbecumei, BinaryShinigami, Rex_Mundi, Red_beard, Strobeflux, s0m3nak3dguy, Descent, teehee, machupicchu, Genetix, Anandarl, NotMyOwn, thegamerdude, Godzila, popo12341234, RedEvolution, velocity_b, myne17, teto111, aVoid, Central-Gsm, 1101, JackalReborn, InjectioN, h4lted, c0re, DisPater, markt4death, splatta, Jackowacko, saint556, Pyron2312, Azerion, howsens, white.hat.gone.bad, vazzilly, pwunkz, Inverted, QuarterCask, Infernoe11, deskata, cr4ck3rj4ck, Blizer, jasonmax, j0sh, gwenwavor, N4g4c3N, spizeyboy, Network X, Uino59, Jae Cee, ianFDK, saykov, medhaavee, zofy, demonkiller410, Stumble, SaMTHG, kishore, Raze, helasraizam, Venom1019 |
| |
|
|
|
|
|