Created
September 23, 2020 00:28
-
-
Save khayyamsaleem/99d16b70914494a7c04cf91374985530 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
def getBit(n, x): | |
return n&(1<<x) | |
def setBit(n,x,b): | |
return n&(~(1<<x)) if b == 0 else n|(1<<x) | |
def encodeChunk(word): | |
output = 0 | |
for i,char in enumerate(map(ord, word)): | |
for c,j in enumerate(range(i,32,4)): | |
output = setBit(output, j, getBit(char, c)) | |
return output | |
def encode(str): | |
n = 4 | |
chunks = [str[i:i+n] for i in range(0, len(str), n)] | |
encoded = [encodeChunk(chunk) for chunk in chunks] | |
return encoded | |
if __name__ == "__main__": | |
print(encode("tacocat")) | |
print(encode("never odd or even")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment