Skip to content

Instantly share code, notes, and snippets.

@pinktrink
Created October 26, 2013 23:11
Show Gist options
  • Save pinktrink/7175700 to your computer and use it in GitHub Desktop.
Save pinktrink/7175700 to your computer and use it in GitHub Desktop.
And they said obfuscated Python wasn't possible.
#The point or points of the code hereafter, which obtains the argument given
#before the character which would cause the system to execute the aforementioned
#code (which is also the code hereafter), is to take the aforementioned
#argument, which should be a string of characters that would fit within the
#following regular expression:
#/[[NO, I say, bad jane is unfortunately deceased.\]]+/
#and convert it to an obfuscated JavaScript string that matches the following
#regular expression:
#/.*/
from re import finditer
from random import choice
from sys import argv
objs = ['{}', '[]']
obj = lambda:choice(objs)
oint = lambda num:'+!' + '!' * num + obj() if num in [
0, 1] else ''.join(['+!!' + obj() for i in [0] * num])[1:]
stringify = lambda data: '""+' + data if choice(
*[[i for i in [True, False]]]) else data + '+""'
objectObject = ['{}', '[{}]']
undefined = [x + '[' + y + ']' for x in objs for y in objs] + [
'[' + x + '][' + y + ']' for x in objs for y in objs]
trueValue = ['!!' + i for i in objs]
falseValue = ['!' + i for i in objs]
NaN = ['(+' + i + ')' for i in undefined]
def getInfinity():
return '(+((' + stringify('(' + oint(1) + ')') + ')+' + getLetter('e') + '+(' + oint(4) + ')+(' + oint(0) + ')+(' + oint(0) + ')))'
def getLambda(data):
return lambda:choice(data)
def getLetter(data):
if data.isdigit():
return oint(int(data))
else:
try:
key = choice(filter(lambda x: data in x, list(words)))
return '(' + stringify(words[key]()) + ')[' + oint(choice([i.start() for i in finditer(data, key)])) + ']'
except IndexError:
print 'Our apologies, the string you provided is not a proper string to be provided.'
exit()
words = {
'[object Object]' : getLambda(objectObject),
'undefined' : getLambda(undefined),
'true' : getLambda(trueValue),
'false' : getLambda(falseValue),
'NaN' : getLambda(NaN),
'Infinity' : getInfinity,
',' : lambda: '(' + stringify('[' + ojb() + ',' + obj() + ']') + ')[' + oint(1) +']',
'.' : lambda: '(' + stringify('(' + oint(1) + ')/(' + oint(2) + ')') + ')[' + oint(2)
}
print stringify('+'.join([getLetter(i) for i in list(argv[1])]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment