Skip to content

Instantly share code, notes, and snippets.

@fenilgandhi
Created December 13, 2022 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fenilgandhi/0145a257a3938a50f8c8bef6dbf8cbf6 to your computer and use it in GitHub Desktop.
Save fenilgandhi/0145a257a3938a50f8c8bef6dbf8cbf6 to your computer and use it in GitHub Desktop.
import json
class IntHash():
"""
Creates a runtime integer from a given list of integer, strings.
"""
@classmethod
def encode(self, list_value):
ascii_codes = [ord(_) for _ in json.dumps(list_value)]
result = "".join(map(str,ascii_codes))
return int(result)
@classmethod
def decode(self, int_value):
int_value = str(int_value)
ascii_codes = [int_value[i:i+2] for i in range(0, len(int_value), 2)]
enc = "".join(map(lambda _:chr(int(_)), ascii_codes))
return json.loads(enc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment