Question

Language is java Create encryption and decryption that changes char by using ASCII by 5. How...

Language is java

Create encryption and decryption that changes char by using ASCII by 5. How to do this using threads?

Let’s assume that our password string is “ABCDEFGHI”, once you run the encrypt function on this string you should get - “FGHIJKLMN” (since you are increasing the ASCII value by 5)

If we call decrypt on this update string right away, it should give us the original string back - “ABCDEFGHI”

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class CaesarEncryption {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter your message:");
        String line = in.nextLine();
        System.out.println("\nEnter your shift cipher key:  ");
        int key = in.nextInt();
        char ch;

        String cipher = "";
        for (int i = 0; i < line.length(); i++) {
            ch = line.charAt(i);
            if(Character.isLowerCase(ch)) {
                ch = (char) ('a' + ((ch - 'a' + key + 26) % 26));
            } else if(Character.isUpperCase(ch)) {
                ch = (char) ('A' + ((ch - 'A' + key + 26) % 26));
            }
            cipher += ch;
        }
        System.out.println("\nEncrypted message:\n" + cipher);

        String plain = "";
        for (int i = 0; i < cipher.length(); i++) {
            ch = cipher.charAt(i);
            if(Character.isLowerCase(ch)) {
                ch = (char) ('a' + ((ch - 'a' - key + 26) % 26));
            } else if(Character.isUpperCase(ch)) {
                ch = (char) ('A' + ((ch - 'A' - key + 26) % 26));
            }
            plain += ch;
        }
        System.out.println("\nDecrypted message:\n" + plain);

        in.close();
    }
}

Add a comment
Know the answer?
Add Answer to:
Language is java Create encryption and decryption that changes char by using ASCII by 5. How...
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
  • Create a Caesar Cipher in Java. Should be able to support full ascii table (0 to...

    Create a Caesar Cipher in Java. Should be able to support full ascii table (0 to infinity) with all symbols, characters, etc. Using the Strings provided below, create an encryption and decryption method: String basicText = "TOX!QL<];`\z6 L"n2=qafDkdp*a'S d 'SkQLq~+Ct*{8Y"4 ZnMxS.9e..&%9" String password = "password1"

  • JAVA public static String generatePassword(String gp)        {            String password="";       ...

    JAVA public static String generatePassword(String gp)        {            String password="";            boolean b= false;            for (int i =0;i            {                char ch = gp.charAt(i);                if (i == 0)                {                    password += Character.toUpperCase(ch);                }                if (ch == 'S' || ch == 's')           ...

  • Creating a Vigenère Cipher Encryption/Decryption in Assembly Language NASM/YASM With these instructions so far we created...

    Creating a Vigenère Cipher Encryption/Decryption in Assembly Language NASM/YASM With these instructions so far we created some variables for the data and the outputs for them but are very confused on how to integrate the cipher portion so help would be appreciated. As seen in the picture below we are supposed to use a Vigenere cipher which uses key and plaintext variables in nasm/yasm assembly. The key is extended to the size of the text and then for each letter...

  • 1.     This project will extend Project 3 and move the encryption of a password to a...

    1.     This project will extend Project 3 and move the encryption of a password to a user designed class. The program will contain two files one called Encryption.java and the second called EncrytionTester.java. 2.     Generally for security reasons only the encrypted password is stored. This program will mimic that behavior as the clear text password will never be stored only the encrypted password. 3.     The Encryption class: (Additionally See UML Class Diagram) a.     Instance Variables                                                i.     Key – Integer...

  • Implement in Go language AES encryption mode CBC with providing the packages name for Go language....

    Implement in Go language AES encryption mode CBC with providing the packages name for Go language. You can implement AES-ECB Mode (the basic AES) from crypto/aes package and crypto/cipher.Block. You can also get the SHA-256 hash function from crypto/sha256. You can get the secure random numbers generator from crypto/rand package. However, the you will implement both CBC mode and HMAC from scratch. You are NOT allowed to use any libraries or packages to implement these two things for you. You...

  • 8.16 Ch 8, Part 1: XOR Cipher Write this program using Eclipse. Comment and style the...

    8.16 Ch 8, Part 1: XOR Cipher Write this program using Eclipse. Comment and style the code according to CS 200 Style Guide. Submit the source code files (.java) below. Make sure your source files are encoded in UTF-8. Some strange compiler errors are due to the text encoding not being correct. This program will implement a simple XOR cipher on an integer array, where the data to be encoded is XOR'd with a key. This idea is often used...

  • Needs to be done in C, The function shown can be called to reverse the char....

    Needs to be done in C, The function shown can be called to reverse the char. 7.5 Bit Encryption 7.5.1 Problem Given a single character, apply a simple bitwise encryption algorithm and return the cipher character. 7.5.2 Preconditions You must provide a series of functions which meet the requirements in the table below. You you may include other functions as long as the requested functions execute correctly. Do not include a main function in your source or header files. You...

  • 5. We must assume that keys are not secure forever, and will eventually be discovered; thus...

    5. We must assume that keys are not secure forever, and will eventually be discovered; thus keys should be changed periodically. Assume Alioe sets up a RSA cryptosystem and announces N = 3403, e = 11. (a) Encrypt m = 37 using Alice's system (b) At some point. Eve discovers Alice's decryption exponent is d = 1491. Verify this (by decrypting the encrypted value of rn = 37). (c) Alice changes her encryption key to e = 31, Encrypt rn...

  • 1. In this lab, you will create a simple encryption function that will require a sentence...

    1. In this lab, you will create a simple encryption function that will require a sentence and a key (both strings) as a parameter and return an encrypted version of the string. The encryption algorithm will use the exclusive OR operator (commonly abbreviated as XOR). The general structure of the encryption is that every position in the sentence is XOR'd with the accompanying position of the key. If the sentence is longer than the key, you repeat the key. For...

  • C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string usi...

    C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string using the RSA algorithm (C90 language only). It can contain ONLY the following libraries: stdio, stdlib, math and string. I want to use the following function prototypes to try and implement things: /*Check whether a given number is prime or not*/ int checkPrime(int n) /*to find gcd*/ int gcd(int a, int h) void Encrypt(); void Decrypt(); int getPublicKeys(); int getPrivateKeys();...

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