@register.filter def js_obfuscate_string(text): CHANCE_TO_ADD=0.2 CHANCE_TO_ADD_INCREASE_BY=0.1 MAX_NUMBER_OF_DIFFERENT_ADDED_CHARS=5 import string,random chars=string.ascii_letters+string.digits unused=(list(filter((lambda x: x not in text), list(chars)))) if len(unused)<4: # punctuations makes the text easy to read, add them only when there's no other choice chars=' _=@!#~`;<>|' # do not add rx meaningful chars like *+?.-\/ unused+=(list(filter((lambda x: x not in text), list(chars)))) unused_in_use='' random.shuffle(unused) next_chance=CHANCE_TO_ADD if unused and len(unused): output="'" for c in list(text): if random.random()