Obfuscation

From HaskellWiki
Revision as of 08:43, 16 February 2006 by DonStewart (talk | contribs) (A page on obfuscating Haskell code)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Obfuscation

Haskell is (perhaps surprisingly) an excellent language for code obfuscation. There have been three Haskell obfuscation contests:

 * Pred Zeroth (early 1990s?)
 * Zeroth Haskell Obfuscation Contest
 * Succ Zeroth International Obfuscated Haskell Code Contest

The ability to use symbols for identifiers helps a lot of course, as does suspending the use of layout. Point-free style is also an excellent help. Finally, Haskell's clean semantics makes refactoring code (semi-)mechanical, leading to some interesting obfuscated encodings (one can rewrite all keywords with lambda abstractions for example).

Example

The following illustrates how, by turning off layout, rewriting keywords (let, case, where) as lambdas, and using symbols for identifiers (in this case multiple '?' characters), Haskell may be highly obfuscated.

--------------------------------------------
module Main where{import List;import System;
import Data.HashTable as H;(???????)=(concat
);(??????)(???)(????)=((groupBy)(???)(????))
;(??????????????????????)(????)=((??????????
)((tail).(???????))((????????????????????)((
??????)(?????????????????????)(????))));(??)
=([' ']);(??????????????)=((hashString));(?)
=((>>=));(???????????????????????)([((???)),
(????)])=((?????????????)(???))?(\(?????)->(
(????????????????)(==)(??????????????))?(\((
???))->((??????????????????)(???????????????
)(???)(?????))>>((?????????????????)(???))?(
\((?????))->((((???????????????????)((????))
((??????????????????????))((?????))))))));((
???????????????????????))(??)=(????????????)
("usage f dic out");(?????????????????????)(
(???),(??????))((????),(????????????????????
))=((???)==(????));(?????????????????)(???)=
(toList)(???);(????????????????????)(????)=(
((??????????)(((??????????)(snd)))((????))))
;(??????????????????)(???????????????)(???)(
(?????))=(((mapM)(((???????????????)(???)))(
(lines)(?????))));(???????????????????)(????
)(???????????????????????)(?????)=(?????????
)(????)((unlines)((???????????????????????)(
?????)));(????????????????)(???)((????))=(((
new)(???)(????)));(main)=((???????????)?(((\
(???)->((???????????????????????)(???))))));
(???????????????)(???)(????)=((????????)(???
)((sort)(????))((??)++(????)));(???????????)
=(getArgs);(????????????)(???)=((((print))((
???))));(??????????)(???)(????)=(((map)(???)
(????)));(????????)((???))(????)(?????)=((((
H.insert))((???))(????)(?????)));(?????????)
((???))((????))=(((writeFile)(???)((????))))
;(?????????????)(???)=(((readFile)((???))))}
--------------------------------------------