Sven Hartrumpf writes:
> Hi all.
> I am looking for a
> source code obfuscator for the Scheme programming language
> (preferably for R5RS programs).
> Renaming identifiers would suffice for my purposes.
Just coded, barely tested, inefficient, simplistic. You would have to
extend `r5rs-keywords' for your purposes.
;; Copyright (C) 2007, Emilio C. Lopes <e@gmx.net>
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; If you have not received a copy of the GNU General Public License
;; along with this software, it can be obtained from the GNU Project's
;; World Wide Web server (http://www.gnu.org/copyleft/gpl.html), from
;; its FTP server (ftp://ftp.gnu.org/pub/gnu/GPL), by sending an eletronic
;; mail to this program's maintainer or by writting to the Free Software
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
(define r5rs-keywords '(cons car cdr define + - * / = <= < > >= if lambda let ...))
(define (obfuscate-symbol symbol)
;; this code is Scsh specific. Just use a hash algorith available
;; in your implementation.
(string->symbol (string-append "x" (number->string (md5-digest->number (md5-digest-for-string (symbol->string symbol))) 16))))
(define (obfuscate expr)
(cond
((and (symbol? expr)
(not (memq expr r5rs-keywords)))
(obfuscate-symbol expr))
((pair? expr)
(cons (obfuscate (car expr)) (obfuscate (cdr expr))))
(else
expr)))
(obfuscate '(define (fac n)
(if (<= n 1)
1
(* n (fac (- n 1))))))
;; => (define (xd2467530ef7303b14c9988df20bb8ce4 x7b8b965ad4bca0e41ab51de7b31363a1) (if (<= x7b8b965ad4bca0e41ab51de7b31363a1 1) 1 (* x7b8b965ad4bca0e41ab51de7b31363a1 (xd2467530ef7303b14c9988df20bb8ce4 (- x7b8b965ad4bca0e41ab51de7b31363a1 1)))))
;; (xd2467530ef7303b14c9988df20bb8ce4 5) => 120
--
Emlio C. Lopes Ich leb und wei nit wie lang,
Munich, Germany ich stirb und wei nit wann,
ich fahr und wei nit wohin,
(Martinus von Biberach) mich wundert, dass ich frhlich bin!