Last active
June 17, 2019 13:57
-
-
Save luca-m/5468314 to your computer and use it in GitHub Desktop.
This file contains 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
alphabet=''.join([chr(i) for i in xrange(256) if chr(i) not in '!"#$&*+-/0123456789;=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\^abcdefghijklmnopqrstuvwxyz|' and i != 0]) | |
def filt(s): | |
return s.translate(ident,'!"#$&*+-/0123456789;=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\^abcdefghijklmnopqrstuvwxyz|') | |
def obfNum(n): | |
""" Obfuscate a number """ | |
if n==0: | |
return "([]<{})" | |
elif n==1: | |
return "({}<[])" | |
elif n==-1: | |
return "~"+obfNum(0) | |
elif n==-2: | |
return "~"+obfNum(1) | |
#elif n==3: | |
# return "~(~"+obfNum(0)+"<<"+obfNum(1)+"<<"+obfNum(1)+")" | |
#elif n==-3: | |
# return "~("+obfNum(1)+")<<"+obfNum(1)+")" | |
#elif n==7: | |
# return "~((~"+obfNum(1)+")<<"+obfNum(1)+"<<"+obfNum(1)+")" | |
#elif n==-7: | |
# return "~(~(~"+obfNum(0)+"<<"+obfNum(1)+"<<"+obfNum(1)+")<<"+obfNum(1)+")" | |
if n % 2: | |
return "~%s" % obfNum(~n) | |
else: | |
return "("+obfNum(n/2)+"<<"+obfNum(1)+")" % | |
def obfChar(c): | |
""" Obfuscate a character """ | |
import string | |
allowed=''.join([i for i in alphabet if i in string.printable]) | |
if c in allowed: | |
return `c`; | |
# Valid : "\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff" | |
if c in '0123456789abcdef': | |
s=chr(0xf0+ord(("0%s"%c).decode('hex'))) | |
return "`'"+s+"'`"+"["+obfNum(4)+"]" | |
if c in `True`: | |
i=string.rfind(`({}<())`,c) | |
return "`({}<())`["+obfNum(i)+"]" | |
#if c in `False`: | |
# i=string.rfind(`({}>())`,c) | |
# return "`({}<{})`["+obfNum(i)+"]" | |
if c in '"\'\'"': | |
i=string.rfind(``''``,c) | |
return "``''``["+obfNum(i)+"]" | |
# Otherwise generate the char with generating '%c'%NUM | |
return "`'%\xfc'`["+obfNum(1)+"::"+obfNum(4)+"]%"+obfNum(ord(c)) | |
def obfString(s): | |
""" Obfuscate a string """ | |
outs="`[" | |
for c in s: | |
try: | |
outs+=""+objChar(c)+"," | |
except: | |
print "char '%s' not found in alphabet" % (c) | |
return | |
return outs[:-1]+"]`["+obfNum(2)+"::"+obfNum(5)+"]" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment