Encrypt your document using ROT13

From LuaTeXWiki
Revision as of 23:19, 7 December 2010 by Patrick (talk | contribs) (Copied from the old bluwiki.com luatex wiki)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The following PlainTeX code example uses the ligaturing callback to "encrypt" the document using ROT13-"encryption".


 %&luatex
 
 % Notes:
 % 
 % -	Hyphenation is applied before rotating.
 % -	Ligaturing is performed after rotating.
 
 \pdfoutput=1
 \begingroup
 \catcode`\%=12
 \directlua0{
 	callback.register('ligaturing', function(head)
 		for v in node.traverse_id(33, head) do
 			if v.subtype == 1 then
 				local c = v.char
 				if c >= 65 and c <= 90 then
 					v.char = (c - 65 + 13) % 26 + 65
 				elseif c >= 97 and c <= 122 then
 					v.char = (c - 97 + 13) % 26 + 97
 				end
 			end
 		end
 		node.ligaturing(head)
 	end)
 }
 \endgroup
 
 % Hello World; fi -- fl -- ffl -- ffi -- enough with the ligatures!
 % Better do some kerning instead: AV
 
 Uryyb Jbeyq; sv -- sy -- ssy -- ssv -- rabhtu jvgu gur yvtngherf!
 Orggre qb fbzr xreavat vafgrnq: NI
 
 
 \bye