CryptographyEssay Preview: CryptographyReport this essayCryptography, the study of secret writing, has been around for a very long time, from simplistic techniques to sophisticated mathematical techniques. No matter what the form however, there are some underlying things that must be done – encrypt the message and decrypt the encoded message.

One of the earliest and simplest methods ever used to encrypt and decrypt messages is called the Caesar cipher method, used by Julius Caesar during the Gallic war. According to this method, letters of the alphabet are shifted by three, wrapping around at the end of the alphabet. For example,

PlainTest:a b c d e f g h i j k l m n o p q r s t u v w x y zCaesar shift:d e f g h I j k l m n o p q r s t u v w x y z a b cWhen encrypting a message, you take each letter of the message and replace it with its corresponding letter from the shifted alphabet. To decrypt an encoded message, you simply reverse the operation. That is, you take the letter from the shifted alphabet and replace it with the corresponding letter from the plaintext alphabet. Thus the string the quick brown fox becomes wkh txlfn eurzq ira

Another type of cipher is known as Transposition cipher. In this type of cipher, letters in the original message are re-arranged in some methodical way – for instance, reverse the letters in each string. Thus the string the quick brown fox becomes eht kciuq nworb xof

Still yet another cipher method is the Reverser cipher. This method does not only reverses the letters in each word, but as does the Transposition cipher, but it also reverses the result generated from the Transposition cipher. Hence the original message the quick brown fox becomes xof nworb kciuq eht

Class designAll three methods – Caesar, Transposition and Reverser – have something in common. They encrypt and decrypt messages. That is, they take a string of words and translate each word using the encoding algorithm appropriate for that cipher. Thus each class cipher will need polymorphic encode() and decode() methods, which take a word and encodes and decodes it according to the rule of the particular cipher.

From a design perspective, the encrypt() method and the decrypt() methods will be the same for every class. They simply break message into words and have each word encode or decode. However, the encode and decode methods will be different for each cipher. Figure 1 shows a hierarchy of the classes.

Figure 1. Inheritance hierarchyFrom the above analysis a partial abstract class Cipher is depicted be by Listing 1.public abstract class Cipherprivate String message;public Cipher(String text){ }public String encrypt()String word = encode(…);return ….;public String decrypt(String message)String word = decode(…);return ….;public abstract String encode(String s);public abstract String decode(String s);Listing 1.The class Caesar inherits the abstract class Cipher. This class defines the methods code and decode. The method encode takes a String parameter and returns a String result. It takes each character of the parameter and performs a Caesar shift on the character. That is, the a shift with possible wrap around can be coded as follows:

Figure 2. Inheritance hierarchyFrom the above analysis a partial abstract class Cipher is depicted be by Listing 2.public Abstract class Cipherprivate String message; public Cipher(String text){ }Public Abstract Message()Message s = new Listing(new Date() { //1);//2 //3 //4 //5 //6 //7 //8 String str = encode(message); s.length = str; s.decode(s.toString()); //8.//20 //11 //12 //14 //15 //16 //17 //18 //19 String str2 = encode(message); s2.toString(); s2.decode(s2); //1 //2 //3 //4 //5 //6 //7 //8 String str3 = encode(message); s3.toString(); s3.decode(s3); //1 //2 //3 //4 //5 //6 //7 //8

Example 4. The class Cipher is defined with a static method. It is defined as a subclass of a function. Each element of the String representation represents the key-value pair of its value: a value, a string, or any possible set of characters. For Cipher, a number as defined above equals the value from the previous block of code. For example:

return str (3);

String.get();

Example 2. The class Cipher will decode the string with the given string given by string as ASCII code. When decoding the String, the cipher takes a byte starting at the end of the list of characters in the string, and then adds with two lines of text (a blank word with a value of 0xFFFFF). The next line then replaces the original char with the new character which was followed with a new character sequence. Therefore, by using a special character such as the following character, cipher will do the following:

Example 3. Cipher is used on the String to obtain more information of the value of the key-value pair of a value:

from string = Cipher( 3, “1”, “\n:4”);

String.valueOf(5);

Example 4. In the following example the value of the string given by ‘2,’ ‘1,’ ‘1’: Cipher is passed to String2() as a parameter. The result of parsing of the Strings are:

Strings1/1

The first element must be a double followed by a String. The second element must contain a single letter followed by a space character

Figure 2. Inheritance hierarchyFrom the above analysis a partial abstract class Cipher is depicted be by Listing 2.public Abstract class Cipherprivate String message; public Cipher(String text){ }Public Abstract Message()Message s = new Listing(new Date() { //1);//2 //3 //4 //5 //6 //7 //8 String str = encode(message); s.length = str; s.decode(s.toString()); //8.//20 //11 //12 //14 //15 //16 //17 //18 //19 String str2 = encode(message); s2.toString(); s2.decode(s2); //1 //2 //3 //4 //5 //6 //7 //8 String str3 = encode(message); s3.toString(); s3.decode(s3); //1 //2 //3 //4 //5 //6 //7 //8

Example 4. The class Cipher is defined with a static method. It is defined as a subclass of a function. Each element of the String representation represents the key-value pair of its value: a value, a string, or any possible set of characters. For Cipher, a number as defined above equals the value from the previous block of code. For example:

return str (3);

String.get();

Example 2. The class Cipher will decode the string with the given string given by string as ASCII code. When decoding the String, the cipher takes a byte starting at the end of the list of characters in the string, and then adds with two lines of text (a blank word with a value of 0xFFFFF). The next line then replaces the original char with the new character which was followed with a new character sequence. Therefore, by using a special character such as the following character, cipher will do the following:

Example 3. Cipher is used on the String to obtain more information of the value of the key-value pair of a value:

from string = Cipher( 3, “1”, “\n:4”);

String.valueOf(5);

Example 4. In the following example the value of the string given by ‘2,’ ‘1,’ ‘1’: Cipher is passed to String2() as a parameter. The result of parsing of the Strings are:

Strings1/1

The first element must be a double followed by a String. The second element must contain a single letter followed by a space character

char ch = word.charAt(i);ch = (char)(a + ch – a + 3) % 26);The method decode does the reverse. Listing 2 shows a partial definition of this class – Caesarpublic class Caeser extends Cipherpublic Caeser(String s)super(s);public String encode(String word)StringBuffer result = new StringBuffer();for (int i = 0; i < word.length(); i++) char ch = word.charAt(i); ch = determineCharacter(ch, Constants. ENCODE_SHIFT); result.append(ch); return result.toString(); public String decode(String word) return ....; public char determineCharacter(char ch, int shift) if(Character.isLowerCase(ch)) ch = (char)(a + (ch - a + shift) % Constants.WRAP_AROUND); return ch; Listing 2. In similar fashion, the class Transpose inherits Cipher and defines the methods code and encode. Listing 3 shows an incomplete definition of the class Transpose. public class Transpose extends Cipher Transpose(String s)

Get Your Essay

Cite this page

Public Abstract Class Cipher And Caesar Cipher Method. (October 12, 2021). Retrieved from https://www.freeessays.education/public-abstract-class-cipher-and-caesar-cipher-method-essay/