Write a simple program in Java or C, that will help you to
figure out the key used for Vigenère encrypted file.
For this exercise, assume the key length is less than five
characters long and only English upper case letters from A-Z are
used. You may also assume the plaintext contains only the upper
case English letters from A-Z, ignore the space characters.
Your program should take a ciphertext file (encrypted using the
Vigenère encryption algorithm) as input and produce an output file
where at the first line print the “key” used for the encryption,
followed by a decrypted plaintext in it.
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package vingenere;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
/**
*
* @author Gajendra
*/
public class Vingenere {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws
FileNotFoundException, IOException {
// TODO code application logic here
String inputFileName = "input.txt";;
if(args.length>0) {
inputFileName =args[0];
}
File file = new File(inputFileName);
FileInputStream fis = new FileInputStream(file);
byte[] data = new byte[(int) file.length()];
fis.read(data);
fis.close();
String inputText = new String(data, "UTF-8");
inputText =inputText.toUpperCase();
String key="";
System.out.println("Enter key (A-Z) max 5 characters :");
Scanner s = new Scanner(System.in);
key = s.nextLine();
key = key.toUpperCase();
String encryptedText =encrypt(inputText,key);
String outputFile ="output.txt";
file = new File(outputFile);
file.createNewFile();
//Write Content
FileWriter writer = new FileWriter(file);
writer.write("Key :"+key);
writer.write(System.lineSeparator());
writer.write("Encrypted Text :"+encryptedText);
writer.close();
}
private static String encrypt(String text, final String key)
{
String res = "";
text = text.toUpperCase();
for (int i = 0, j = 0; i < text.length(); i++)
{
char c = text.charAt(i);
if (c < 'A' || c > 'Z')
continue;
res += (char) ((c + key.charAt(j) - 2 * 'A') % 26 + 'A');
j = ++j % key.length();
}
return res;
}
}
output:
input file text:
ASDSGSDAG SAGASA GDSAAG AGSGDSGDSAGSDGADSGAHFDNFDNARA
ASGDASEGDGAFHAHAHA
output.txt
Key :WAWEWT
Encrypted Text
:WSZWCLZACWWZWSWKZLWACECLCDOKZLWGOHCTZSCEDYZNBHJTNAWWCWWSAKZZWFDEDTDA
Write a simple program in Java or C, that will help you to figure out the...
C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...
WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you will write functions to encrypt and decrypt messages using simple substitution ciphers. Your solution MUST include: a function called encode that takes two parameters: key, a 26-character long string that identifies the ciphertext mapping for each letter of the alphabet, in order; plaintext, a string of unspecified length that represents the message to be encoded. encode will return a string representing the ciphertext. a...
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...
Using Python; Caesar part of the homework: Write c_encrypt() and c_decrypt(), both of which take two arguments, the first one a string and the second one an integer key. Both should return a string. Vigenère part of the homework: Write vig_encrypt() and vig_decrypt() functions. Each takes two strings as inputs, with the first being the plaintext/ciphertext, and the second being the key. Both should be calling functions you wrote earlier to help make the work easier. The key will be...
in c++ The science of writing secret codes is called cryptography. For thousands of years cryptography has made secret messages that only the sender and recipient could read, even if someone captured the messenger and read the coded message. A secret code system is called a cipher. In cryptography, we call the message that we want to be secret the plaintext. The plaintext could look like this: Hello there! The keys to the house are hidden under the flower pot. Converting...
Write a short Java program that uses private key (symmetric) encryption method to encrypt a short string. Approximate algorithm: Enter a text string Use Java to generate a key and encrypt the string Use Java (and the key) to decrypt the string Compare original and decrypted string to make sure it is the same Note: Please make it as simple as possible
C++ program by netBeans
java language
Exercise #2: Write a java program that prompts the user to enter a sentence. The program has to find the print: a. the position of vowels in the sentence. b. the number of vowels in the sentence (A, a, U, u, E, e, 0, o, I, i) c. the number of characters as numbers or special characters (other than English letters a..z, A..Z). Hint: remember to ignore the spaces. Sample input-output: Enter the sentnse:...
Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D. Decryption Implement two decryption functions corresponding to the above ciphers. When decrypting ciphertext, ensure that the produced decrypted string is equal to the original plaintext: decryptCaesar(ciphertext, rshift) == plaintext decryptVigenere(ciphertext, keyword) == plaintext Write a program decryption.cpp that uses the above functions to demonstrate encryption and decryption for both ciphers. It should first ask the user to input plaintext, then ask for a right...
Please help me write this Java program. I had posted this question before, but got an answer that was totally wrong. We are using the latest version of Java8. Thank You! -------------------------------------------------------------------------------------- Write a Java program that can successfully DECRYPT a string inputted by the user which has been encrypted using a Caesar Cipher with a unknown shift value(key). You can use brute force to do a for loop through all the 26 shift values, however, your program should only...
1) Echo the input: First, you should make sure you can write a program and have it compile and run, take input and give output. So to start you should just echo the input. This means you should prompt the user for the plaintext, read it in and then print it back out, with a message such as "this is the plaintext you entered:". [4 points, for writing a working program, echoing the input and submitting the program on the...