axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Axiom-developer] size issue with noweb


From: David MENTRE
Subject: Re: [Axiom-developer] size issue with noweb
Date: Fri, 21 Apr 2006 23:30:41 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Tim,

"David MENTRE" <address@hidden> writes:

>> unfortunately i cannot send you my current program as it is not
>> (yet?) open source. i'd have to get permission from work.
>
> If I find time, I'll try to make an obfuscation tool that keep the
> noweb structure but replace content with meaningless one.

I hacked a little noweb obfuscation tool in Python, attached to this
email.

It removes all code, while keeping the noweb structure (code chunk names
are MD5 of original names) and initial size. Regarding latex comments,
it is more difficult to obfuscate properly without writing a latex
parser (which I don't want to write :-). So I obfuscate all individuals
words. That should not mess to much latex commands and remove enough
meaning.

Could you try it on your file:
  ./noweb-obfuscation.py file.pamphlet

If you find the result safe enough, could you send it to me?

Best wishes,
d.
-- 
David MENTRE <address@hidden> -- http://wiki.axiom-developer.org/FrontPage

#!/usr/bin/python

import md5
import sys
import re

chunk_re = re.compile("^(<<.+?>>address@hidden)$", re.MULTILINE | re.DOTALL)
chunk_components_re = re.compile("^<<(.+?)>>=(.*?\n)@\s*$",
                                 re.MULTILINE | re.DOTALL)

chunk_call_re = re.compile("(<<.+?>>)")
chunk_call_name_re = re.compile("<<(.+?)>>")

word_re = re.compile(r'[\s./][a-zA-Z0-9]+?[\s./]')

def log(txt):
    sys.stderr.write(txt)

def md5_str(str):
    h = md5.new()
    h.update(str)
    return h.hexdigest()

def obfuscate_code_string(str):
    s = ""
    for i in range(0, len(str)):
        if str[i] != '\n':
            s += 'a'
        else:
            s += '\n'
    return s

def obfuscate_code(text):
    calls = re.split(chunk_call_re, text)
    for s in calls:
        m = re.match(chunk_call_name_re, s)
        if m != None:
            print "<<%s>>" % md5_str(m.group(1)),
        else:
            print obfuscate_code_string(s),
        
def obfuscate_comment(text):
    def word_repl(match_obj):
        return obfuscate_code_string(match_obj.group(0))
    t = re.sub(word_re, word_repl, text)
    print t,

def obfuscate_file(filename):
    f = open(filename, 'r')
    file_content = f.read()
    f.close()

    splitted = re.split(chunk_re, file_content)
    for part in splitted:
        m = re.match(chunk_components_re, part)
        if m != None:
            chunk_name = m.group(1)
            # a code chunk
            if chunk_name != "*":
                print "<<%s>>=\n" % md5_str(m.group(1)),
            else:
                print "<<*>>=\n",
            obfuscate_code(m.group(2))
            print "@\n",
        else:
            # some comment
            obfuscate_comment(part)

obfuscate_file(sys.argv[1])


reply via email to

[Prev in Thread] Current Thread [Next in Thread]