Question

In: Computer Science

The following methods are used: main(...), the encode(...) and the decode()....Is there any issue with one...

The following methods are used: main(...), the encode(...) and the decode()....Is there any issue with one of the method? If yes can you correct it.

You are requested to implement the same program without the two methods encode() and decode()...

Implement the code only with the main() and test your program again.

public class SCiphM {

    final static String key = "]kYV}(!7P$n5_0i R:?jOWtF/=-pe'AD&@r6%ZXs\"v*N"
            + "[#wSl9zq2^+g;LoB`aGh{3.HIu4fbK)mU8|dMET><,Qc\\C1yxJ";

    static String text = "Here we have to do is there will be a input/source "
            + "file in which we are going to Encrypt the file by replacing every "
            + "upper/lower case alphabets of the source file with another "
            + "predetermined upper/lower case alphabets or symbols and save "
            + "it into another output/encrypted file and then again convert "
            + "that output/encrypted file into original/decrypted file. This "
            + "type of Encryption/Decryption scheme is often called a "
            + "Substitution Cipher.";

    public static void main(String[] args) {
        String enc = encode(text);

        System.out.println("Encoded: " + enc);
        System.out.println("\nDecoded: " + decode(enc));
    }

    static String encode(String s) {
        String sb = new String(s);
        String r="";
        for (int i =0 ; i < sb.length(); i++) {
            r= r + key.charAt((int)sb.charAt(i) - 32);
           
        }

        return r;
    }
   
    static String decode(String s) {
        String sb1 = new String(s);
        String r1="";
       
        for (int i =0 ; i < sb1.length(); i++) {
            r1= r1 + key.charAt((int)sb1.charAt(i) + 32);
           
        }

        return r1;
    }
   

   
}

Solutions

Expert Solution

Answer:

There is issue with Decode method.


Related Solutions

An encryption-decryption system consists of three elements: encode, transmit, and decode. A faulty encode occurs in...
An encryption-decryption system consists of three elements: encode, transmit, and decode. A faulty encode occurs in 0.7% of the messages processed, transmission errors occur in 1% of the messages, and a decode error occurs in 0.1% of the messages. Assume the errors are independent. Round your answers to four decimal places (e.g. 98.7654). (a) What is the probability of a completely defect-free message? (b) What is the probability of a message that has either an encode or a decode error?
Write a Java program that will encode plain text into cipher text and decode cipher text...
Write a Java program that will encode plain text into cipher text and decode cipher text into plain text. Create following methods and add them to your class: • a method named encode(String p, int key) that takes a plain text p and encodes it to a cipher text by adding the key value to each alphabet character of plain text p using the ASCII chart. The method should return the encoded String. For example, if p = "attack at...
Q, Haskell. I need to define function encode and decode. Details about the functions are provided...
Q, Haskell. I need to define function encode and decode. Details about the functions are provided in code. -- | encode -- -- Given a string, return a list of encoded values of type (Int,Char) -- -- >>> encode ['a','a','a','a','b','c','c','a','a','d','e','e','e','e'] -- [(4,'a'),(1,'b'),(2,'c'),(2,'a'),(1,'d'),(4,'e')] -- -- >>> encode "hello" -- [(1,'h'),(1,'e'),(2,'l'),(1,'o')] -- -- >>> encode [] -- [] -- encode :: String -> [(Int,Char)] encode = undefined -- | decode -- -- Given a list of encoded values of type (Int,Char), generate...
Encode the following instruction (1) identify the instruction format that will be used (2) indicate the...
Encode the following instruction (1) identify the instruction format that will be used (2) indicate the values of each of the fields for that format in decimal (3) convert each of these decimal val- ues to binary (4) represent the entire instruction as one hexadecimal value j L2. # where L2 is at the decimal byte address 1,048,608
Encode the following instruction opcode: 100011 (1) identify the instruction format that will be used (2)...
Encode the following instruction opcode: 100011 (1) identify the instruction format that will be used (2) indicate the values of each of the fields for that format in decimal (3) convert each of these decimal values to binary (4) represent the entire instruction as one hexadecimal value. subu $t3,$v1,$s2
A significant issue faced by developers of any system is the size of the devices used...
A significant issue faced by developers of any system is the size of the devices used by their clients. Based on your understanding of the three-layer architecture, explain how developers can solve this issue. Describe the tests that are conducted during the deployment stage.
Describe the three basic methods for contructing a life table (2 main methods, one of which...
Describe the three basic methods for contructing a life table (2 main methods, one of which has 2 submethods). For each one explain how data are collected and entered into a life table. Identify a positive and negative aspect for each.
One of the main elements of the success of any project is the purchasing and supply...
One of the main elements of the success of any project is the purchasing and supply management of the project and the quality management of projects. Can you give a description of the role of each department in increasing project effectiveness and work efficiency? (Procurement Management for Projects) (Project Supply Management) (Project Quality Management)
Thanks in advance. In Java. I'm having an issue with one of my methods. Ex: The...
Thanks in advance. In Java. I'm having an issue with one of my methods. Ex: The array being pass in is a character array with element: w, ' ', K, Q, k, q, ' ', -, ' ', 0, ' ', 1 public class Find { public void enPassant(char[] array) {   for(int i = 0; i < array.length; ++i) { if(array[i] == 'e') { count = i; } else { count += 0; } }    if(count > 0) {...
1.What are the two main methods used to integrate external benefits into the provision of goods...
1.What are the two main methods used to integrate external benefits into the provision of goods and services? Select one: A. By providing normal goods or taxing producers. B. By taxing producers and consumers. C. By providing quasi-public goods or subsidizing producers. D. By providing quasi-public goods or taxing producers. 2 .Why does the market fail to produce public goods? Select one: A. Because such products usually entail large external costs. B. Because it is impossible for the producer to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT