change encodeStrings=1 to encodeStrings=0 to desactivate string encoding
function renamed
parameters renamed
variables renamed
strings encoded and moved
importreimportstringimportrandomencodeStrings=1protected=["abstract","arguments","boolean","break","byte","case","catch","char","class*","const","continue","debugger","default","delete","do","double","else","enum*","eval","export*","extends*","false","final","finally","float","for","function","goto","if","implements","import*","in","instanceof","int","interface","let","long","native","new","null","package","private","protected","public","return","short","static","super*","switch","synchronized","this","throw","throws","transient","true","try","typeof","var","void","volatile","while","with","yield","Array","Date","eval","function","hasOwnProperty","Infinity","isFinite","isNaN","isPrototypeOf","length","Math","NaN","name","Number","Object","prototype","String","toString","undefined","valueOf"]caracters=['{','}','!','=','+','-','*','%','/','<','>','(',')',';','&','|',',',']','[','.',':']caracters2=list(caracters)mywords=[]unique=[]tabstrings=[]defgenerate():code=''.join([random.choice(string.ascii_letters)forninxrange(5)])ifcodenotinunique:unique.append(code)else:returngenerate()returncodedefencode(str):return'"'+''.join(('\\x%02x'% ord(c)) if ord(c) <= 255 else ('\\u%04x' % ord(c)) for c in str)+'"'#Get textdonnees=editor.getText().decode("utf8")#remove commentsdonnees=re.sub('(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)','',donnees)#encode strings to protect themstrings=re.finditer("(\".*?\")|(\'.*?\')",donnees)for s in strings: if (encodeStrings==1): codedStr=encode(s.group(0)[1:-1]) else: codedStr=s.group(0) if codedStr not in tabstrings: tabstrings.append(codedStr) console.write(s.group(0)+"\n") donnees=re.sub("(\"|\')"+re.escape(s.group(0)[1:-1])+"(\"|\')","t["+str(len(tabstrings)-1)+"]",donnees)#separate wordsfor c in caracters: donnees=re.sub("(\\"+c+")",""+c+"",donnees)#new filenotepad.new()editor.setCodePage(65001)notepad.menuCommand(MENUCOMMAND.LANG_JS)#variablesstrings=re.finditer("(var\s|const\s)\s*([a-zA-Z][a-zA-Z\d_]*(?:\s*,\s*[a-zA-Z][a-zA-Z\d_]*)*)\s*",donnees)for s in strings: if ((s.group(2) not in protected) and (s.group(2) not in mywords)): if s.group(2) != '': mywords.append(s.group(2))#functionsstrings=re.finditer("function\s+(.*)\(",donnees)for s in strings: if ((s.group(0).split(' ')[1] not in protected) and (s.group(0).split(' ')[1] not in mywords)): if s.group(0).split(' ')[1] != '': mywords.append(s.group(0).split(' ')[1])#parametresstrings=re.finditer("function\s+.*\((.*)\)",donnees)for s in strings: for p in s.group(1).replace("","").split(","): if ((p not in protected) and (p not in mywords)): if p != '': mywords.append(p)for s in mywords: donnees=re.sub("\s"+s+"\s",""+generate()+"",donnees)#minimizefor c in caracters2: donnees=re.sub("\s*\\"+c+"\s*",c,donnees)donnees=re.sub("\s+","",donnees)res='var t=['for s in tabstrings: res=res+s+","res=res+"'']"print(res)print(donnees.encode("utf8"))
Last edit: REY Sébastien 2016-03-22
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Last edit: REY Sébastien 2016-03-22