Presentation is loading. Please wait.

Presentation is loading. Please wait.

Consolidation. Code making (i.e. making ciphers) is undertaken by a cryptographer whereas cryptanalysts try to break ciphers in order to gain intelligence.

Similar presentations


Presentation on theme: "Consolidation. Code making (i.e. making ciphers) is undertaken by a cryptographer whereas cryptanalysts try to break ciphers in order to gain intelligence."— Presentation transcript:

1 Consolidation

2 Code making (i.e. making ciphers) is undertaken by a cryptographer whereas cryptanalysts try to break ciphers in order to gain intelligence about enemy activity. The diagram below illustrates the process of encoding and decoding text.

3 A well-known kind of substitution encryption is the Caesar Cipher Shift. Julius Caesar used this algorithm to encrypt messages sent to officials. In this algorithm each plain text character is replaced by a character N places after (or before) that character. Here the key contains a shift number. So if the key had the value 1 then the text Hello world Would be encrypted as: IFMMN XNSME You are required to develop a game program that supports the Caesar cipher shift algorithm. The game is undertaken by two players using a single Java application running on one computer: the cryptographer and the cryptanalyst.

4 The cryptographer is presented with a window (JFrame) that allows her to enter a plain text message (of about 10 lines, with only alphabetic characters and space punctuation). She can also select a key using a JComboBox that allows a shift of between 1 and 25. Shift left and shift right JRadioButtons should be used to indicate the direction of substitution. A separate read-only text area displays the resulting cipher text. The cryptanalyst’s window is then displayed, just showing the read-only cipher text. The cryptanalyst is then required to decrypt the cipher and typing the decrypted plain text in a separate text area input field. When satisfied with the decryption she hits the “Decrypted” button. The program must compare the decrypted text with the original plain text and provide a score showing the percentage of characters that were entered in the correct position.

5 Design the screens

6 You got 60% The answer was hello Type words here How many places Will look like this encrypt done What happens when close? hello ifmmp 1 You see Type guess here guess What happens when close? ifmmp henno quit

7 What objects does that lead to? Cryptographer? Cryptoanalyst? Something in background holding the model (what is in the model?)

8

9 Starting with SimpleImproved code public class MyDriver{ public static void main(String a[]){ MyFrame app=new MyFrame(); } Need 2 frames 1 for cryptographer 1 for cryptoanalyst Also create the model Pass the model to the frames AND ???

10 roughly public class MyDriver{ public static void main(String args[]) { Model m=new Model(); Cryptanalyst p2=new Cryptanalyst(m); Cryptographer p1=new Cryptographer(m,p2); }

11 import javax.swing.*; public class MyFrame extends JFrame{ private MyPanel panel; public MyFrame() { panel= new MyPanel(); add(panel); setSize(200,200); setLocation(200,200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("demo swing"); setVisible(true); } Could base both on this Note could have a different default close operation for the 1 st person (instead perhaps it should just close that frame) Or possibly for both

12 roughly import javax.swing.*; public class Cryptographer extends JFrame{ private CryptoPanel panel; public Cryptographer(Model m, Cryptanalyst p) { panel= new CryptoPanel(m, p, this); add(panel); setSize(200,200); setLocation(200,200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //probably not! setTitle("cryptographer"); setVisible(true); }

13 roughly import javax.swing.*; public class Cryptanalyst extends JFrame{ private AnalystPanel panel; public Cryptanalyst (Model m) { panel= new AnalystPanel(m); add(panel); setSize(200,200); setLocation(300,300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //maybe? setTitle("CRYPTANALYST"); setVisible(false); }

14 import javax.swing.*; import java.awt.event.*; public class MyPanel extends JPanel implements ActionListener{ private JButton button; private String name; public MyPanel() { button=new JButton("Hello"); add(button); button.addActionListener(this); } public void actionPerformed(ActionEvent e){ System.out.println("pressed"); name = JOptionPane.showInputDialog (null,"Enter name : ","entry", 1); if(name != null) JOptionPane.showMessageDialog(null, "hallo : " + name,"entry", 1); }

15 The panel in the Cryptographer frame could be a GridLayout with 4 rows and 2 columns It needs 2 JButtons, 2 JTextFields and 4 JLabels (worry about the radio button later) When the encrypt button is pressed it takes what they typed and updates the model When the done button is pressed it makes its frame not visible and makes the OTHER frame visible Note this means you need a link back to this frame and a link to the other frame Type words here How many places Will look like this encrypt done What happens when close? hello ifmmp 1

16 roughly import javax.swing.*; import java.awt.event.*; public class CryptoPanel extends JPanel implements ActionListener{ private Model model; private Cryptanalyst otherPlayer; private Cryptographer parent; private JButton done; public CryptoPanel(Model m, Cryptanalyst c, Cryptographer p) { model=m; otherPlayer=c; parent=p; done=new JButton("done"); add(done); done.addActionListener(this); //also encrypt button } public void actionPerformed (ActionEvent e) { System.out.println("pressed player 1"); //when they press done make the otherPlayer visible and make this frame invisible otherPlayer.setVisible(true); parent.setVisible (false); //when they press encrypt update the model with the values }

17 The panel in the Cryptoanalyst frame could be a GridLayout with 3 rows and 2 columns It needs 2 JButtons, 1 JTextFields and 3 JLabels When the guess button is pressed it compares the value in the JTextField to the value in the model and pops up a show MessageDialog with the stats When the quit button is pressed it quits You got 60% The answer was hello You see Type guess here guess What happens when close? ifmmp henno quit

18 VERY roughly import javax.swing.*; import java.awt.event.*; public class AnalystPanel extends JPanel implements ActionListener{ private Model model; public AnalystPanel(Model m) { model=m; //buttons, make sure ‘this’ listens to buttons, and textfield } public void actionPerformed(ActionEvent e){ System.out.println("pressed player 2"); //when they press ‘guess’ call a method of model with the value in the JTextField //that should return a string (the % right and the answer) //display that using //JOptionPane.showMessageDialog(null, returnedString, 1); } }

19 I will make this available It is incomplete


Download ppt "Consolidation. Code making (i.e. making ciphers) is undertaken by a cryptographer whereas cryptanalysts try to break ciphers in order to gain intelligence."

Similar presentations


Ads by Google