Skip to content

Instantly share code, notes, and snippets.

@alastairparagas
Last active April 15, 2020 03:57
Show Gist options
  • Save alastairparagas/416a141a6a0c53993c7c4681322f6ea7 to your computer and use it in GitHub Desktop.
Save alastairparagas/416a141a6a0c53993c7c4681322f6ea7 to your computer and use it in GitHub Desktop.
Vectorized Encode
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