Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- MAXLEN = 18
- ENGDICT = [[] for i in range(MAXLEN)]
- # https://raw.githubusercontent.com/dwyl/english-words/master/words.txt
- # encoder can use any other dictionary
- for line in open("words.txt"):
- word = line.strip()
- if len(word) < len(ENGDICT) and " " not in word:
- ENGDICT[len(word)].append(word)
- def text_to_hex(text):
- ans = []
- for c in text:
- ans.append(1 + (ord(c) // 16))
- ans.append(1 + (ord(c) % 16))
- return ans
- def hex_to_text(numbers):
- assert len(numbers) % 2 == 0
- ans = []
- for i in range(0, len(numbers), 2):
- ans.append((numbers[i] - 1) * 16 + numbers[i + 1] - 1)
- return "".join(chr(i) for i in ans)
- def hex_to_code(numbers):
- ans = []
- for num in numbers:
- ans.append(random.choice(ENGDICT[num]))
- return " ".join(ans)
- def code_to_hex(words):
- return [len(i) for i in words.split()]
- def antiai_encode(text):
- numbers = text_to_hex(text)
- return hex_to_code(numbers)
- def antiai_decode(code):
- numbers = code_to_hex(code)
- return hex_to_text(numbers)
- s = "Hi, fellow human!"
- print("=== ORIGINAL TEXT ===")
- print(s)
- print()
- print("=== ENCODED TEXT ===")
- code = antiai_encode(s)
- print(code)
- print()
- s1 = antiai_decode(code)
- print("=== DECODED TEXT ===")
- print(s1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement