python-snippets/utils/str_utils.py
2024-07-17 22:30:12 +01:00

37 lines
839 B
Python

import random
import string
import base64
def obscure(content):
data = content.encode('utf-8')
return base64.b64encode(data)
def unobscure(content):
data = content.decode('utf-8')
return str(base64.b64decode(data))
def get_random_string(length, caps=False, numbers=False, specials=False):
letters = string.ascii_lowercase
if caps:
letters += string.ascii_uppercase
if numbers:
letters += string.digits
if specials:
letters += string.punctuation
return ''.join(random.choice(letters) for _ in range(length))
def get_colon_prefix(content):
split_string = content.split(":", 1)
return split_string[0].strip()
def get_dash_suffix(content):
last_dash = content.rfind("-")
rando = content[last_dash + 1:]
return rando