INFSCI 1075 Network Security Homework 5 Reading assig nment

INFSCI 1075: Network Security Homework 5 Reading assig nment Read the article on ransomware posted on courseweb 1. Write a program (in Cor Java) that can implement the shift cipher Ittakes as input plain ascii text, a character \"D\" or \"E to denote decryption or encryption and a key k that is also a capital alphabet. It converts the text into all caps, ignores all other characters and outputs the ciphertext or plaintext as the case may be. Make sure that it prints an error if anything other than Dor Eistyped or ifthe key is not a capital alphabet. a. Attach the source code with your homework. b. Show some example inputs and outputs. 2. The following piece of ciphertext is di GOGONDDYCOOKWYFSOVKCDG00U If it is the shift cipher, determine the value of the key k by brute force. You can use the program from Problem 2. Show the results for each value of the key kfork 1, 2 25 3. Consider the following piece of ciphertext. You know that it has been encrypted using the shift cipher. Without performing an exhaustive key search, determine the key and the plaintext. Explain what you did clearly. 4. If a chip can do a decryp ion in three clock cycles and it is at 4 GHz.compute he average and worst case time (in years) required to do a brute force attack on AES with a key size of 128 bits with a known plaintext. How does this compare with the age of the earth which is estimated to be 455 billion years? If the chip speed doubles every 8 months, how many years do we have to wait before this enhanced version can be broken by brute force in 24 hours? How do the results change if 5000 chips run in parallel in each case? Compare the times and comment on the results

Solution

import java.util.Scanner;

public class ShiftCipher {

   public static String encyrptDecrypt(String inputText, int offset) {
      
       StringBuffer encryptBuffer = new StringBuffer();
      
       /*
       * For each character, it checks whether it is between A-Z,
       * if yes then computes the substitute character
       */
       for (int i=0; i< inputText.length(); i++) {
           char character = inputText.charAt(i);
          
           if (character >= 65 && character<= 97) {
               character = (char) ((character -\'A\' + offset) % 26 + \'A\');
           }
           encryptBuffer.append(character);
       }
       return encryptBuffer.toString();
   }
  
   public static void main(String args[]) {
      
       Scanner scan = new Scanner(System.in);
       System.out.print(\"Encryption or Decryption ? (E/D) : \");
       String choice = scan.nextLine();
      
       if(choice.equals(\"E\") || choice.equals(\"D\")) {
          
           System.out.print(\"Enter the key (A-Z) : \");
           String key = scan.nextLine().trim();
          
           /*
           * Validate if key is a capital alphabet
           * Beacuse of the cyclic property, we can use the same functions
           * to encrypt (key=n) and decrypt(key=26-n)
           */
           if (key.length() == 1 && Character.isUpperCase(key.charAt(0))) {
              
               System.out.print(\"Enter the text : \");
               String text = scan.nextLine().trim().toUpperCase();
              
               if (choice.equals(\"E\")) {
                   System.out.println(\"Cipher is : \"+ encyrptDecrypt(text, key.charAt(0)-\'A\'));
               }
               else {
                   System.out.println(\"Cipher is : \"+ encyrptDecrypt(text, 26-(key.charAt(0)-\'A\')));
               }
           }
           else {
               System.out.println(\"Invalid key entered. Must be between A-Z\");
           }
       }
       else {
           System.out.println(\"Invalid Option Entered\");
       }
       scan.close();
   }
}

--------------------------------------------
Output-1

Encryption or Decryption ? (E/D) : E
Enter the key (A-Z) : H
Enter the text : ZUBAIR
Cipher is : GBIHPY

-------------------------------------------
Output-2

Encryption or Decryption ? (E/D) : D
Enter the key (A-Z) : H
Enter the text : GBIHPY
Cipher is : ZUBAIR
--------------------------------------------

 INFSCI 1075: Network Security Homework 5 Reading assig nment Read the article on ransomware posted on courseweb 1. Write a program (in Cor Java) that can imple
 INFSCI 1075: Network Security Homework 5 Reading assig nment Read the article on ransomware posted on courseweb 1. Write a program (in Cor Java) that can imple

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site