Question

A company that wants to send data over the Internet has asked you to write a...

A company that wants to send data over the Internet has asked you to write a program that will encrypt it so that it may be transmitted more securely. All the data is transmitted as four-digit integers. Your application should read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the first digit with the third, and swap the second digit with the fourth. Then print the encrypted integer. Write a separate application that inputs an encrypted four-digit integer and decrypts it (by reversing the encryption scheme) to form the original number.

Java version!

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

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

import java.util.Scanner;
public class Test{

public static int encrypt( int n)
{
   // obtain digits of number
   int a = n / 1000;
   int b = (n % 1000) / 100;
   int c = (n % 100) / 10;
   int d = n % 10;
   // Replace each digit with the result of adding 7 to the digit and getting
   // the remainder after dividing the new value by 10.
   a = (a + 7) % 10;
   b = (b + 7) % 10;
   c = (c + 7) % 10;
   d = (d + 7) % 10;
   return (c * 1000 + d * 100 + a * 10 + b); // swap a-c and b-d; generate result number
}

public static int decrypt( int n)
{
   // obtain digits of number
   int a = n / 1000;
   int b = (n % 1000) / 100;
   int c = (n % 100) / 10;
   int d = n % 10;
   // Replace each digit with the result of substract 7 to the digit and getting
   // the remainder after dividing the new value by 10.
   a = (a + 3) % 10;
   b = (b + 3) % 10;
   c = (c + 3) % 10;
   d = (d + 3) % 10;
   return (c * 1000 + d * 100 + a * 10 + b);
}


public static void main(String []args){
Scanner sc=new Scanner(System.in);
    int n;
   System.out.println("Enter four-digit number: ");
   n=sc.nextInt();
   System.out.println("Encrypted number is: "+encrypt(n));
   System.out.println("Number after encrypt-decrypt cycle is: "+decrypt(encrypt(n)));
}
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
A company that wants to send data over the Internet has asked you to write a...
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
  • This is to be written in C++. Thank you so much for you help as I'm...

    This is to be written in C++. Thank you so much for you help as I'm really struggling with this. Must be written in this format: #include <stdio.h> int main(void) { printf("Hello World\n"); return 0; } The explosive growth of Internet communications and data storage on Internet-connected computers has greatly increased privacy concerns. The field of cryptography is concerned with coding data to make it difficult (and hopefully—with the most advanced schemes—impossible) for unauthorized users to read. In this exercise,...

  • 8. A company would like to encrypt a token that it uses to identify data. The...

    8. A company would like to encrypt a token that it uses to identify data. The token is a four digit integer. The encryption method is as follows- replace each digit with the result of adding 7 to the digit and getting the remainder by dividing the resulting value by 10. Write a method that will return the answer as a new four digit integer. Now, writea method that will DECRYPT the integer token you just created back to your...

  • Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA...

    Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA {    private BigInteger phi; private BigInteger e; private BigInteger d; private BigInteger num; public static void main(String[] args) {    Scanner keyboard = new Scanner(System.in); System.out.println("Enter the message you would like to encode, using any ASCII characters: "); String input = keyboard.nextLine(); int[] ASCIIvalues = new int[input.length()]; for (int i = 0; i < input.length(); i++) { ASCIIvalues[i] = input.charAt(i); } String ASCIInumbers...

  • in java PART ONE ================================================== Write a program that will read employee earnings data from an...

    in java PART ONE ================================================== Write a program that will read employee earnings data from an external file and then sort and display that data. Copy and paste the input file data below into an external file, which your program will then read. You will want to use parallel arrays for this program. Modify the select sort algorithm to receive both arrays as parameters as well as the size of the arrays. Use the algorithm to sort your earnings array....

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

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