Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sys import argv
- if len(argv) <= 1:
- exit("Synthax:\npython3 script.py string to encode goes here, spaces are allowed")
- def textToBits(text, encoding='utf-8', errors='surrogatepass'):
- bits = bin(int.from_bytes(text.encode(encoding, errors), 'big'))[2:]
- return bits.zfill(8 * ((len(bits) + 7) // 8))
- # Used to separate bits
- #zws = "\u200b" # Zero width space
- # Represents a one
- zwj = "\u200d" # Zero width joiner
- #zwj = "a"
- # Represents a zero
- zwnj = "\u200c" # Zero width non-joiner
- #zwnj = "b"
- message = ""
- for arg in argv[1:]:
- message += arg + " "
- message = message[:-1]
- msgBin = textToBits(message)
- print("Original message: " + message)
- #print("Binary message: " + msgBin)
- msgZw = "".join([zwj if bit in "1" else zwnj for bit in msgBin])
- print("\t==> Zero width message can be hard to copy from some terminal, they have been outputted to a text file along with instructions")
- print("Zero Width message (len: {}): \"{}\"".format(len(msgZw), msgZw))
- with open("zeroWidth.txt", "w") as txtFile:
- txtFile.write("vvvv COPY BELOW ({} chars) vvvv\n".format(len(msgZw)) + msgZw + "\n^^^^ COPY ABOVE ^^^^")
- print("Zero width message has been saved to 'zeroWidth.txt'")
Advertisement
Add Comment
Please, Sign In to add comment