Created
September 23, 2020 00:26
-
-
Save khayyamsaleem/f5b794302236f5c5cc1b85d6d5968d20 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