Question

Write a java code that will Implement Simple Substitution cipher with permutations and Implement Letter Frequency...

Write a java code that will Implement Simple Substitution cipher with permutations and Implement Letter Frequency Analysis. As well as Apply Letter Frequency Analysis to chosen outputs of your Simple Substitution encryption.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code to write simple substitution,

class substitution

{ public static StringBuffer encrypt(String text, int s)

    { StringBuffer result= new StringBuffer();

        for (int i=0; i<text.length(); i++)

        { if (Character.isUpperCase(text.charAt(i))) // since we are using the ASCII we need all of the word to be same case for the conversation so we'll do small and upper one by one

            {

char ch = (char)(((int)text.charAt(i) +s - 65) % 26 + 65);

                result.append(ch); // this is actually converting the acsii and then adding the position and them getting the character corresponding to that and replacing that in the result at the end.

            }else {

char ch = (char)(((int)text.charAt(i) + s - 97) % 26 + 97);

                result.append(ch); } }

        return result;

    }

Now we just have to call the function with the input and the number of places we want to shift this so if we need a simple substitution then the number of places will be same for each character, where as if you say as per the question you need a particular permuting then you can use the value of N from a array just make that edit, but simple substitution cipher does have only 1 value for n and not a variable so

String text = "put the plain text here";

int s = 4;

System.out.println("Cipher: " + encrypt(text, s));

Now the time to make a frequency for all the characters,

int n = str.length();

int[] freq = new int[26];

// we make table for frequency

for (int i = 0; i < n; i++)

freq[str.charAt(i) - 'a']++;

//Above we took the character and then subtracted the 'a' so that the number left is the index of frequency count of that character and we increased it by ++

Now it's upto the analysis posting who they want to take care of the crypto Analysis part, which means that we can just look at the frequency of characters and say the most frequently used is e and then make out the words like "the" or "is" as the most frequently coming three and two character words and like that but that all depends on the strategy we follow

for (int i = 0; i < n; i++) {

  if (freq[str.charAt(i) - 'a'] != 0) {

  System.out.print(str.charAt(i));

  System.out.print(freq[str.charAt(i) - 'a'] + " ");}

This will print the character and there frequency to visualise

Add a comment
Know the answer?
Add Answer to:
Write a java code that will Implement Simple Substitution cipher with permutations and Implement Letter Frequency...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text an...

    I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text and key My Current Code is: void SubDecrypt(char *message, char *encryptKey) { int iteration; int iteration_Num_Two = 0; int letter; printf("Enter Encryption Key: \n");                                                           //Display the message to enter encryption key scanf("%s", encryptKey);                                                                   //Input the Encryption key for (iteration = 0; message[iteration] != '0'; iteration++)                               //loop will continue till message reaches to end { letter = message[iteration];                                                      ...

  • The given plaintext is “Feistel cipher structure uses the same algorithm for both encryption and decryption”....

    The given plaintext is “Feistel cipher structure uses the same algorithm for both encryption and decryption”. Write Java code to implement Shift cipher (Encryption and Decryption) and test your code on given plaintext. Your code must meet following conditions. 1. User must enter the value of key from command prompt and print it at command prompt. 2. Print the cipher text and the plaintext at the command prompt after encryption and decryption. 3. Test your algorithm for 5 different key...

  • In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or...

    In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. Given an arbitrary cipher text file, you need to write a C++ program to find out the value of the shift, and decrypt the...

  • Write the following cipher in java: Playfair And detail your code with comments of what each...

    Write the following cipher in java: Playfair And detail your code with comments of what each block of code does...

  • Write a java program that takes the following phrases and encrypts them using a substitution cipher....

    Write a java program that takes the following phrases and encrypts them using a substitution cipher. The program should ask for a key and a phrase and then proceed to encrypt that phrase using the given shared key. Make sure that you have the key for the cipher and the output of encrypted phrases. Encrypt the phrase: He who fights with monsters should look to it that he himself does not become a monster. And if you gaze long into...

  • C PROGRAMMING Implement a function (using only #include library) that can encrypt/decrypt with a substitution cipher....

    C PROGRAMMING Implement a function (using only #include library) that can encrypt/decrypt with a substitution cipher. cipher_sub (a, b, c, d) a is the string that has the data that will be encrypted or decrypted b is the string that has the result of the encrypt/decrypt c is the code string used for our substitution cipher (27 entries plus '\0' character) d is an integer that will pass two constants defined as ENC (encrypt) or DEC (decrypt) --> The function...

  • Caesar Cipher v3 Decription Description A Caesar cipher is one of the first and most simple...

    Caesar Cipher v3 Decription Description A Caesar cipher is one of the first and most simple encryption methods. It works by shifting all letters in the original message (plaintext) by a certain fixed amount (the amounts represents the encryption key). The resulting encoded text is called ciphertext. Example Key (Shift): 3 Plaintext: Abc Ciphertext: Def Task Your goal is to implement a Caesar cipher program that receives the key and an encrypted paragraph (with uppercase and lowercase letters, punctuations, and...

  • . Please write a function that will do the following Decryption of a message encrypted with a substitution cipher given cipher text only without any key Please provide comments on each line of code ou...

    . Please write a function that will do the following Decryption of a message encrypted with a substitution cipher given cipher text only without any key Please provide comments on each line of code outlining what that line is doing. Note: Only the Function is to be written, all user inputs i.e the text to be decrypted will be entered earlier in the program. Code must be written in C and be able to be compiled using GCC If any...

  • help please! due tomorrow! Write code in Java Write a program that takes as input an...

    help please! due tomorrow! Write code in Java Write a program that takes as input an unordered list of integers, creates a Btree of minimum degree t 4 and then outputs the sorted list of integers. A simple inorder traversal of the B tree will output the list of the integers in a increasing order. You can choose your programming language and the platform you run on. The documentation is required for any programming assignment.

  • Write a javascript program which implements the following two classical cryptosystem which we covered in class:...

    Write a javascript program which implements the following two classical cryptosystem which we covered in class: Affine Cipher Vigenere Cipher Your program should consist of at least five functions: Two functions named encrypt, one for each of the two algorithms which accepts a lowercase alphabetical plaintext string and key as input and outputs a corresponding cipher text string. Two functions named decrypt, one for each of the two algorithms which accepts a lowercase alphabetical ciphertext string and a key as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT