Skip to content

Instantly share code, notes, and snippets.

@jstenmark
Created February 6, 2024 21:28
Show Gist options
  • Select an option

  • Save jstenmark/8f1ff5cd08ff848824d726c95bfe8151 to your computer and use it in GitHub Desktop.

Select an option

Save jstenmark/8f1ff5cd08ff848824d726c95bfe8151 to your computer and use it in GitHub Desktop.
password generator
def extract_service_identifier(url):
# Extract the domain name from the URL, removing any 'www.' prefix and TLD
if "://" in url:
domain = url.split("://")[1].split("/")[0]
else:
domain = url.split("/")[0]
domain = domain.replace("www.", "").split(".")[0]
# Incorporate 'ö' by replacing the first occurrence of 'o' or appending it
if 'o' in domain:
service_identifier = domain.replace('o', 'ö', 1)
else:
service_identifier = domain + 'ö'
return service_identifier
def generate_password(book, url, number, random_word):
# Transform the book title into an anchor
anchor = ''.join(word[0] for word in book.title().split())
# Extract service identifier from URL
service_identifier = extract_service_identifier(url)
# Generate service-specific number
service_specific_number = generate_service_specific_number(url, number)
# Special characters
special_chars = "*!"
# Assemble the password
password = f"{service_identifier}{special_chars}{anchor}{service_specific_number}{random_word}"
return password
def generate_service_specific_number(service, base_number):
# Use domain name for service-specific transformation
domain = service.split("://")[-1].split("/")[0].split(".")[0]
service_modifier = sum(ord(char.lower()) for char in domain) % 100 # Keep it within 2 digits for simplicity
# Apply a transformation to the base number using the service modifier
service_specific_number = int(base_number) + service_modifier
return service_specific_number
# User inputs
favorite_book = input("Enter your favorite book: ")
service_url = input("Enter the service URL: ")
meaningful_number = input("Enter a base meaningful number: ")
random_word = input("Enter a random word: ")
# Generate password
password = generate_password(favorite_book, service_url, meaningful_number, random_word)
print(f"Your generated password is: {password}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment