Created
July 19, 2024 23:40
-
-
Save nullifye/c893813ac09d01914a5275e406305764 to your computer and use it in GitHub Desktop.
Password Generator with Malay words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# URL containing the list of words | |
#URL="https://raw.githubusercontent.com/asrafulsyifaa/Malay-Dataset/master/dictionary/malay-text.txt" | |
URL="https://gist.githubusercontent.com/nullifye/a20b52a10fcbaef73850f4905e23d2d5/raw/4b5ca641b6473be9f3cf019aecbf7b3f9e491c7a/malay_dict" | |
# Fetch the list of words from the URL | |
words=$(curl -s $URL) | |
# Check if the curl command was successful | |
if [ $? -ne 0 ]; then | |
echo "Failed to fetch the list of words." | |
exit 1 | |
fi | |
# Convert the list of words into an array | |
IFS=$'\n' read -rd '' -a words_array <<< "$words" | |
# Filter the words to include only those with a maximum of 6 characters | |
#filtered_words_array=() | |
#for word in "${words_array[@]}"; do | |
# if [ ${#word} -le 6 ]; then | |
# filtered_words_array+=("$word") | |
# fi | |
#done | |
# Check if the array has at least 3 words | |
if [ ${#words_array[@]} -lt 3 ]; then | |
echo "The list must contain at least 3 words." | |
exit 1 | |
fi | |
# Function to get a unique random index | |
unique_random_index() { | |
local index | |
while :; do | |
index=$((RANDOM % ${#words_array[@]})) | |
if [[ ! " ${selected_indices[*]} " =~ " $index " ]]; then | |
selected_indices+=($index) | |
echo $index | |
return | |
fi | |
done | |
} | |
# Function to capitalize the first character of a word | |
capitalize() { | |
local word=$1 | |
echo "$(tr '[:lower:]' '[:upper:]' <<< ${word:0:1})${word:1}" | |
} | |
# Function to get a random number | |
random_number() { | |
echo $((RANDOM % 10)) | |
} | |
# Function to get a random symbol | |
random_symbol() { | |
local symbols="!@#$%^&*()-_+=<>?" | |
echo "${symbols:RANDOM % ${#symbols}:1}" | |
} | |
# Default values | |
iterate=5 | |
separator="-" | |
altmode=false | |
# Parse arguments | |
for arg in "$@"; do | |
case $arg in | |
--num=*) iterate="${arg#*=}" ;; | |
--sep=*) separator="${arg#*=}" ;; | |
--alt) altmode=true ;; | |
*) | |
echo "Unknown parameter: $arg" | |
exit 1 | |
;; | |
esac | |
done | |
# Generate and print n password patterns | |
for ((i=0; i<iterate; i++)); do | |
# Array to keep track of selected indices | |
selected_indices=() | |
# Get three random words from the array | |
word1=$(capitalize "${words_array[$(unique_random_index)]}") | |
word2=$(capitalize "${words_array[$(unique_random_index)]}") | |
word3=$(capitalize "${words_array[$(unique_random_index)]}") | |
# Generate a random number and symbol | |
number=$(random_number) | |
#symbol=$(random_symbol) | |
# Construct the password pattern | |
if [ "$altmode" = true ]; then | |
# Alternative pattern if --alt is provided | |
password_pattern="$(random_number)${word1}${separator}$(random_number)${word2}${separator}$(random_number)${word3}" | |
else | |
# Default pattern | |
password_pattern="${word1}${separator}${word2}${separator}${word3}${separator}${number}" | |
fi | |
# Output the password pattern | |
echo $password_pattern | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment