Difference between revisions of "Obfuscation"

From HaskellWiki
Jump to navigation Jump to search
m (The first obfuscation contest was in 1993)
m (Link to other idioms that also contribute to obfuscation)
Line 9: Line 9:
   
 
The ability to use symbols for identifiers helps a lot of course, as
 
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
+
does suspending the use of layout. [[Pointfree]] style is also an
help. Use of strange monads and type trickery can all be very confusing.
+
excellent help. Use of strange monads and [[Type_arithmetic]] can all be
Finally, Haskell's clean semantics makes refactoring code
+
very confusing. Finally, Haskell's clean semantics makes refactoring
(semi-)mechanical, leading to some interesting obfuscated encodings (one
+
code (semi-)mechanical, leading to some interesting obfuscated encodings
can rewrite all keywords with lambda abstractions for example).
+
(one can replace most Haskell keywords with lambda abstractions, for
  +
example).
   
 
== Example ==
 
== Example ==

Revision as of 03:29, 17 February 2006

Obfuscation

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

 * 1993 Bottomth Obfuscation Haskell Contest
 * 2003 Zeroth Obfuscated Haskell Contest
 * 2004 Succ Zeroth Obfuscated Haskell Contest

The ability to use symbols for identifiers helps a lot of course, as does suspending the use of layout. Pointfree style is also an excellent help. Use of strange monads and Type_arithmetic can all be very confusing. Finally, Haskell's clean semantics makes refactoring code (semi-)mechanical, leading to some interesting obfuscated encodings (one can replace most Haskell 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)((???))))}
--------------------------------------------