Skip to content

Instantly share code, notes, and snippets.

@vitstradal
Created March 14, 2016 12:39
Show Gist options
  • Save vitstradal/7bf370b87583264a69e8 to your computer and use it in GitHub Desktop.
Save vitstradal/7bf370b87583264a69e8 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
# autor: vitas@matfyz.cz
# licence: public domain
import re
import sys
# no atoi in python, really?
# atoi stolen from: http://www.codecodex.com/wiki/Base_conversion
# We have to write our own function for outputting to string with arbitrary base
def itoa(num, radix):
result = ""
while num > 0:
result = "0123456789abcdefghijklmnopqrstuvwxyz"[num % radix] + result
num /= radix
return result
def openload_level2_debase(m):
radix, num = int(m.group(1)) + 27 , int(m.group(2))
return '"' + itoa(num, radix) + '"'
def openload_level2(txt):
return re.sub(ur'\u01c3\((\d+),(\d+)\)', openload_level2_debase, txt, re.UNICODE).replace('"+"', '')
def openload_decode(txt):
c = [
('_', '(゚Д゚) [゚Θ゚]'),
('a', '(゚Д゚) [゚ω゚ノ]'),
('b', '(゚Д゚) [゚Θ゚ノ]'),
('c', '(゚Д゚) [\'c\']'),
('d', '(゚Д゚) [゚ー゚ノ]'),
('e', '(゚Д゚) [゚Д゚ノ]'),
('f', '(゚Д゚) [1]'),
('o', '(゚Д゚) [\'o\']'),
('u', '(o゚ー゚o)'),
('c', '(゚Д゚) [\'c\']'),
('9', '???'),
('8', '???'),
('7', '((゚ー゚) + (o^_^o))'),
('6', '((o^_^o) +(o^_^o) +(c^_^o))'),
('5', '((゚ー゚) + (゚Θ゚))'),
('4', '(-~3)'),
('3', '(-~-~1)'),
('2', '(-~1)'),
('1', '(-~0)'),
('0', '((c^_^o)-(c^_^o))'),
]
delim = "(゚Д゚)[゚ε゚]+"
ret = u''
for aachar in txt.split(delim):
for i in range(len(c)):
val,pat = c[i]
aachar = aachar.replace(pat, val)
aachar = aachar.replace('+ ', '')
m = re.match(r'^\d+', aachar)
if m:
ret += unichr(int(m.group(0), 8))
else:
m = re.match(r'^u([\da-f]+)', aachar)
if m:
print "g:", m.group(1), int(m.group(1), 16)
ret += unichr(int(m.group(1), 16))
#print "ret:", ret
return openload_level2(ret)
s = sys.stdin.read()
print openload_decode(s)
@Sarfroz
Copy link

Sarfroz commented Apr 16, 2017

is there any possibility of PHP implementation?

@badrazizi
Copy link

i don't know if is it broswer encoding issue but seems in arr c 8 and 9 values is ??? is that the right value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment