Created
July 20, 2024 00:46
-
-
Save kingnebby/bce666cc197e6282dea2ca8135db40b1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# This is a Python file XD | |
import sys | |
import string | |
import base64 | |
# Globals | |
def getAlphaToNumbersDict(): | |
alpha_to_numbers = {} | |
for index, char in enumerate(string.ascii_lowercase, 1): | |
alpha_to_numbers[char] = index % 10 | |
return alpha_to_numbers | |
def getSymbolDict(): | |
symbols = "!@#$%^&*()" | |
symbolDict = {} | |
for index, symbol in enumerate(symbols, 1): | |
symbolDict[index] = symbol | |
return symbolDict | |
alphaToNumberDict = getAlphaToNumbersDict() | |
symbolDict = getSymbolDict() | |
# Have fun! | |
def run(): | |
text = sys.argv[1] | |
print(f'Starting with... {text}') | |
encodedText = getFirstTenEncodedChars(text) | |
print(f'You can get the range with [i:j]: {encodedText}') | |
firstCharacterAsNumber = alphaToNumberDict[text[0].lower()] | |
print(f'You can map using dictionaries: {firstCharacterAsNumber}') | |
lastCharAsSymbol = getLastCharNumberWithOffsetAsSymbol(text) | |
print(f'You can do a substring with just string[]: {lastCharAsSymbol}') | |
spliced = spliceTwoChars(encodedText, firstCharacterAsNumber, lastCharAsSymbol) | |
print(f'You can splice with ranges as well: {spliced}') | |
def getFirstTenEncodedChars (value: str = '') -> str: | |
return base64.b64encode(value.encode())[0:10].decode() | |
def getLastCharNumberWithOffsetAsSymbol (value): | |
lastCharLowercase = value[-1].lower() | |
offset = 2 | |
symbolIndex = (alphaToNumberDict[lastCharLowercase] + offset) % 10 | |
return symbolDict[symbolIndex] | |
def spliceTwoChars (value, firstChar, secondChar): | |
return value[0] + str(firstChar) + value[1:5] + secondChar + value[6:] | |
# HelloWorld === 'S8GVsb^9Xb3' | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment