Last active
April 15, 2020 03:57
-
-
Save alastairparagas/416a141a6a0c53993c7c4681322f6ea7 to your computer and use it in GitHub Desktop.
Vectorized Encode
This file contains 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
import numpy as np | |
import base64 | |
from typing import List | |
def encode(ord_key: List[int], some_str: str): | |
s_len = len(some_str) | |
ord_key_remapped = np.resize(ord_key, s_len) | |
encoded_str = np.array(list(map(ord, some_str))) + ord_key_remapped % 256 | |
return base64.urlsafe_b64encode(encoded_str.tostring()) | |
print(encode([1,2,3,4], 'cat attack')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment