Skip to content

Instantly share code, notes, and snippets.

@robcowie
Created May 4, 2011 16:14
Show Gist options
  • Save robcowie/955493 to your computer and use it in GitHub Desktop.
Save robcowie/955493 to your computer and use it in GitHub Desktop.
Port of the Zalgo translator at http://eeemo.net
# -*- coding: utf-8 -*-
"""Port of the Zalgo translator at http://eeemo.net/
To invoke the hive-mind representing chaos.
Invoking the feeling of chaos.
With out order.
The Nezperdian hive-mind of chaos. Zalgo.
He who Waits Behind The Wall.
ZALGO
"""
import itertools
import random
zalgo_up = set([
u'\u030d', ## ̍
u'\u030e', ## ̎
u'\u033f', ## ̿
u'\u0311', ## ̑
u'\u0352', ## ͒
u'\u0357', ## ͗
u'\u0308', ## ̈
u'\u030a', ## ̊
u'\u0344', ## ̈́
u'\u034a', ## ͊
u'\u0303', ## ̃
u'\u0302', ## ̂
u'\u0300', ## ̀
u'\u0301', ## ́
u'\u0312', ## ̒
u'\u0313', ## ̓
u'\u0309', ## ̉
u'\u0363', ## ͣ
u'\u0366', ## ͦ
u'\u0367', ## ͧ
u'\u036a', ## ͪ
u'\u036b', ## ͫ
u'\u036e', ## ͮ
u'\u036f', ## ͯ
u'\u0346', ## ͆
u'\u031a', ## ̚
u'\u0304', ## ̄
u'\u0305', ## ̅
u'\u0306', ## ̆
u'\u0310', ## ̐
u'\u0351', ## ͑
u'\u0307', ## ̇
u'\u0342', ## ͂
u'\u0343', ## ̓
u'\u034b', ## ͋
u'\u034c', ## ͌
u'\u030c', ## ̌
u'\u0350', ## ͐
u'\u030b', ## ̋
u'\u030f', ## ̏
u'\u0314', ## ̔
u'\u033d', ## ̽
u'\u0364', ## ͤ
u'\u0365', ## ͥ
u'\u0368', ## ͨ
u'\u0369', ## ͩ
u'\u036c', ## ͬ
u'\u036d', ## ͭ
u'\u033e', ## ̾
u'\u035b', ## ͛
])
zalgo_down = set([
u'\u0316', ## ̖
u'\u0317', ## ̗
u'\u0318', ## ̘
u'\u0319', ## ̙
u'\u031c', ## ̜
u'\u031d', ## ̝
u'\u031e', ## ̞
u'\u031f', ## ̟
u'\u0320', ## ̠
u'\u0324', ## ̤
u'\u0325', ## ̥
u'\u0326', ## ̦
u'\u0329', ## ̩
u'\u032a', ## ̪
u'\u032b', ## ̫
u'\u032c', ## ̬
u'\u032d', ## ̭
u'\u032e', ## ̮
u'\u032f', ## ̯
u'\u0330', ## ̰
u'\u0331', ## ̱
u'\u0332', ## ̲
u'\u0333', ## ̳
u'\u0339', ## ̹
u'\u033a', ## ̺
u'\u033b', ## ̻
u'\u033c', ## ̼
u'\u0345', ## ͅ
u'\u0347', ## ͇
u'\u0348', ## ͈
u'\u0349', ## ͉
u'\u034d', ## ͍
u'\u034e', ## ͎
u'\u0353', ## ͓
u'\u0354', ## ͔
u'\u0355', ## ͕
u'\u0356', ## ͖
u'\u0359', ## ͙
u'\u035a', ## ͚
u'\u0323' ## ̣
])
zalgo_mid = set([
u'\u0315', ## ̕
u'\u031b', ## ̛
u'\u0340', ## ̀
u'\u0341', ## ́
u'\u0358', ## ͘
u'\u0321', ## ̡
u'\u0322', ## ̢
u'\u0327', ## ̧
u'\u0328', ## ̨
u'\u0334', ## ̴
u'\u0335', ## ̵
u'\u0336', ## ̶
u'\u034f', ## ͏
u'\u035c', ## ͜
u'\u035d', ## ͝
u'\u035e', ## ͞
u'\u035f', ## ͟
u'\u0360', ## ͠
u'\u0362', ## ͢
u'\u0338', ## ̸
u'\u0337', ## ̷
u'\u0361', ## ͡
u'\u0489' ## ҉_
])
zalgo_all = zalgo_up.union(zalgo_mid, zalgo_down)
def is_zalgo_char(c):
return c in zalgo_all
def zalgo(s):
"""He comes"""
for char in s:
yield char
if is_zalgo_char(char):
continue
num_up = random.randint(0, 16) / 2 + 1
num_mid = random.randint(0, 6) / 2
num_down = random.randint(0, 16) / 2 + 1
up_chars = random.sample(zalgo_up, num_up)
mid_chars = random.sample(zalgo_mid, num_mid)
down_chars = random.sample(zalgo_down, num_down)
for char in itertools.chain(up_chars, mid_chars, down_chars):
yield char
def zalgo(s, mode='max'):
"""He comes, in either min, mid or max modes"""
for char in s:
yield char
if is_zalgo_char(char):
continue
out = []
num_down = random.randint(0, 16) / 2 + 1
down_chars = random.sample(zalgo_down, num_down)
out.append(down_chars)
if mode == 'max':
num_mid = random.randint(0, 6) / 2
out.append(random.sample(zalgo_mid, num_mid))
num_up = random.randint(0, 16) / 2 + 1
out.append(random.sample(zalgo_up, num_up))
elif mode == 'mid':
num_mid = random.randint(0, 6) / 2
out.append(random.sample(zalgo_mid, num_mid))
for char in itertools.chain(*reversed(out)):
yield char
if __name__ == '__main__':
test = '\n'.join(__doc__.strip().split('\n')[2:-1])
print u''.join(zalgo(test))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment