Cryptography – Caesar Cipher

The Caesar Cipher

The key for the Caesar Cipher will be a number from 1 to 26. Unless you know the key (that is, know the number used to encrypt the message), you won’t be able to decrypt the secret code.

The Caesar Cipher was one of the earliest ciphers ever invented. In this cipher, you encrypt a message by taking each letter in the message (in cryptography, these letters are called symbols because they can be letters, numbers, or any other sign) and replacing it with a “shifted” letter. If you shift the letter A by one space, you get the letter B. If you shift the letter A by two spaces, you get the letter C. Figure 14-1 is a picture of some letters shifted over by three spaces.

To get each shifted letter, draw out a row of boxes with each letter of the alphabet. Then draw a second row of boxes under it, but start a certain number (this number is the key) of spaces over. After the letters at the end, wrap around back to the start of the boxes. Here is an example with the letters shifted by three spaces:

Invent with Python

Making paper cryptography paper tools

A Virtual Cipher Wheel

Assignments:
1. En-Crypt: Caesar Cipher  – Cryptography

Use the cipherwheel to encrypt a message. In a piece of paper, share the encrypted message with a partner.
In this post, you will type the message, the encrypted message and the one piece of information needed for your partner to decrypt it.

2. De-Crypt: Caesar Cipher –  Cryptography
In this post type your partner’s encrypted message and the one piece of information needed to decrypt it. What is the message?

NOTE: Include your partner’s name

In this post type your partner’s encrypted message and the one piece of information needed to decrypt it. What is the message?

NOTE: Include your partner’s name

3. Your Cipher – Cryptography

Design your own cipher and a device to easily encrypt and decrypt messages. Think ahead and prepare a checklist of materials you might need.

  1. Describe your cipher.
  2. Draw a diagram for your device.
  3. Build your device.
  4. Type here decryption instructions.

4. Friend’s Cipher – Cryptography

Find a classmate and exchange ciphers, instructions and encrypted message. After you checked with your classmate that you were able to decrypt the message, comment on the following:
1. Efficiency of the cipher
2. Quality of the instructions

NOTE: If the instructions were not clear or you couldn’t follow them, help your classmate make the right changes.
Include the name of your classmate.

5. Brute Force – Cryptography

If you didn’t have a key to decipher an encrypted message, how would write a program to decrypt it?

Write the pseudocode for you decrypting program using brute force.

Submit the instructions for your encryption device in the corresponding post. Include your name in the instructions.
Print your instructions and attach it to your device. I will “glue/attach” it to a poster. Please hand everything with your name on it.

Cryptography – Resources

Your Cipher – Clwk 9/6/2018 – Cryptography

Due 09/11, 6:45 PM

Instructions

‘3. Design your own cipher and a device to easily encrypt and decrypt messages.

Describe your cipher. Draw a diagram for your device. Build your device. Type here decryption instructions.

    1. Friend’s Cipher – Cryptography

Find a classmate and exchange ciphers, instructions and encrypted message. After you checked with your classmate that you were able to decrypt the message, comment on the following: Efficiency of the cipher Quality of the instructions

NOTE: If the instructions were not clear or you couldn’t follow them, help your classmate make the right changes. Include the name of your classmate.

    1. Brute Force – Cryptography

If you didn’t have a key to decipher an encrypted message, how would write a program to decrypt it?

Write the pseudocode for you decrypting program using brute force.

Submit the instructions for your encryption device in the corresponding post. Include your name in the instructions.

Print your instructions and attach it to your device. I will “glue/attach” it to a poster. Please hand everything with your name on it.

De-Crypt: Caesar Cipher – Clwk 9/6/2018 – Cryptography

Due 09/06, 6:45 PM

Instructions

    1. In this post type your partner’s encrypted message and the one piece of information needed to decrypt it. What is the message?

NOTE: Include your partner’s name

En-Crypt: Caesar Cipher – Clwk 9/6/2018 – Cryptography

Due 09/06, 6:45 PM

Instructions

https://java.mrseliasclasses.org/cryptography-caesar-cipher/

    1. Use the “cipherwheel” to encrypt a message. In a piece of paper, share the encrypted message with a partner. In this post, you will type the message, the encrypted message and the one piece of information needed for your partner to decrypt it.

NOTE: Include your partner’s name Yours should be at the top.

Submit here both messages from you: the encrypted and the decrypted from your partner.

What do you need to tell your partner to be able to decrypt the message?

Encryption and Decryption Hand-written Example

Due 09/11, 6:45 PM

Instructions

Hand-in the paper(s) with your english sentence and the encrypted version for your partner. And, the encrypted sentence from your partner and the english version of it.

Information entropy | Journey into information theory | Computer Science | Khan Academy

https://www.youtube.com/watch?v=2s3aJfRr9gE

Shannon Entropy and Information Gain

https://www.youtube.com/watch?v=9r7FIXEAGvs

https://www.youtube.com/watch?v=9r7FIXEAGvs&t=57s

Entropy in Compression – Computerphile

https://www.youtube.com/watch?v=M5c_RFKVkko

Your Cipher – Clwk 9/6/2018 – Cryptography

Due 09/11, 6:45 PM

Instructions

‘3. Design your own cipher and a device to easily encrypt and decrypt messages.

Describe your cipher. Draw a diagram for your device. Build your device. Type here decryption instructions.

    1. Friend’s Cipher – Cryptography

Find a classmate and exchange ciphers, instructions and encrypted message. After you checked with your classmate that you were able to decrypt the message, comment on the following: Efficiency of the cipher Quality of the instructions

NOTE: If the instructions were not clear or you couldn’t follow them, help your classmate make the right changes. Include the name of your classmate.

    1. Brute Force – Cryptography

If you didn’t have a key to decipher an encrypted message, how would write a program to decrypt it?

Write the pseudocode for you decrypting program using brute force.

Submit the instructions for your encryption device in the corresponding post. Include your name in the instructions.

Print your instructions and attach it to your device. I will “glue/attach” it to a poster. Please hand everything with your name on it.

De-Crypt: Caesar Cipher – Clwk 9/6/2018 – Cryptography

Due 09/06, 6:45 PM

Instructions

    1. In this post type your partner’s encrypted message and the one piece of information needed to decrypt it. What is the message?

NOTE: Include your partner’s name

En-Crypt: Caesar Cipher – Clwk 9/6/2018 – Cryptography

Due 09/06, 6:45 PM

Instructions

https://java.mrseliasclasses.org/cryptography-caesar-cipher/

    1. Use the “cipherwheel” to encrypt a message. In a piece of paper, share the encrypted message with a partner. In this post, you will type the message, the encrypted message and the one piece of information needed for your partner to decrypt it.

NOTE: Include your partner’s name Yours should be at the top.

Submit here both messages from you: the encrypted and the decrypted from your partner.

What do you need to tell your partner to be able to decrypt the message?

Encryption and Decryption Hand-written Example

Due 09/11, 6:45 PM

Instructions

Hand-in the paper(s) with your english sentence and the encrypted version for your partner. And, the encrypted sentence from your partner and the english version of it.

Information entropy | Journey into information theory | Computer Science | Khan Academy

https://www.youtube.com/watch?v=2s3aJfRr9gE

Shannon Entropy and Information Gain

https://www.youtube.com/watch?v=9r7FIXEAGvs

https://www.youtube.com/watch?v=9r7FIXEAGvs&t=57s

Entropy in Compression – Computerphile

https://www.youtube.com/watch?v=M5c_RFKVkko

Mail Order System

Good programming style:

  1. Header (Description, author’s name, date, and java version)
  2. Imports if any.
  3. Driver or tester class.
  4. The program should have a proper exit with a message.
  5. Input/output included as a paragraph comment.

The following description of this assignment can be modified to suit the requirements: it should use at least an ArrayList, it should be object-oriented, and have good programming practices. 

mail-order house sells five products whose retail prices are as follows:

Product 1, $2.98

Product 2, $4.50

Product 3, $9.98

Product 4, $4.49

Product 5, $6.87

Write a java program MailOrder_YI.java and its driver, MailOrderTest.java to prompt the user for the following after a short welcome message.

a) Product number
b) Quantity sold


It should calculate and display the total retail value of all products sold. Use a sentinel-controlled (like “yesNo”) loop to determine when the program should stop looping and display the final results.


Sample output:

Welcome to Mrs. “Elia’s Mail Order Clearing House”
Product 1, $2.98
Product 2, $4.50
Product 3, $9.98
Product 4, $4.49
Product 5, $6.87

Product number?: 1
Quantity?: 2
Do you want to continue?(yes/no): yes
Product number?: 2
Quantity?: 5
Do you want to continue?(yes/no): yes
Product number?: 3
Quantity?: 3
Do you want to continue?(yes/no): yes
Product number?: 4
Quantity?: 1
Do you want to continue?(yes/no): no
Total Price: $62

Required submission:

  1. A short video.
  2. Copy and paste both programs.
  3. Submit the zipped project.

Calories and Fat Calculator

Good programming style:

  1. Header (Description, author’s name, date, and java version)
  2. Imports if any.
  3. Driver or tester class.
  4. The program should have a proper exit with a message.
  5. Input/output included as a paragraph comment.

The following description of this assignment can be modified to suit the requirements: it should use at least an ArrayList, it should be object-oriented, and have good programming practices. 

Write a java program, FoodChart.java, and FoodChartTest.java to provide calories and fat content in a selected number of foods.
– Choose 4 different categories of foods from the link attached to the image or any other resource you might want to use.
– Write a function for each of the categories with at least 5 food choices.
– Display a menu and prompt the user for choices.
– Once the user is finished selecting, display the number of calories and the fat content.

Example:

1. Meats
2. Grains
3. Vegetables
4. Fruit

Choose a category: 2

1. Rice, brown long-grain  Fat: 1.8 grams Calories: 216
2. Pasta, whole wheat      Fat: 1 gram    Calories: 214
3. Pasta, corn             Fat: 1.5 grams Calories: 210
4. Pasta, Quinoa           Fat: 0 grams   Calories: 200
5. Pasta, Soba (buckwheat) Fat: 1.5 grams Calories: 190
Choose the food: 4

Do you want to continue? y/n

if the answer is not:
   The total gram of fat is ... and the calories are ...
   Would you like to start again? y/n
else
    
1. Meats
2. Grains
3. Vegetables
4. Fruit

Choose a category:

Required submission:

  1. A short video.
  2. Copy and paste both programs.
  3. Submit the zipped project.

GUI: Moving Car “Animation”

Courtesy from Lachlan:


/* Lachlan McCarty
 * 11-16-14
 * 1.8.0_25
 * LM_MovingCar.java
 * Write a program, YI_MovingCar.java that animates a car 
 * so that it moves across a frame.
 */

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JFrame;
import javax.swing.JComponent;
import javax.swing.Timer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LM_MovingCar {

	private final int FRAME_WIDTH = 450;
	private final int FRAME_HEIGHT = 100;
	private final int DELAY = 100;
	private final LM_MovingCarComponent component = new LM_MovingCarComponent();
	private final JFrame frame = new JFrame();
	
	public LM_MovingCar() {
		frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
		frame.setTitle("Moving Car");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		frame.add(component);
		
		frame.setVisible(true);
		
		ActionListener listener = new LM_TimerListener();
		Timer t = new Timer(DELAY, listener);
		t.start();
	}
	
	public static void main(String[] args) {
		new LM_MovingCar();
	}
	
	private class LM_TimerListener implements ActionListener {
		public void actionPerformed(ActionEvent event) {
			component.increaseCoor(1,0);
		}
	}
	
	private class LM_MovingCarComponent extends JComponent {
		private final int MULTIPLIER = 2; //ok to change
		private int xpadding = 10; // ok to change
		private int ypadding = 10; // ok to change
		private int CAR_WIDTH = 60*MULTIPLIER; // do not change
		private int CAR_HEIGHT = 40*MULTIPLIER; // do not change
	
		public void paintComponent(Graphics g) {
			Graphics2D g2 = (Graphics2D) g;
			// turn on antialiasing so it doesn't look like crap
			RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
													RenderingHints.VALUE_ANTIALIAS_ON);
			g2.setRenderingHints(rh);
			
			g2.drawRect(0*MULTIPLIER+xpadding,10*MULTIPLIER+ypadding,60*MULTIPLIER,10*MULTIPLIER);
			g2.drawOval(10*MULTIPLIER+xpadding,20*MULTIPLIER+ypadding,10*MULTIPLIER,10*MULTIPLIER);
			g2.drawOval(40*MULTIPLIER+xpadding,20*MULTIPLIER+ypadding,10*MULTIPLIER,10*MULTIPLIER);
			g2.drawPolygon(new int[]{10*MULTIPLIER+xpadding,20*MULTIPLIER+xpadding,40*MULTIPLIER+xpadding,50*MULTIPLIER+xpadding},
							new int[]{10*MULTIPLIER+ypadding,0*MULTIPLIER+ypadding,0*MULTIPLIER+ypadding,10*MULTIPLIER+ypadding}, 4);
		}
		
		public void increaseCoor(int x, int y) {
			if (xpadding+x+CAR_WIDTH <= FRAME_WIDTH) xpadding += x;
			if (ypadding+y+CAR_HEIGHT <= FRAME_HEIGHT) ypadding += y;
			repaint();
		}
	}
}

Screen Shot 2014-11-25 at 1.43.16 PM

GUI: House.java

Classwork:

Exercise:

  1. Write a GUI application, YI_House.java and its JFrame class to draw a house and the sun like the one in the picture.

house
NOTE: You can have only one class.
Extra credit: Draw a person like the one in the picture.

Homework: finish up this assignment

GUI: Dialog boxes

Classwork:
Write an OOD application, YI_WordValue.java to calculate the value of a word in the Scrabble game. Prompt the user for a word and display it worth using the table below:
Screen Shot 2015-02-11 at 12.19.37 PM

Write the tester class using a dialog box for user input.

Using dialog boxes
The JOptionPane class has the static showInputDialog method of t and supply the string that
prompts the input from the user.

Some examples:
String input = JOptionPane.showInputDialog(“Enter a word:”);
That method returns a String object.

You can also display output in a dialog box:
JOptionPane.showMessageDialog(null, “Word value: ” + worth);

Screen Shot 2015-02-18 at 11.10.45 AM

Any time you invoke the showInputDialog or showMessageDialog method in a program that
does not show any other frame windows, you need to add a line

System.exit(0);

to the end of your main method.

The showInputDialog method starts a user interface thread to handle user input. When the main method reaches the end, that thread is still running, and your program won’t exit automatically.

Calling the static method exit() from the System class, will force the program to exit. The parameter is the program’s status code. Zero represents a successful execution.


Screen Shot 2015-02-11 at 12.59.39 PM

Exit code is

0 when execution went fine;
1, -1, whatever != 0 when some error occurred, you can use different values for different kind of errors.

GUI: Rectangle moving component

More on Event Listeners:
Classwork:

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JComponent;

/**
   This component displays a rectangle that can be moved. 
*/
public class RectangleMovingComponent extends JComponent
{  
   private static final int BOX_X = 100;
   private static final int BOX_Y = 100;
   private static final int BOX_WIDTH = 20;
   private static final int BOX_HEIGHT = 30;

   private Rectangle box;

   public RectangleMovingComponent()
   {  
      // The rectangle that the paintComponent method draws 
      box = new Rectangle(BOX_X, BOX_Y, BOX_WIDTH, BOX_HEIGHT);         
   }

   public void paintComponent(Graphics g)
   {  
      Graphics2D g2 = (Graphics2D) g;

      g2.draw(box);
   }

   /**
      Moves the rectangle by a given amount. 
      @param x the amount to move in the x-direction 
      @param y the amount to move in the y-direction 
   */
   public void moveBy(int dx, int dy)
   {
      box.translate(dx, dy);
      repaint();      
   }
}

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.Timer;

/**                         
   This program moves the rectangle.
*/
public class RectangleMover
{
   private static final int FRAME_WIDTH = 300;
   private static final int FRAME_HEIGHT = 400;

   public static void main(String[] args)
   {
      JFrame frame = new JFrame();

      frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
      frame.setTitle("An animated rectangle");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      final RectangleMovingComponent component = new RectangleMovingComponent();
      frame.add(component);

      frame.setVisible(true);
      
      class TimerListener implements ActionListener
      {
         public void actionPerformed(ActionEvent event)
         {
            component.moveBy(1, 1);
         }
      }

      ActionListener listener = new TimerListener();

      final int DELAY = 100; // Milliseconds between timer ticks
      Timer t = new Timer(DELAY, listener);
      t.start();      
   }
}


Use the programs given to write a program, YI_BouncingBlock.java to make the block bounce when it reaches a all.

Homework:
1. Write a program, YI_MovingCar.java that animates a car so that it moves across a frame.
2. Write a program, YI_TwoMovingCars.java that animates two cars moving across a frame in opposite directions (but at different heights so that they don’t collide.)

import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
   This program demonstrates how to install an action listener.
*/
public class ButtonViewer
{  
   private static final int FRAME_WIDTH = 100;
   private static final int FRAME_HEIGHT = 60;
   

   public static void main(String[] args)
   {  
       
        /************   Inner Class Define Before is used  ***************************/
      
        /**
           An action listener that prints a message.
        */
        class ClickListener implements ActionListener
        {
           public void actionPerformed(ActionEvent event)
           {
              System.out.println("I was clicked.");
           }            
        }

       /************   Inner Class  End  ***************************/
       
       
       
       
      JFrame frame = new JFrame();
      JButton button = new JButton("Click me!");
      frame.add(button);
     
      ActionListener listener = new ClickListener();
      button.addActionListener(listener);

      frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
      
      
      

   }
   


}