1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
velikii [3]
3 years ago
6

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 tran

smitted more securely. All the data is transmitted as four-digit integers. Your app 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 display the encrypted integer. Write a separate app that inputs an encrypted four-digit integer and decrypts it (by reversing the encryption scheme) to form the original number. Use the format specifier D4 to display the encrypted value in case the number starts with a 0
Computers and Technology
1 answer:
elixir [45]3 years ago
4 0

Answer:

The output of the code:

Enter a 4 digit integer : 1 2 3 4

The decrypted number is : 0 1 8 9

The original number is : 1 2 3 4

Explanation:

Okay, the code will be written in Java(programming language) and the file must be saved as "Encryption.java."

Here is the code, you can just copy and paste the code;

import java.util.Scanner;

public class Encryption {

public static String encrypt(String number) {

int arr[] = new int[4];

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

char ch = number.charAt(i);

arr[i] = Character.getNumericValue(ch);

}

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

int temp = arr[i] ;

temp += 7 ;

temp = temp % 10 ;

arr[i] = temp ;

}

int temp = arr[0];

arr[0] = arr[2];

arr[2]= temp ;

temp = arr[1];

arr[1] =arr[3];

arr[3] = temp ;

int newNumber = 0 ;

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

newNumber = newNumber * 10 + arr[i];

String output = Integer.toString(newNumber);

if(arr[0]==0)

output = "0"+output;

return output;

}

public static String decrypt(String number) {

int arr[] = new int[4];

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

char ch = number.charAt(i);

arr[i] = Character.getNumericValue(ch);

}

int temp = arr[0];

arr[0]=arr[2];

arr[2]=temp;

temp = arr[1];

arr[1]=arr[3];

arr[3]=temp;

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

int digit = arr[i];

switch(digit) {

case 0:

arr[i] = 3;

break;

case 1:

arr[i] = 4;

break;

case 2:

arr[i] = 5;

break;

case 3:

arr[i] = 6;

break;

case 4:

arr[i] = 7;

break;

case 5:

arr[i] = 8;

break;

case 6:

arr[i] = 9;

break;

case 7:

arr[i] = 0;

break;

case 8:

arr[i] = 1;

break;

case 9:

arr[i] = 2;

break;

}

}

int newNumber = 0 ;

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

newNumber = newNumber * 10 + arr[i];

String output = Integer.toString(newNumber);

if(arr[0]==0)

output = "0"+output;

return output;

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter a 4 digit integer:");

String number = sc.nextLine();

String encryptedNumber = encrypt(number);

System.out.println("The decrypted number is:"+encryptedNumber);

System.out.println("The original number is:"+decrypt(encryptedNumber));

}

}

You might be interested in
Write a complete program that declares an integer variable, reads a value from the keyboard into that variable, and writes to st
NNADVOKAT [17]
The programming language to use here is not stated, so standard output is not clear. A solution using text boxes for input and output can be given in Delphi:

unit Unit2;
interface
uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;
type  TForm2 = class(TForm)   
Edit1: TEdit;   
Edit2: TEdit;   

procedure FormCreate(Sender: TObject); 
private    { Private declarations } 
public    { Public declarations } 
end;
var  Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormCreate(Sender: TObject);
var   i: integer;   
txtline: string;
begin   
    i := StrToInt(edit1.text);   
    txtline := IntToStr(i) + ', ' + IntToStr(2 * i) + ', ' + IntToStr(i * i);   edit2.text := txtline;
end;
end.


6 0
3 years ago
All windows on the desktop have width and height (as well as numerous other attributes). However the actual contents of the wind
Cerrena [4.2K]

Answer:

The abstract class Window:

public abstract class Window

Two integer instance variables, width and height:

private int width, height;

Two accessor methods, getWidth and getHeight:

public int getWidth()

public int getHeight()

A constructor that accepts two integers and uses them to initialize the two instance variables:

public Window(int var1, int var2) {width =var1; height = var2;}

An abstract void-returning method named paint that accepts no parameters

public abstract void paint();

Explanation:

Abstract keyword is used with Windows class to make this class an abstract class which means no object can be created using this class.

Two private instance variable width and height. Private means they are not accessible outside this class.

Then getWidth and getHeight methods are used to return width and height.

The constructor takes two integer type variables var1 and var2. These two variable are used to initialize the variables width and height. Constructor has the same name as that of the class.

Method paint() is an abstract method with the return type void which has no parameters.  

So here is what the class with all its methods and instance variables looks.

public abstract class Window {

private int width, height;

public Window(int a, int b) {width = a; height = b;}

public int getWidth(){ return width; }

public int getHeight(){ return height; }

public abstract void paint();

}

6 0
3 years ago
What would you use to exit from a for each activity and continue the execution of the workflow?
mr_godi [17]

Answer:

Break activity

Explanation:

The Break activity simply allows a user to stop the loop at any point chosen, and then continue with another activity or the next activity.

4 0
3 years ago
Hi Guys,
Bingel [31]

Answer:

Please check the attachment.

Explanation:

Please check the attachment.

Download docx
8 0
4 years ago
How to reset windows 7 password without logging in
hammer [34]

Explanation:

<em>.</em><em>Reboot your laptop or PC. </em>

<em>Select the Repair your Computer option and press Enter. </em>

<em>The System Recovery Options window will popup, click System Restore, it will check the data in your Restore Partition and factory reset laptop without password.</em>

4 0
3 years ago
Read 2 more answers
Other questions:
  • Ideation includes all of the following EXCEPT
    5·1 answer
  • Why is it important to use standard english when applying for a job
    13·2 answers
  • You support Richman Investments, a brokerage firm that employs 20 brokers. Each broker has his own client computer, and the firm
    15·1 answer
  • Siva added a Contact Form to her website. This is used for the collection to be included in
    5·1 answer
  • GUI stands for "___ user interface."
    9·2 answers
  • What did I do wrong? May you please correct it for me...I was also looking on how to delay when it prints. Like when it prints a
    9·1 answer
  • Marilyn needs help exporting her spreadsheet as a few different types of files. She needs to know exactly how her file should be
    11·1 answer
  • What is a piece of information sent to a function
    15·1 answer
  • tls Explain in your own words how, by applying both asymmetric and symmetric encryption, your browser uses TLS to protect the pr
    8·1 answer
  • How wow low sow mow tow row fow
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!