# HG changeset patch # User František Kučera # Date 1371909639 -7200 # Node ID c681a3a6cbac83f4f3a93e390752b321bcfe0b5a # Parent b356e7c9211f4c46b194bb0ea0a24fe759711748 Caesarova šifra – jednoduchá GUI aplikace pro šifrování a dešifrování. diff -r b356e7c9211f -r c681a3a6cbac java/CaesarovaŠifra/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/CaesarovaŠifra/build.xml Sat Jun 22 16:00:39 2013 +0200 @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project CaesarovaŠifra. + + + diff -r b356e7c9211f -r c681a3a6cbac java/CaesarovaŠifra/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/CaesarovaŠifra/manifest.mf Sat Jun 22 16:00:39 2013 +0200 @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff -r b356e7c9211f -r c681a3a6cbac java/CaesarovaŠifra/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/CaesarovaŠifra/nbproject/build-impl.xml Sat Jun 22 16:00:39 2013 +0200 @@ -0,0 +1,1411 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r b356e7c9211f -r c681a3a6cbac java/CaesarovaŠifra/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/CaesarovaŠifra/nbproject/genfiles.properties Sat Jun 22 16:00:39 2013 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=c939b5a0 +build.xml.script.CRC32=3140f660 +build.xml.stylesheet.CRC32=28e38971@1.56.1.46 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=c939b5a0 +nbproject/build-impl.xml.script.CRC32=fac7e01a +nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 diff -r b356e7c9211f -r c681a3a6cbac java/CaesarovaŠifra/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/CaesarovaŠifra/nbproject/project.properties Sat Jun 22 16:00:39 2013 +0200 @@ -0,0 +1,71 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Caesarova_ifra.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=cz.frantovo.p\u0159\u00edklady.Caesar +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff -r b356e7c9211f -r c681a3a6cbac java/CaesarovaŠifra/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/CaesarovaŠifra/nbproject/project.xml Sat Jun 22 16:00:39 2013 +0200 @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + CaesarovaŠifra + + + + + + + + + diff -r b356e7c9211f -r c681a3a6cbac java/CaesarovaŠifra/src/cz/frantovo/příklady/Caesar.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/CaesarovaŠifra/src/cz/frantovo/příklady/Caesar.java Sat Jun 22 16:00:39 2013 +0200 @@ -0,0 +1,108 @@ +package cz.frantovo.příklady; + +/** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +import java.awt.GridLayout; +import java.awt.HeadlessException; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JTextField; + +/** + * @author Ing. František Kučera (frantovo.cz) + */ +public class Caesar extends JFrame { + + private JTextField prostýText = new JTextField(); + private JTextField šifrovanýText = new JTextField(); + private JButton šifruj = new JButton("Šifruj"); + private JButton dešifruj = new JButton("Dešifruj"); + private static final char[] ABECEDA_ZNAKY = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray(); + private static final List ABECEDA; + private static final int SKOK = 3; + + static { + List abeceda = new ArrayList<>(); + for (char z : ABECEDA_ZNAKY) { + abeceda.add(z); + } + ABECEDA = Collections.unmodifiableList(abeceda); + } + + public static void main(String[] args) { + Caesar c = new Caesar(); + c.setVisible(true); + } + + public Caesar() throws HeadlessException { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setTitle("Caesarova šifra"); + setLocationRelativeTo(null); + setLayout(new GridLayout(3, 2)); + + add(new JLabel("Prostý text")); + add(prostýText); + + add(new JLabel("Šifrovaný text")); + add(šifrovanýText); + + add(šifruj); + add(dešifruj); + + šifruj.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + šifrovanýText.setText(posuň(prostýText.getText(), SKOK)); + } + }); + + dešifruj.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + prostýText.setText(posuň(šifrovanýText.getText(), -SKOK)); + } + }); + + pack(); + } + + private static String posuň(String text, int oKolik) { + StringBuilder posunutý = new StringBuilder(text.length()); + + for (char z : text.toCharArray()) { + posunutý.append(posuň(z, oKolik)); + } + + return posunutý.toString(); + } + + private static char posuň(char znak, int oKolik) { + int původníPozice = ABECEDA.indexOf(znak); + + if (původníPozice < 0) { + return znak; + } else { + int nováPozice = (původníPozice + oKolik) % ABECEDA_ZNAKY.length; + nováPozice = nováPozice < 0 ? ABECEDA_ZNAKY.length + nováPozice : nováPozice; + return ABECEDA.get(nováPozice); + } + } +}