ROT13 – šifrování #18
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 11 Jan 2012 17:01:59 +0100
changeset 84f866267d7b3c
parent 83 b8e5f8f9c77b
child 85 9d8b6055150a
ROT13 – šifrování #18
vstup/css/styl.css
vstup/js/javascript.js
vstup/js/skript.js
vstup/produkty.xml
šablona/makra/šifra.xsl
     1.1 --- a/vstup/css/styl.css	Tue Jan 10 17:47:21 2012 +0100
     1.2 +++ b/vstup/css/styl.css	Wed Jan 11 17:01:59 2012 +0100
     1.3 @@ -124,3 +124,18 @@
     1.4     color:black;
     1.5  }
     1.6  
     1.7 +.rot13 span {
     1.8 +	color: gray;
     1.9 +	font-family: monospace;
    1.10 +}
    1.11 +
    1.12 +.rot13 a {
    1.13 +	margin-left: -5px;
    1.14 +	color: green;
    1.15 +	text-decoration: none;
    1.16 +}
    1.17 +
    1.18 +.rot13 a:hover {
    1.19 +	color: red;
    1.20 +}
    1.21 +
     2.1 --- a/vstup/js/javascript.js	Tue Jan 10 17:47:21 2012 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,1 +0,0 @@
     2.4 -
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/vstup/js/skript.js	Wed Jan 11 17:01:59 2012 +0100
     3.3 @@ -0,0 +1,41 @@
     3.4 +/**
     3.5 + * XML Web generátor – program na generování webových stránek
     3.6 + * Copyright © 2012 František Kučera (frantovo.cz)
     3.7 + * 
     3.8 + * This program is free software: you can redistribute it and/or modify
     3.9 + * it under the terms of the GNU General Public License as published by
    3.10 + * the Free Software Foundation, either version 3 of the License, or
    3.11 + * (at your option) any later version.
    3.12 + * 
    3.13 + * This program is distributed in the hope that it will be useful,
    3.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.16 + * GNU General Public License for more details.
    3.17 + * 
    3.18 + * You should have received a copy of the GNU General Public License
    3.19 + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    3.20 + */
    3.21 +
    3.22 +/**
    3.23 + * XML Web generátor – jmenný prostor 
    3.24 + */
    3.25 +var xwg = { 
    3.26 +	/**
    3.27 +	 * Zašifruje/dešifruje obsah elementu pomocí Rot13.
    3.28 +	 * @param id ID elementu, jehož text chceme změnit.
    3.29 +	 */
    3.30 +	rot13: function(id) {
    3.31 +		var e = document.getElementById(id);
    3.32 +		e.textContent = e.textContent.rot13();
    3.33 +	}
    3.34 +};
    3.35 +
    3.36 +/**
    3.37 + * Vrací hodnotu textového řetězce zašifrovanou/dešifrovanou algoritmem Rot13 
    3.38 + */
    3.39 +String.prototype.rot13 = function() {
    3.40 +	return this.replace(/[a-zA-Z]/g, function(z) {
    3.41 +		return String.fromCharCode((z <= "Z" ? 90 : 122) >= (z = z.charCodeAt(0) + 13) ? z : z - 26);
    3.42 +	});
    3.43 +};
    3.44 +
     4.1 --- a/vstup/produkty.xml	Tue Jan 10 17:47:21 2012 +0100
     4.2 +++ b/vstup/produkty.xml	Wed Jan 11 17:01:59 2012 +0100
     4.3 @@ -15,10 +15,11 @@
     4.4  		
     4.5  		<p>Vhodnost zvířete do domácnosti:</p>
     4.6  		<m:měřák hodnota="95"/>
     4.7 +		<p><m:šifra>Tučňáky si prostě oblíbíte!</m:šifra></p>
     4.8  		
     4.9  		<h2>Panda malá</h2>
    4.10  		<p>Vivamus nec dictum dolor. Aliquam et tellus dolor. Curabitur et est sapien. Sed nec neque massa. Integer luctus erat vel arcu molestie ac dapibus dolor pretium. Curabitur eget augue non ipsum pulvinar venenatis eget et lectus. Proin fringilla aliquet sapien, non luctus est lobortis vel. Nunc vehicula volutpat varius. Aliquam suscipit accumsan sollicitudin. Morbi ultricies, mauris id elementum pellentesque, nunc dolor viverra nisl, sit amet consequat velit libero at ligula. Nulla luctus rhoncus tortor nec sollicitudin. Vivamus posuere sodales ipsum, hendrerit cursus felis pharetra sit amet. Nunc interdum facilisis massa ac congue.</p>
    4.11 -		<p>Aliquam erat volutpat. Quisque vitae libero est. Aliquam erat volutpat. Integer elementum, nisl nec lacinia facilisis, dolor tellus varius eros, sit amet facilisis sem sapien vitae nulla. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Integer rutrum sodales venenatis. Donec mollis aliquet enim, id venenatis urna faucibus sed. Suspendisse pharetra neque et nibh tincidunt suscipit. Morbi ut justo sit amet lectus faucibus tempor quis non libero. Aenean in dolor sem, in lacinia sem.</p>
    4.12 +		<p>Aliquam erat volutpat. Quisque vitae libero est. <m:šifra>Panda malá je menší než panda velká.</m:šifra> Aliquam erat volutpat. Integer elementum, nisl nec lacinia facilisis, dolor tellus varius eros, sit amet facilisis sem sapien vitae nulla. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Integer rutrum sodales venenatis. Donec mollis aliquet enim, id venenatis urna faucibus sed. Suspendisse pharetra neque et nibh tincidunt suscipit. Morbi ut justo sit amet lectus faucibus tempor quis non libero. Aenean in dolor sem, in lacinia sem.</p>
    4.13  		
    4.14  		<p>Vhodnost zvířete do domácnosti:</p>
    4.15  		<m:měřák hodnota="80"/>
    4.16 @@ -30,6 +31,7 @@
    4.17  
    4.18  			Pozor: v současné verzi se stahuje ze Sítě při každém generování.
    4.19  		-->
    4.20 +		
    4.21      </text>
    4.22  
    4.23  </stránka>
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/šablona/makra/šifra.xsl	Wed Jan 11 17:01:59 2012 +0100
     5.3 @@ -0,0 +1,50 @@
     5.4 +<?xml version="1.0" encoding="UTF-8"?>
     5.5 +<!--
     5.6 +XML Web generátor – program na generování webových stránek
     5.7 +Copyright © 2012 František Kučera (frantovo.cz)
     5.8 +
     5.9 +This program is free software: you can redistribute it and/or modify
    5.10 +it under the terms of the GNU General Public License as published by
    5.11 +the Free Software Foundation, either version 3 of the License, or
    5.12 +(at your option) any later version.
    5.13 +
    5.14 +This program is distributed in the hope that it will be useful,
    5.15 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.17 +GNU General Public License for more details.
    5.18 +
    5.19 +You should have received a copy of the GNU General Public License
    5.20 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    5.21 +-->
    5.22 +<xsl:stylesheet version="2.0"
    5.23 +	xmlns="http://www.w3.org/1999/xhtml"
    5.24 +	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
    5.25 +	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    5.26 +	xmlns:xs="http://www.w3.org/2001/XMLSchema"
    5.27 +	exclude-result-prefixes="m xs">
    5.28 +
    5.29 +	<!--
    5.30 +		Šifrování (Rot13)
    5.31 +		*****************
    5.32 +		Umožňuje vkládat „zašifrované“ části textu.
    5.33 +		Použijeme např. pro text, který vyzrazuje, jak skončí film.
    5.34 +		Pro zobrazení v čitelném tvaru je potřeba kliknout na tlačítko a text „dešifrovat“,
    5.35 +		takže si ho nepřečteme omylem, aniž bychom chtěli.
    5.36 +		*
    5.37 +		@algoritmus zatím je výchozím a jediným algoritmem Rot13
    5.38 +	-->
    5.39 +	<xsl:template match="m:šifra">
    5.40 +		<xsl:variable name="šifra-id">šifra-<xsl:number level="any"/></xsl:variable>
    5.41 +		<span class="rot13" title="Tento text je „zašifrován“ algoritmem Rot13, abyste si ho omylem nepřečetli. Pokud číst chcete, klikněte na tlačítko…">
    5.42 +			<span id="{$šifra-id}"><xsl:value-of select="m:rot13(text())"/></span>
    5.43 +			<a onclick="javascipt:xwg.rot13('{$šifra-id}'); return false;" href="#{encode-for-uri(' &gt;&gt; zobrazí „zašifrovaný“ text &lt;&lt;')}">↹</a>
    5.44 +		</span>
    5.45 +	</xsl:template>
    5.46 +
    5.47 +	<xsl:function name="m:rot13" as="xs:string">
    5.48 +		<xsl:param name="vstup"/>
    5.49 +		<xsl:value-of select="translate($vstup, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM')"/>
    5.50 +	</xsl:function>
    5.51 +
    5.52 +</xsl:stylesheet>
    5.53 +