1 Šifrovací metody v prostředí webmathematica Encryption methods in environment of webmathematica Vítězslav Jaroš Bakalářská práce 20072 3 4 ABSTRAKT ...
Šifrovací metody v prostředí webMathematica Encryption methods in environment of webMathematica
Vítězslav Jaroš
Bakalářská práce 2007
ABSTRAKT Abstrakt česky Tato práce se zabývá klasickými metodami šifrování, mezi něž mimo jiné patří Viegenérova šifra, Cardanova mřížka, Cézarova šifra a další. Vybrané metody jsou zpracovány v programu Mathematica a poté implementovány do prostředí webMathematica, což je zjednodušeně řečeno Mathematica na Internetu. Čtenář této práce by si měl po přečtení osvojit teorii každé uvedené šifry a poté si ji může vyzkoušet v praxi ve svém prohlížeči a také se dozvědět základy práce v prostředí WebMathematica.
Klíčová slova: Mathematica, webMathematica, HTML
ABSTRACT Abstract in English This work deal with classical methods encryption, among which among others belongs to Viegener cipher, Cardan grating, Cesar cipher and next. Choice method are processed in programme Mathematica and after it implemented to the environment webMathematica, which is simply told by Mathematica on internet. Reader those work would had after perused develop theory every mentioned cipher and after it her is able to try out practically in his browser as well as learn bases work in environment webMathematica.
Keywords: Mathematica, webMathematica, HTML
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
5
Poděkování, motto Poděkování patří především mému vedoucímu bakalářské práce doc. Ing. Ivanu Zelinkovi, Ph.D. za rady a připomínky, které mi poskytoval během vypracovávání mojí bakalářské práce.
Prohlašuji, že jsem na bakalářské práci pracoval samostatně a použitou literaturu jsem citoval. V případě publikace výsledků, je-li to uvolněno na základě licenční smlouvy, budu uveden jako spoluautor.
Ve Zlíně ……………………. Podpis diplomanta
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
6
OBSAH ÚVOD .............................................................................................................................. 8 I
TEORETICKÁ ČÁST ........................................................................................... 9
1
KLASICKÉ METODY ŠIFROVÁNÍ ................................................................. 10
4.1 PROGRAMOVANÍ STRÁNEK WEBMATHEMATICA ................................................ 25 4.1.1 Základní obsah dokumentu webMathematica............................................. 25 4.1.2 Získávání dat............................................................................................. 26 4.1.3 Zobrazení výsledku ................................................................................... 27 4.2 WWW STRÁNKY .............................................................................................. 29 4.2.1 Grafické zobrazení .................................................................................... 29 4.2.2 Metody programování............................................................................... 30 4.2.3 Struktura www stránek ............................................................................. 30 4.2.4 Ovládání stránek ....................................................................................... 31 4.2.5 Ukázka zdrojového textu šifry a její popis ................................................. 32 4.2.5.1 Zdrojový text pro aplikaci webMathematica .................................... 32 4.2.5.2 Zdrojový text pro aplikaci Mathematica .......................................... 37 ZÁVĚR .......................................................................................................................... 40 ZÁVĚR V ANGLIČTINĚ ............................................................................................. 41 SEZNAM POUŽITÉ LITERATURY........................................................................... 42 SEZNAM POUŽITÝCH SYMBOLŮ A ZKRATEK................................................... 43
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
7
SEZNAM OBRÁZKŮ................................................................................................... 44 SEZNAM TABULEK ................................................................................................... 45 SEZNAM PŘÍLOH ....................................................................................................... 46
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
8
ÚVOD Šifrovací metody jsou předmětem výuky kurzu Aplikovaná informatika. Jelikož se jedná o velmi obsáhlé téma, které by zabralo několik semestrů, tak je tento kurz zaměřený na klasické metody šifrování. Tyto metody jsou počátkem současných šifrovacích metod. Teorie není složitá, což přispívá ke snadnému pochopení vyučované látky. Součástí tohoto kurzu jsou i cvičení, ve kterých jsme měli možnost si odpřednášené metody šifrovaní naprogramovat v programu Mathematica a tím si prakticky ukázat funkci jednotlivých metod. Někde tady asi vznikla otázka: „Jak mám ukázat svoji skvěle naprogramovanou šifru kamarádovi, který nemá program Mathematica ve svém počítači?“ Odpovědí na tuto otázku je WebMathematica. WebMathematica je nástroj, který přenese vaše projekty z okna programu Mathematica do internetového prohlížeče kohokoliv na celém světě. Pokud se tedy chcete dozvědět o několika klasických metodách šifrování, způsoby jejich naprogramovaní v programu Mathematica a implementaci těchto zdrojových kódů do prostředí WebMathematica čtěte dále.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
I. TEORETICKÁ ČÁST
9
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
1
10
KLASICKÉ METODY ŠIFROVÁNÍ
Už od starověku se lidé snaží předávat zprávy tak, aby je mohl číst pouze adresát a nikdo jiný. Je-li zpráva napsána ručně a doručována otrokem (jak tomu bylo ve starém Řecku nebo Římě) nebo poštou dnes, tak vždy existuje nebezpečí, že se dostane do ruky někomu, komu není určena. Otrok může být zajat, pošťák se může zmýlit a doručit zprávu na nesprávnou adresu. Je-li zpráva napsána srozumitelně, přirozeným jazykem bez jakékoliv snahy skrýt její obsah, tak jí může porozumět každý, komu se dostane do ruky, pokud zná jazyk, kterým je napsána. V novější době můžeme zprávy předávat telegrafem, radiovými vlnami, telefonem, faxem nebo e-mailem, ale nebezpečí, že budou odposlechnuty, je stále přítomné. Ve skutečnosti se od té doby nesmírně zvýšilo. Tak například radiové vysílání může slyšet každý, kdo je v dosahu vysílače a má přijímač naladěný na správnou frekvenci. Zpráva e-mailem může být doručena na spoustu nezamýšlených adres v důsledku překlepu nebo viru číhajícího v počítači. Jakkoliv pesimisticky to může vypadat, je dobrým pravidlem předpokládat, že každá zpráva, která má být důvěrná, se může dostat do rukou někomu, komu není určena. Je proto projevem potřebné opatrnosti učinit kroky, které zajistí, že nezamýšlený příjemce bude mít přinejmenším velké problémy zprávě porozumět, nebo ještě lépe, vůbec ji nebude schopen přečíst. Rozsah škody, kterou může nezamýšlené odhalení zprávy způsobit, do velké míry závisí na čase, který uplynul mezi odposlechnutím zprávy a jejím rozluštěním. V některých případech stačí, aby mezi odposlechnutím a rozluštěním zprávy uplynul jeden den nebo dokonce jenom pár hodin, aby k žádné škodě nedošlo. Například rozhodnutí akcionáře prodat nebo koupit okamžitě velký balík akcií, nebo rozkaz armádního velitele zaútočit za rozbřesku následujícího dne. V jiných případech má informace dlouhodobou hodnotu a musí být proto utajena co nejdéle. Například zprávy týkající se plánování rozsáhlých vojenských operací. Úsilí, které musí vynaložit soupeř, oponent nebo nepřítel k tomu, aby rozluštil zachycenou zprávu, má proto velký význam. Jestliže neautorizovaný příjemce zprávy nedokáže zprávu rozluštit za použití nejlepších známých metod a nejvýkonnějších dostupných počítačů za dobu kratší, než po kterou je utajení obsahu zprávy důležité, tak si odesílatel může být relativně jistý. Nemůže si ale být zcela jistý, protože rozluštění nějakých dříve odeslaných zpráv může protivníkovi pomoci urychlit luštění následujících zpráv. Je také možné, že protivník objevil nějakou metodu, kterou odesílatel nezná, a je proto schopen luštit zprávy rychleji, než si odesílatel dokáže představit. To se například přihodilo německé armádě se šifrovacím zařízením Enigma
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
11
v průběhu druhé světové války.
1.1 Transpoziční šifry Transpozice neboli přesmyčka spočívá ve změně pořadí znaků podle určitého pravidla. Například tak, že otevřený text je zapsán do tabulky po řádcích a šifrový text vznikne čtením sloupců téže tabulky. 1.1.1 Viegenérova šifra Vytvoří se Viegenérova tabulka (tabulka o 26 řádcích, v každém řádku písmena od "a" do "z", v 2. řádku je na první místo posunut poslední znak předcházejícího řádku a tak se postupuje dále až v posledním řádku je převrácená abeceda). Pokud je heslo kratší než zpráva k zašifrování, tak se duplikuje tolikrát, aby v součtu mělo tolik znaků jako zpráva. Postupně vybíráme ze zprávy a hesla znaky, které si odpovídají pozicí. Znak ze zprávy určuje souřadnici sloupce a znak z hesla hledejte na prvním místě v jednotlivých řádcích Viegenérovi tabulky, tím určíte souřadnici řádku. Znak, jenž leží na určených souřadnicích, je šifra. Jiný způsob je následující. Zjistí se pořadí znaku, získaného ze zprávy v abecedě. Označímeli ho n, pak se o n-1 pozic posune odpovídající znak v hesle. Sepsáním těchto znaků za sebe vzniká šifrovaná zpráva.
a b c d e f g h i j k l m n o p q r s t u v w x y z
b c d e f g h i j k l m n o p q r s t u v w x y z a
c d e f g h i j k l m n o p q r s t u v w x y z a b
d e f g h i j k l m n o p q r s t u v w x y z a b c
e f g h i j k l m n o p q r s t u v w x y z a b c d
f g h i j k l m n o p q r s t u v w x y z a b c d e
g h i j k l m n o p q r s t u v w x y z a b c d e f
h i j k l m n o p q r s t u v w x y z a b c d e f g
i j k l m n o p q r s t u v w x y z a b c d e f g h
j k l m n o p q r s t u v w x y z a b c d e f g h i
k l m n o p q r s t u v w x y z a b c d e f g h i j
l m n o p q r s t u v w x y z a b c d e f g h i j k
m n o p q r s t u v w x y z a b c d e f g h i j k l
n o p q r s t u v w x y z a b c d e f g h i j k l m
o p q r s t u v w x y z a b c d e f g h i j k l m n
p q r s t u v w x y z a b c d e f g h i j k l m n o
12 q r s t u v w x y z a b c d e f g h i j k l m n o p
r s t u v w x y z a b c d e f g h i j k l m n o p q
s t u v w x y z a b c d e f g h i j k l m n o p q r
t u v w x y z a b c d e f g h i j k l m n o p q r s
u v w x y z a b c d e f g h i j k l m n o p q r s t
v w x y z a b c d e f g h i j k l m n o p q r s t u
w x y z a b c d e f g h i j k l m n o p q r s t u v
x y z a b c d e f g h i j k l m n o p q r s t u v w
y z a b c d e f g h i j k l m n o p q r s t u v w x
z a b c d e f g h i j k l m n o p q r s t u v w x y
Obrázek 1: Viegenérova tabulka – metoda Viegenérova šifra Příklad: Zpráva k zašifrování je „acryptosystem“ a použijeme heslo „michaeal“. Prvním znakem ve zprávě je písmeno a. V abecedě se nachází na první pozici. Posunutí bude tedy nulové (11=0). První znak v hesle, tedy zůstane stejný, v našem případě m. zpráva:
a c r y p t o s y s t e m
klíč:
m i c h a e l m i c h a e
šifra:
m k t f p x z e g u a e q
Tabulka 1: Viegenérova šifra
1.1.2 Jednoduchá transpozice Zpráva se poskládá do tabulky o rozměru n (řádků) x m (sloupců). Heslo pro zašifrování se skládá z číslic 1 - m různě zpřeházených. Jednotlivé číslice hesla se postupně přiřazují sloupcům tabulky. Zašifrovaný text se tvoří tak, že se do řádku opíšou písmena z vytvořené
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
13
tabulky, jejichž sloupec má nad sebou 1, pak se pokračuje dvojkou až po číslo m. Pokud má tabulka více buněk než je znaků v zadaném textu, pak se doplní písmenem x. Pro náš příklad jsem použil tabulku 6x4. Příklad: Zpráva je „zasifrovanitextuzpravy“. Heslo „123654“. Zprávu vepíšeme do tabulky 6x4. Délka zprávy je 22 znaků, zbývající místa v tabulce tedy doplníme písmenem x. Nad sloupce tabulky si napíšeme heslo. Zašifrovaná zpráva pak vznikne sepsáním čtveřic znaků z každého
sloupce
(1-6
postupně)
vedle
sebe.
Pro
náš
příklad
má
tvar
„zoefavxasatvrtpxfizxinuy“. 1 z o e r
2 a v x a
3 s a t v
6 i n u y
5 f i z x
4 r t p x
Tabulka 2: Jednoduchá transpozice
1.1.3 Dvojitá transpozice Zadaný text se poskládá do tabulky o rozměru n (řádků) x m (sloupců). Heslo pro zašifrování se skládá z číslic 1-m různě zpřeházených. Jednotlivé číslice hesla se postupně přiřazují sloupcům tabulky. Poté se vytvoří tabulka m x n. Do jednotlivých řádků se opíší sloupce z první tabulky v pořadí od 1 po 6. Zašifrovaný text se tvoří tak, že se do řádku opíšou písmena z druhé tabulky, jejichž sloupec má nad sebou 1, pak se pokračuje dvojkou až po číslo n. Pokud má první tabulka více buněk než je znaků v zadaném textu, pak se doplní písmenem x. Příklad: Zpráva je „zasifrovanitextuzpravy“. První heslo například „123654“ a druhé heslo je „3214“. Zprávu vepíšeme do tabulky 6x4. Nad sloupce tabulky si napíšeme první heslo. Poté jednotlivé sloupce opíše ve správném pořadí do 1. -6. řádku druhé tabulky, která má rozměry 4x6. Nad sloupce v druhé tabulce doplníme druhé heslo. Zašifrovaná zpráva pak
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
14
vznikne sepsáním šestic znaků z každého sloupce (1-4 postupně) vedle sebe. Pro náš příklad má tvar „extpzuovatinzasrfifavxxy“. 1 z o e r
2 a v x a
3 s a t v
6 i n u y
5 f i z x
4 r t p x
Tabulka 3: Dvojitá transpozice první heslo 3 z a s r f i
2 o v a t i n
1 e x t p z u
4 f a v x x y
Tabulka 4: Dvojitá transpozice druhé heslo
1.1.4 Cardanova mřížka Původně to byla mřížka vyrobená z tvrdého papíru, do níž byly vyřezány otvory, do kterých odesilatel vepsal zprávu, poté odejmul mřížku a vyplnil různými písmeny zbylá místa. V tomto případě má mřížka rozměr 8x8 (zpráva tedy může mít nejvýše 64 znaků), ve které je 16 otvorů, do kterých se vpisuje zpráva. Vězněme tedy mřížku, nastavíme do první polohy a vpisujeme do dírek písmena tak jako bychom psali zprávu, tzn. po řádcích. Až vyplníme všechna políčka, otočíme mřížku o 90 stupňů a pokračujeme v psaní zprávy opět od prvního řádku, až dojdeme opět na konec mřížky. Tento postup zopakujeme ještě 2krát a výsledkem je vyplněná tabulka 8x8, tedy zašifrovaný text. Pokud máme zprávu kratší jak 64 znaků, tak nakonec doplníme různé znaky. Příklad:
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
15
Zprávu k zašifrování zvolíme ve tvaru „nicnenitaktezkeabysetohonemohlodosahnout“. Postupně tedy vepisujeme jednotlivé znaky do tabulky, dokud jsou prázdné políčka. Až se zaplní první tabulka. Otočíme tabulkou o 90° a pokračujeme tímto stylem, až se zaplní celá tabulka 8x8.
Tabulka 5: Jedna z Cardanových mřížek b n d y o s
i
s
d a e t c n d o e d n h d h n
i
o d o n u d t c t a e k d t m d c e d o z c h c d l c c d d k o e c d a d d c d
Tabulka 6: Výsledná Cardanova mřížka pro náš příklad
1.2 Substituční šifry Je druh šifry, kdy se nahrazuje každý znak otevřeného textu jiným znakem šifrovaného textu. Aby příjemce získal otevřený text, musí na zašifrovaný text použít inverzní substituci. 1.2.1 Cézarova šifra Zpráva určená k zašifrování je rozložena na jednotlivé znaky a každý se změní na znak, který bychom našli v abecedě, pokud bychom se posunuli o n míst směrem dopředu. Zašifrovaný text se pak získá sepsáním zašifrovaných znaků za sebe.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
16
Příklad: Zpráva je „ahojkamarade“, posunutí si určíme 4. Podle výše uvedeného postupu pak vznikne zašifrovaná zpráva „elsnoeqevehi“ 1.2.2 Jednoduchá substituce v tabulce Zadaný text se rozloží na jednotlivé znaky a ty se podle zadání uživatele vymění za definované znaky, čím vznikne samotná šifra. Příklad: Máme zprávu „ahoj“ a definujeme si dvě výměny. Písmeno a zaměníme za c a písmeno o za p. Tím vznikne zašifrovaná zpráva „chpj“. 1.2.3 Autokláv Postupně se vybírají x-té znaky zprávy a hesla, dokud nedojdou písmena ve zprávě. Používá se třeba Viegenerova tabulka (26 abeced pod sebou, n-tá abeceda má posunutý začátek o n pozic doprava a na konci vznikne inverzní abeceda). Označíme-li tuto tabulku n x m, pak pozice znaku z hesla v abecedě udává n-tou souřadnici řádku a pozice znaku ve zprávě udává m-tou souřadnici sloupce ve Viegenerově tabulce, přičemž písmeno z v hesle je 0tý řádek v tabulce. Znak, který v tabulce leží na této pozici, je pak hledaným šifrovaným znakem. Pokud je heslo kratší než zpráva, pak se doplňuje buď zprávou (použití abecedy otevřeného textu), nebo již zašifrovaným textem (použití abecedy šifrovaného textu). Příklad: Zpráva k zašifrování je „ahojkamarade“ a heslo dáme „abeceda“. Heslo je kratší než zpráva, doplníme tedy heslo na tvar „abecedaahoj“ v případě použití původní zprávy k doplnění hesla. Pokud bychom heslo doplňovali o zašifrovanou zprávu, pak by heslo mělo tvar „abecedabjtm“. Podle výše uvedeného postupu vyhledáme ve Viegenérově tabulce zašifrované znaky. Nakonec nám vyjde šifra ve tvaru „bjtmpenbzpnp“.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
17
Pro připomenutí a přehlednost uvádím ještě jednou Viegenérovu tabulku. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
a b c d e f g h i j k l m n o p q r s t u v w x y z
b c d e f g h i j k l m n o p q r s t u v w x y z a
c d e f g h i j k l m n o p q r s t u v w x y z a b
d e f g h i j k l m n o p q r s t u v w x y z a b c
e f g h i j k l m n o p q r s t u v w x y z a b c d
f g h i j k l m n o p q r s t u v w x y z a b c d e
g h i j k l m n o p q r s t u v w x y z a b c d e f
h i j k l m n o p q r s t u v w x y z a b c d e f g
i j k l m n o p q r s t u v w x y z a b c d e f g h
j k l m n o p q r s t u v w x y z a b c d e f g h i
k l m n o p q r s t u v w x y z a b c d e f g h i j
l m n o p q r s t u v w x y z a b c d e f g h i j k
m n o p q r s t u v w x y z a b c d e f g h i j k l
n o p q r s t u v w x y z a b c d e f g h i j k l m
o p q r s t u v w x y z a b c d e f g h i j k l m n
p q r s t u v w x y z a b c d e f g h i j k l m n o
q r s t u v w x y z a b c d e f g h i j k l m n o p
r s t u v w x y z a b c d e f g h i j k l m n o p q
s t u v w x y z a b c d e f g h i j k l m n o p q r
t u v w x y z a b c d e f g h i j k l m n o p q r s
u v w x y z a b c d e f g h i j k l m n o p q r s t
v w x y z a b c d e f g h i j k l m n o p q r s t u
w x y z a b c d e f g h i j k l m n o p q r s t u v
x y z a b c d e f g h i j k l m n o p q r s t u v w
y z a b c d e f g h i j k l m n o p q r s t u v w x
z a b c d e f g h i j k l m n o p q r s t u v w x y
Obrázek 2: Viegenérova tabulka – metoda Autokláv 1.2.4 Jednoduchá záměna 1.2.4.1 Srovnaná abeceda Vytvoří se klasická abeceda a až z a srovnaná abeceda (abeceda šifrovaného textu), což je klasická abeceda, ale první prvek tedy a je posunut o uživatelem definovaný počet pozic směrem doprava. Při každém posunutí se poslední prvek abecedy přesouvá na místo prvního prvku a ten je posunut na bezprostředně následující pozici. Toto se provede n-krát, kde n je posunutí. Dále se určí první prvek ve zprávě, kterou chceme zašifrovat. Najde se jeho pozice v klasické abecedě a zašifrovaným znakem je pak prvek ležící na stejné pozici, ale ve srovnané abecedě. Tohle se opakuje pro celý řetězec určený k zašifrování. Příklad: Mějme zprávu „sifra“ a posunutí nastavíme na 4. Pak si vytvoříme abecedu šifrovaného textu (AŠT). A vytvoříme si pro přehlednost tabulku, která bude mít v prvním řádku abecedu otevřeného textu (AOT) a pod ní v druhém řádku je AŠT.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
18
AOT a b c d e f g h i j k l m n o p q r s t u v w x y z AŠT w x y z a b c d e f g h i j k l m n o p q r s t u v
Tabulka 7: Jednoduchá záměna – srovnaná abeceda Zašifrovaná zpráva má pak tvar „oebnw“. 1.2.4.2 Reciproká abeceda Vytvoří se klasická abeceda a až z a reciproká abeceda (abeceda šifrovaného textu), což je klasická abeceda v inverzním (obráceném) tvaru. Dále se určí první prvek v řetězci, který chceme zašifrovat. Najde se jeho pozice v klasické abecedě a zašifrovaným znakem je pak prvek ležící na stejné pozici, ale v reciproké abecedě. Tohle se opakuje pro celý řetězec určený k zašifrování. Příklad: Mějme zprávu „sifra“. Pak si vytvoříme abecedu šifrovaného textu (AŠT). A vytvoříme si pro přehlednost tabulku, která bude mít v prvním řádku abecedu otevřeného textu (AOT) a pod ní v druhém řádku je AŠT. AOT a b c d e f g h i j k l m n o p q r s t u v w x y z AŠT z y x w v u t s r q p o n m l k j i h g f e d c b a
Tabulka 8: Jednoduchá záměna – reciproká abeceda Zašifrovaná zpráva má pak tvar „hruiz“. 1.2.4.3 Rozházená abeceda Vytvoří se klasická abeceda a až z a rozházená abeceda (abeceda šifrovaného textu), což je klasická abeceda, ale její prvky jsou náhodně rozházené do pole o délce 26 pozicí (26 znaků abecedy). Dále se určí první prvek v řetězci, který chceme zašifrovat. Najde se jeho pozice v klasické abecedě a zašifrovaným znakem je pak prvek ležící na stejné pozici, ale v rozházené abecedě. Tohle se opakuje pro celý řetězec určený k zašifrování.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
19
Příklad: Mějme zprávu „sifra“. Pak si vytvoříme abecedu šifrovaného textu (AŠT). A vytvoříme si pro přehlednost tabulku, která bude mít v prvním řádku abecedu otevřeného textu (AOT) a pod ní v druhém řádku je AŠT. AOT a b c d e f g h i j k l m n o p q r s t u v w x y z AŠT p q m z l a o x n w s k c j e u d h i r y v b f h t
Tabulka 9: Jednoduchá záměna – rozházená abeceda Zašifrovaná zpráva má pak tvar „inahp“. 1.2.5 Tabulka 4x7 Vytvoří se tabulka 4x7. Řádky tabulky jsou označeny čísly 7, 8, 9 a 0. První sloupec nezastupuje žádné číslo, dalších 6 sloupců je označeno čísly 1 - 6. Šifrování probíhá tak, že místo znaků zprávy se dosadí jejich souřadnice z tabulky. Příklad: Zpráva k zašifrování je „ahojpepo“. Nalezneme tedy jednotlivé znaky v tabulce a určíme číselnou šifru každého znaku. Nejprve se píše číslo řádku a pak sloupce.
7 8 9 0
a h o v
1 b i p w
2 c j q x
3 d k r y
4 e l s z
5 6 f g m n t u ; §
Tabulka 10: Tabulka 4x7 Zašifrovaná zpráva má poté tvar „789829174919“. 1.2.6 Tabulka 5x10 Vytvoří se tabulka 5x10. Řádky tabulky jsou označeny čísly 1-5. Sloupce čísly 1 - 9 a poslední označíme číslem 0. Tabulka je vyplněna znaky české abecedy. Nevyplněná políčka v tabulce doplníme různými znaky. Šifrování probíhá tak, že místo znaků zprávy se dosadí jejich souřadnice z tabulky a to v pořadí řádek-sloupec.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
20
Příklad: Jako zprávu si zvolíme text „kryptosystém“. Nalezneme tedy jednotlivé znaky v tabulce. Sepíšeme vedle sebe souřadnice řádků a sloupců.
1 2 3 4 5
1 a f ň ť ž
2 á g o u ;
3 b h ó ú -
4 c i p ů *
5 č í q v +
6 d j r w =
7 ď k ř x §
8 e l s y )
9 é m š ý (
0 ě n t z ,
Tabulka 11: Tabulky 5x10 Tímto způsobem vznikne šifra ve tvaru „273648343032384838301029“. 1.2.7 Playfair Jsou nadefinovány 4 matice 5x5 (25 písmen abecedy, znak x se vynechá) matice 1
matice 3
matice 4
matice 2
Tabulka 12: Playfair - rozložení matic Definují se dvě hesla. První heslo obsadí první políčka matice 3, ostatní políčka obsadí písmena nevyskytující se v hesle. Druhé heslo obsadí první políčka matice 4. Heslo nesmí obsahovat dvě a více stejných písmen. Dále se definuje zpráva k zašifrování. Znaky zprávy se rozdělí postupně do dvojic. Šifrování probíhá tímto způsobem. První písmeno z každé dvojice se nalezne v matici 1. Jeho řádková souřadnice definuje řádkovou souřadnici písmene v matici 3 a jeho sloupcová souřadnice definuje sloupcovou souřadnici písmene v matici 4. Druhé písmeno z každé dvojice se nalezne v matici 2. Jeho řádková souřadnice definuje řádkovou souřadnici písmene v matici 4 a jeho sloupcová souřadnice definuje sloupcovou souřadnici písmene v matici 3. Písmena nalezená v maticích 3,4 jsou zašifrovanými písmeny dané dvojice znaků za matice 1,2. Opakováním tohoto postupu se zašifruje celý text. Tento postup se používá hlavně k programování. V příkladu si ukáže způsob, kdy máme k dispozici grafické zobrazení čtyř matic.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
21
Příklad: Zpráva nechť má tvar „playfair“. První heslo je „dum“ a druhé heslo „deska“. Vytvoříme si tedy čtyři matice o rozměru 5x5. Matice 1 a 2 obsahuje klasickou abecedu kromě písmene x. Do matice 3 a 4 nejprve vyplníme hesla a poté doplníme zbývajícími písmeny z abecedy. V matici 1 nalezneme první písmeno ze zprávy a v matici 2 druhé písmeno. Vytvoříme si pomyslný čtyřúhelník, jehož dva vrcholy se dotýkají těchto dvou písmen. Na dalších dvou vrcholech jsou jejich zašifrované protějšky. Tímto způsobem pokračujeme s dalšími dvojicemi. V ukázce jsem použil první dvojici písmen ve zprávě.
a f k p u d b i o u
matice 1 b c d g h i l m n q r s v w y e s k c f g j l m p q r v w y matice 4
e j o t z
d c i o t
a h n t z
a f k p u
matice 3 u m a e f g j k l p q r v w y b c d g h i l m n q r s v w y matice 2
Tabulka 13: Metoda Playfair - příklad Zašifrovaná zpráva má tvar „piaucdfr“.
b h n s z e j o t z
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
2
22
HISTOGRAM
Histogram textu je grafické znázornění četnosti znaků v daném textu. Většinou se zobrazuje procentuální výskyt těchto znaků. Na obrázku 3 vidíme histogram textu, kde na souřadnici y je procentuální vyjádření četnosti znaků v textu a na ose x jsou vypsané znaky, pro které se četnosti počítali. % 8
6
4
2
a b c d e f g h i j k l m no p q r st u v w x y z
Obrázek 3. Histogram textu
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
3
23
WEBMATHEMATICA
3.1 Úvod do aplikace webMathematica WebMathematica nám umožňuje přenést vytvořené notebooky z programu Mathematica na web. WebMathematica slouží pro lidi, co nemají Mathematicu doma, ale přes web mohou s ní pracovat. Přidává tedy interaktivní výpočty a vizualizace do vašich webových stránek díky propojení programu Mathematica s nejnovějšími serverovými technologiemi. WebMathematica a Mathematica jsou v základu stejné, ale poskytují jiné uživatelské rozhraní a jsou zaměřeny na rozdílné skupiny uživatelů. WebMathematica nabízí přístup ke specifickým aplikacím programu Mathematica skrz webový prohlížeč nebo jiného web klienta. Orientace v prostředí webMathematica pro uživatele nevyžaduje zvláštní znalosti programování. Ve většině případů uživatelé nemusí být obeznámeni s programem Mathematica, dokonce nemusí ani vědět, že Mathematicu používají. Mathematica tedy poskytuje vývojové prostředí pro webMathematica web stránky. Například v programu Mathematica se vytvoří kód, který modeluje nějaký fyzický proces. Tento kód může být poté umístěn na webMathematica stránky, čímž umožníme lidem tento model spustit a řídit odkudkoliv na světě a požít ho tak pro zjištění výsledků pro své projekty. Detaily k programování v programu webMathematica budou následovat v praktické části této bakalářské práce.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
II.
PRAKTICKÁ ČÁST
24
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
4
25
WEBMATHEMATICA
4.1 Programovaní stránek webMathematica Když se pustíme poprvé do programování stránek, tak nás asi napadnou tři základní úkony. Zařadil bych mezi ně základní obsah dokumentu. Tedy základní elementy dokumentu, které by měl obsahovat, aby si s jeho překladem webMathematica poradila. Dalším úkonem je vstup od uživatele, tedy získávání dat. Konkrétně v metodách šifrování je to zpráva k zašifrování a hesla (ať už ve formě textu nebo čísel). A tím třetím by nejspíš bylo zobrazení výsledku. Na co by nám taky bylo šifrování, když bychom se nedozvěděli šifru či výsledek kteréhokoliv výpočtu provedeného „srdcem“ aplikace webMathematica. Ještě je tady však jeden důležitý úkon a jím je naprogramování samotné šifry či jiné konkrétní aplikace, které by měla řešit daný technologický problém a tento kód vložit do webové stránky. Ale tohle už je za hranicemi této kapitoly. Jen připomenu, že znalost programování v prostředí Mathematica je jeden z předpokladů, ke zvládnutí programu webMathematica. 4.1.1 Základní obsah dokumentu webMathematica Základní vzhled kódu, který webMathematica umí zpracovat je následující. 1 <%@ taglib uri="/webMathematica-taglib" prefix="msp" %> 2 <%@ page contentType="text/html; charset=windows-1250" language="java" import="java.sql.*" errorPage="" %> 3 4 5 6 <meta http-equiv="Content-Type" content="text/html; charset=windows1250" /> 7 titulek stránky 8 9 10 11 <msp:allocateKernel> 12 20 21 22 23
Vysvětlení jednotlivých řádků (číslování odpovídá jednotlivým řádkům v kódu): 1. Standardní jsp hlavička, která nám říká, že v kódu je používána syntaxe, jenž zpracovává weMathematica a prvky této syntaxe mají předponu msp. 2. Nastavení typu obsahu a kódovaní javascriptu. 3. Typ dokumentu HTML. 4. - 23. Obsah HTML dokumentu. 5. - 8. Hlavička HTML dokumentu. 10. – 22. Tělo HTML dokumentu. 11. Přiřadí stránce kernel programu Mathematica, umístěný např. na serveru, k výpočtům použitým v kódu stránky. Počáteční tag. 12. - 19. Obsah formuláře, který se po potvrzení odesílá na URL stránky uvedené v parametru action metodou post. 13. - 15. Obsah těchto tagů je odeslán kernelu Mathematica ke zpracování. 14. Vyžádání si vnější knihovny pro výpočty. 21. Uvolnění kernelu Mathematica. 4.1.2 Získávání dat Většina komunikace s uživatelem a získávání dat od něj probíhá přes formulář a v něm umístěné prvky .
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
27
Ukázka formuláře: 1 .. 2 9 ..
Tag na 3. řádku zobrazí ve formuláři prázdné okýnko, do kterého uživatel zadává jakýkoliv text. Důležitým parametrem tohoto tagu je name. Pomocí tohoto názvu se po odeslání formuláře získávají uživatelem sdělená data (text) do proměnných, které dále zpracovává jádro programu Mathematica. Toto „přenesení“ dat z políčka formuláře do proměnné se provádí v příkazu na 6. řádku výše uvedeného kódu. Obecná syntaxe je následující. nazev_promenne=$$nazev_prvku_input_z_formulare;
Z uvedeného označení tedy vyplývá, že ať už bereme data z formuláře pomocí prvku input nebo třeba textarea, vždy se před jeho název dají dva znaky dolaru - $$. Následné zpracování proměnných už probíhá tak jak jej známe z programování v programu Mathematica. Pro doplnění uvedu, že prvek input na 4. řádku slouží k potvrzení odeslání formuláře ke zpracování. 4.1.3 Zobrazení výsledku V předchozí kapitole jsme si ukázali jak od uživatele získat data ke zpracování. Data prošla algoritmem některé z našich šifer. A nyní bych se rád pokusil vysvětlit zobrazení výsledků výpočtu na níže uvedených výřezech ze zdrojového kódu. V první ukázce jsem použil jednoduché uložení hodnoty do proměnné (4. řádek) a následný výpis obsahu dané proměnné. Na stránce se zobrazí číslo „5“.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
28
1 ... 2 <msp:allocateKernel> 3 <msp:evaluate> 4
x=5; x
5 6 7 ...
Následující ukázka obsahuje příkaz Print[]. Ten určitě znají nejen programátoři Mathematica. Uvnitř hranatých závorek je většinou nějaký text nebo proměnná určená k výpisu na obrazovku. Při použití tohoto příkazu v programu Mathematica je obsah závorek okamžitě vypsán na obrazovku. V prostředí webMathematica to však takto nepracuje. Obsah jednotlivých Print[] se ukládá postupně do schránky a tam sečkají na příkaz,
který
je
naráz
vypíše
na
obrazovku.
Tímto
příkazem
je
ColumnForm[MSPGetPrintOutput[]].
Jeho nevýhodou je, že nedokáže zvlášť vypsat jednotlivé výstupy. V naší ukázce jsem schválně uvedl dvakrát tento příkaz a vložil jsem mezi ně další text pro výpis na obrazovku (14. řádek). Co tedy udělá níže uvedený kód? Příkaz na 11. řádku zobrazí zprávu uvedenou na 5. řádku, tedy „Výsledek výpočtu je: 4“. Na tom by nebylo nic divného. Avšak na řadu přichází 17. řádek, který tuto zprávu vypíše znovu a přidá k ní další, která je uvedený na 14. řádku našeho kódu. 1 ... 2 <msp:allocateKernel> 3 <msp:evaluate> 4 x=2; 5 Print[ "Výsledek výpočtu je: ", x^2]; 6
7 ... 8
nějaký kód
9 ... 10 <msp:evaluate> 11
ColumnForm[ MSPGetPrintOutput[]]
12 13 <msp:evaluate> 14 Print[ "Další text k zobrazení"]; 15
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
29
16 <msp:evaluate> 17
ColumnForm[ MSPGetPrintOutput[]]
18 19 20 ...
Poslední způsob, který bych rád uvedl, jsem používal nejčastěji. Používá se příkaz StringJoin[], který už známe z programu Mathematica. Níže uvedený příklad vypíše „Proměnná x obsahuje hodnotu: 2“. Jak už z názvu vyplívá, jde o spojení dvou a více řetězců. Přičemž řetězcem rozumějme text v uvozovkách, nebo proměnná, které byl text někde v předchozích řádcích kódu přidělen. Pozn. Číselný obsah proměnné lze převést na řetězec příkazem ToString[promenna]. 21 ... 22 <msp:allocateKernel> 23 <msp:evaluate> 24 x=2; 25 26 ... 27
nějaký kód
28 ... 29 <msp:evaluate> 30
StringJoin[“Proměnná x obsahuje hodnotu: ”,ToString[x]]
31 32 33 ...
4.2 WWW stránky Jsou praktickou ukázkou programování aplikací pro webMathematicu. 4.2.1 Grafické zobrazení Jsou graficky navrženy tak, aby byli rychlé i pro majitele pomalejších připojení k Internetu. Tudíž nejsou tvořeny z obrázků umístěných v tabulce, která tvoří strukturu stránky, ale
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
30
99% grafického zobrazení je vytvořeno CSS styly (to jedno procento je pro obrázek v levém horním rohu). 4.2.2 Metody programování K naprogramování obsahu byl použit JavaScript (menu stránky), XHTML a samozřejmě Mathematica (veškeré algoritmy uvedených šifer). 4.2.3 Struktura www stránek Stránka je tvořena neměnným záhlavím (s nápisem Metody šifrování) a zápatím. Dynamickou částí stránky je menu (1) obsahující názvy a zároveň odkazy na praktické ukázky některých klasických šifer zpracovaných v Mathematice a implementovaných do prostředí webMathematica. Odkazy z menu jsou nasměrovány do prostorově největší části stránky (2). Po prvním načtení stránky je na tomto místě stránka s krátkým úvodem do problematiky.
Obrázek 4: Vzhled www stránky
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
31
4.2.4 Ovládání stránek Kliknutím na odkaz (1) v menu se v hlavní části stránek zobrazí daná problematika. V horní části je uveden název problematiky (6). Dále je zde tlačítko „Teorie“ (2), po jejímž stlačení se bezprostředně pod ním zobrazí teorie daného příkladu šifry, nebo třeba histogramu jak je na následujícím obrázku. V následující oblasti (4) se nachází „okýnka“ pro vkládání dat uživatelem a potvrzovací tlačítka pro odeslání těchto dat. Po odeslání dat se výsledek zobrazí v oblasti (5). Poslední na co bych chtěl na každém příkladu šifer nebo histogramu upozornit je oblast (7), kde se nachází odkaz pro stáhnutí dané šifry v souboru s příponou *.nb, se kterou si poradí Mathematica. Každá šifra nebo histogram mají jiné požadavky na vstupní data, tudíž se mění i obsah prvků v oblasti (4).
Obrázek 5:Ovládání stránek Dalším typickým vzhledem oblasti (4) z obrázku 5 může být i následující výřez ze stránky s metodou Playfair zobrazený na obrázku 6.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
32
Oblast je rozdělená na dvě části a to na část pro data k zašifrování (1) a pro data k dešifrování (2).
Obrázek 6: Výřez oblasti pro zadávání dat uživatelem
4.2.5 Ukázka zdrojového textu šifry a její popis Vybral jsem šifru jednoduchá záměna s použitím rozházené abecedy. Nejprve uvedu a vysvětlím zdrojový text z www stránek a poté pro porovnání i zdrojový text z Mathematici. Zdrojové texty ostatních šifer mají podobnou strukturu, jen se liší v některých použitých funkcích. 4.2.5.1 Zdrojový text pro aplikaci webMathematica Název souboru je JednZam_ROA.jsp. 1 <%@ taglib uri="/webMathematica-taglib" prefix="msp" %> 2 <%@ page contentType="text/html; charset=windows-1250" language="java" import="java.sql.*" errorPage="" %> 3 4 5 6
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
Vytvoří se klasická abeceda <strong>a..<strong>z a rozházená abeceda, což je klasická abeceda, ale její prvky jsou náhodně rozházené do pole o délce 26 pozicích(26 znaků abecedy). Dále se určí první prvek v řetězci, který chceme zašifrovat. Najde se jeho pozice v klasické abecede a zašifrovaným znakem je pak prvek ležící na stejné pozici, ale v rozházené abecede. Tohle se opakuje pro celý řetězec určený k zašifrování.
17
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
35
74 75 76
Popis zdrojového textu: Řádky 1-12 přeskočím, protože jejich význam jsme si už osvětlili v sekci 4.1.1. Dále budu psát čísla řádků a k nim popis. 13. Hlavička s názvem šifry, jejíž styl je v souboru grafika.css . 14. Hypertextovy odkaz na soubor Jednoducha_zam_ROA.nb, který lze kliknutím na tento odkaz na stránkách stáhnout na Váš disk a otevřít v Mathematice. 15. Tlačítko s nápisem „Teorie“ po jejímž stlačení se volá funkce JavaScriptu s parametrem Div1 (což je id prvku
na řádku 16) „Skryj_Zobraz(Div1)", která je zapsána v souboru grafika.js. 16. Teorie k dané šifře. 17. Začátek formuláře s cílovou stránkou viegener.jsp a data se posílají metodou post. 18. Alokace výpočetního jádra na serveru webMathematici pro následující výpočty. 19. Záčatek buňky s příkazy pro Kernel (dále již nebudu zmiňovat). 20. Vyvolání knihovny pro výpočty. 21. Konec buňky s příkazy pro Kernel (dále již nebudu zmiňovat). 23. Prvek <span> slouží pro řádkou úpravu stylu textu. Má nastavenou třídu „sifrovani“, jejíž styl je popsán v souboru grafika.css. A tento prvek definuje nadpis „Šifrování“. 24. Textové sdělení vypsané přímo na obrazovku. 25. Prvek s parametrem typu použití nastaveným na „text“ a názvem „retezec“. Pokud je potřeba získat data vložená do tohoto textového pole, použije se právě tento název „retezec“. Maximální délka řetezce nastavena na 26 znaků. Přednastavenou hodnotou pro testování je řetězec „ahojpepino“. 26. Tento prvek má nastavený typ na „submit“ a ten z něj udělá tlačítko pro odeslání. Parametr value nastaví popisek na tlačítku a parametrem name je název pro využití stavu tlačítka v další části formuláře.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
36
28. Zde se testuje, zda bylo stlačeno tlačítko s názvem „odeslat“ (jeho zdrojový text se nachází na 26. řádku). ValueQ má dvě hodnoty. Pokud vrátí hodnotu „1“, pak to znamená, že tlačítko „odeslat“ bylo zmáčknuto. Hodnota „0“ značí, že uživatel ještě nestlačil toto tlačítko, tudíž se následující příkazy (zahrnuté v hranatých závorkách If) nebudou provadět. 29. Uvolnění proměnných uvnitř závorek. 30. Vytvoří se proměnná „pomocna“ typu pole, jehož prvky jsou jednotlivé znaky řetězce, který uživatel zadal do prvku s názvem “retezec” ve formuláři. 31. Vznikne proměnná „delka“ do níž se uloží délka předcházející proměnné. 32. Do proměnné „abeceda“ se uloží abeceda „a“ – „z“. 33. Vytvoříme proměnnou „rozabeceda“, což je klasická abeceda, jejíž prvky jsou náhodně přemístěny. Později se použije k zašifrování textu. 34. Inicializace proměnných „sifrovany“ a „pocitadlo“ na prázdnou resp. nulovou hodnotu. 35. – 39. Cyklus for, jenž probíhá tak dlouho, dokud nedojde na konec uživatelem zadaného řetězce. Do proměnné „pomoc2“ se uloží pozice právě zpracovávaného znaku (pomocna[[pocitadlo]]) v abecedě, neboli v proměnné „abeceda“. Následně se najde prvek, který
leží
na
právě
získané
pozici,
avšak
v proměnné
„rozabeceda“
(ToString[rozabeceda[[pomoc2[[1, 1]]]]], tady probíhá šifrování) a obdržený znak se poté zapíše na konec řetězce uloženého v proměnné „siforovany“. 43. 44. Znovu testování stlačení tlačítka „odeslat“. 45. – 46. Výpis výsledku šifrování a tvaru rozházené abecedy. 48. Horizontální čára. 49. – 71. Zde probíhá opačný proces, tedy dešifrování. Postup je velmi podobný, takže zmíním pouze rozdíly. Řetězec k dešifrování má název „retezec2“. Tlačítko pro odeslání textu k dešifrování má tentokrát název „odeslat2“, čímž se rozliší úmysl uživatele. Jestli se jedná o šifrování, obdrží hodnotu „1“ pouze od tlačítka „odeslat“, v případě dešifrování bude hodnotu jedna obsahovat „odeslat2“. Dešifrovaný text je pak uložen v proměnné „desifrovany“ a ten se pak použije při výpisu dešifrovaného textu. 73. Zde končí obsah formuláře.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
37
74. Uvolnění kernelu pro jiné výpočty. 75. Konec těla dokumentu. 76. Konec dokumentu HTML.
4.2.5.2 Zdrojový text pro aplikaci Mathematica Název souboru je Jednoducha_zam_ROA.nb. zdrojový text pro šifrování textu: 1 retezec="ahojpepino"; 2 pomocna=Characters[retezec]; 3 delka=Length[pomocna]; 4 abeceda=CharacterRange["a","z"]; 5 pomoc={p, q, m, z, l, a, o, x, n, w, s, k, c, j,i, e, u, d, h, r, y, v, b, f, g, t}; 6 sifrovany=""; 7 For[pocitadlo=0,pocitadlo<delka,++pocitadlo; 8
Zašifrovaný text: pxiwelenji Popis zdrojového textu šifrování: 1. Do proměnné „retezec“ se uloží řetězec uvedený v uvozovkách za znakem rovnítka. 2. Proměnná s názvem „pomocna“ je tímto definována jako pole, které je postupně naplněno jednotlivými znaky z řetězce uloženého v proměnné „retezec“. 3. Zjištění délky pole „pomocna“ a uložení této hodnoty do proměnné „delka“. 4. Vytvoření pole „abeceda“ a jeho naplnění znaky z rozsahu „a“ až „z“. 5. Pole „pomoc“ s obsahem uvedeným v závorkách. 6. Inicializace proměnné „sifrovany“. 7. – 11. Cyklus For, ve kterém se nejprve na 9. řádku zjišťuje pozice jednotlivých znaků získaných z proměnné „pomocna“ v poli s názvem „abeceda“ a uložení
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
38
získané hodnoty do „pozice“. Poté na 10. řádku následuje zjištění prvku, který leží na právě získané pozici, avšak v poli „pomoc“. Tento znak se poté přidá na konec řetězce, jenž je uložen v proměnné „sifrovany“. Cyklus proběhne tolikrát, jak dlouhý je řetězec určený k šifrování (proměnná „delka“). 12. Výpis proměnné „sifrovany“. Vzniklá šifra ukázkového textu (2. řádek zdrojového textu) je „pixwelei“, uvedl jsem ho do ukázky pro dešifrování, abychom si ukázali, že šifra funguje správně. zdrojový text pro dešifrování textu: 1 retezec2="pxiwelei"; 2 pomocna2=Characters[retezec2]; 3 delka2=Length[pomocna2]; 4 abeceda=CharacterRange["a","z"]; 5 pomoc2={p, q, m, z, l, a, o, x, n, w, s, k, c, j,i, e, u, d, h, r, y, v, b, f, g, t}; 6 desifrovany=""; 7 For[pocitadlo=0,pocitadlo<delka2,++pocitadlo; 8
Dešifrovaný text: ahojpepo Popis zdrojového textu šifrování: 1. – 5. Jsou téměř identické jako u šifrování, jen jsem přidal index „2“. V proměnné „retezec2“ je vložený zašifrovaný řetězec z předcházejícího příkladu šifrování. 6. Inicializace proměnné „desifrovany“ na prázdnou hodnotu. 7. Začátek cyklu For. 8. – 9. Tělo cyklu provádí stejný proces jako na řádcích 7. – 11. z předchozího příkladu s tím rozdílem, že se prohodily proměnné „pomoc2“ a „abeceda“, takže se znaky převádí z abecedy šifrovaného textu do abecedy otevřeného textu (klasický abeceda „a“ – „z“). 10. Konec cyklu.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
39
11. Výpis proměnné „desifrovany“ na výstupu. Podle dešifrovaného textu uvedeného následně po zdrojovém textu je vidět, že program pracuje správně, což si ostatně můžete vyzkoušet i v přiloženém souboru, jehož název je uvedený výše.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
40
ZÁVĚR Hlavním cílem této práce bylo naznačit potenciál aplikace webMathematica na několika příkladech metod šifrování klasické kryptografie. Když zkouším jednotlivé šifry na www stránkách, tak získávám stejné výsledky, jako kdybych prováděl šifrování na papíře, tudíž se mi tahle část práce povedla. Kromě šifrování jsem u většiny šifer uvedl i možnost dešifrování pro ověření správnosti výsledku, které získáme pomocí šifrování. Možnosti rozšíření mých www stránek bych viděl v přeložení do anglického jazyka, aby jim rozumělo širší spektrum uživatelů. Vývoj aplikací v prostředí webMathematica mě osobně hodně zaujal a myslím, že propojení programu Mathematica s webovými stránkami byl velmi dobrý nápad a může směřovat k velmi zajímavým projektům.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
41
ZÁVĚR V ANGLIČTINĚ Main aim those work was indicate potential of application webMathematica on several instances methods encryption classical cryptography. When I examine individual cipher on www pages, so extract same record, like if do encryption on paper, hence me traction volume of work answer. Except encryption near most cipher introduced also possibility decipherment for check rightness result that we obtain by the help of encryption. Possibilities enlargement mine www pages I would saw in transfer to the English language, to state intelligibility wider spectrum users. I am personally with application development in environment webMathematica much impressed and I think that the connection program Mathematica with web pages was very good idea and is able to aim at intriguing projects.
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
SEZNAM POUŽITÉ LITERATURY Grošek O., Porubský Š.: Šifrovanie. Algoritmy, metódy a prax. Praha, Grada 1992 Janeček J.: Odhalená tajemství šifrovacích klíčů minulosti. Praha, Naše vojsko, 1994 Prokopová Z.: Základy informatiky. Vydavatelství FT, Zlín, 1998 Zelinka I.: Aplikovaná informatika. VUT Zlín, 1999 http://www.zivel.cz/toISO-8859-2.en/article.php?id=304 http://cs.wikipedia.org/ http://zelinka-mathematica.utb.cz:8080/webMathematica/student/ http://www.wolfram.com/products/webmathematica/whatis.html http://www.karlin.mff.cuni.cz/~tuma/nciphers/nciphers1.pdf
42
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
SEZNAM POUŽITÝCH SYMBOLŮ A ZKRATEK AOT
abeceda otevřeného textu.
AŠT
abeceda šifrovaného textu.
43
UTB ve Zlíně, Fakulta aplikované informatiky, 2007
44
SEZNAM OBRÁZKŮ Obrázek 1: Viegenérova tabulka – metoda Viegenérova šifra ........................................... 12 Obrázek 2: Viegenérova tabulka – metoda Autokláv........................................................ 17 Obrázek 3. Histogram textu ............................................................................................. 22 Obrázek 4: Vzhled www stránky ..................................................................................... 30 Obrázek 5:Ovládání stránek ............................................................................................. 31 Obrázek 6: Výřez oblasti pro zadávání dat uživatelem...................................................... 32
UTB ve Zlíně, Fakulta aplikované informatiky, 2007