Skip to content

Instantly share code, notes, and snippets.

@16BitS3G4l
Last active August 9, 2023 18:21
Show Gist options
  • Save 16BitS3G4l/22094f6d06f0fabe552074e7574902d8 to your computer and use it in GitHub Desktop.
Save 16BitS3G4l/22094f6d06f0fabe552074e7574902d8 to your computer and use it in GitHub Desktop.
Decode Username
import math
# note: this can easily be implemented using conditions, but I like leveraging math for it instead
# map input to 1 (when a = x), other values (a != x) to 0; domain is ASCII table values (0-255)
# 0.0001 should be an arbitrarily small number approaching 0 to prevent dividing by zero error when x=a
def f(x, a):
return math.floor(1 - ( abs(x-a)/(abs(x-a) + 0.0001) ))
def decode(character):
ascii_value = ord(character)
return chr( ( f(ascii_value, 49) * 121 ) + ( f(ascii_value, 54) * 101 ) + ( f(ascii_value, 66) * 104 ) + ( f(ascii_value, 105) * 111 ) + ( f(ascii_value, 116) * 115 ) + ( f(ascii_value, 83) * 104 ) + ( f(ascii_value, 51) * 117 ) + ( f(ascii_value, 71) * 97 ) + ( f(ascii_value, 52) * 92 ) + ( f(ascii_value, 108) * 48 ))
def decode_string(characters):
decoded_str = ""
for character in characters:
decoded_str += decode(character)
return decoded_str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment