A company wants to transmit data over the telephone, but it
is concerned that its phones may be tapped. All of its data
is transmitted as four-digit integers. It has asked you to
write a program that will encrypt its data so that the data
may be transmitted more securely. Your script should read a
four digit integer entered by the user in a prompt dialog
and encrypt it as follows: Replace each digit by (the sum
of that digit plus 7) modulus 10. Then swap the first digit
with the third, and swap the second digit with the fourth.
Then output XHTML text that displays the encrypted
integer.

Answers were Sorted based on User's Feedback



A company wants to transmit data over the telephone, but it is concerned that its phones may be ta..

Answer / hafiz waqas

import java.util.Scanner;


public class Main {


public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner myScanner=new Scanner(System.in);

boolean flag = true; //check value is 4 digit or not..
int beforeIncryption = 0;//take plain text
int temp; // for processing plain text
int incryptValue; // for storing after encryption process

//Check value is 4 digit or not
while(flag){
System.out.println("Please Enter exactly 4 digit enteger ");
beforeIncryption = myScanner.nextInt();

if( beforeIncryption-1000 >= 0 && beforeIncryption-1000
<= 8999)
flag=false;
}
temp = beforeIncryption;

int v1 , v2 , v3,v4;// v1 contain 1st digit,v2 contain 2nd
digit and so on...

//take separate digit and apply encryption process
v4=temp%10;
v4+=7;
v4%=10;

temp/=10;

v3=temp%10;
v3+=7;
v3%=10;

temp/=10;

v2=temp%10;
v2+=7;
v2%=10;

temp/=10;

v1=temp%10;
v1+=7;
v1%=10;

//swapping values 1st digit with 3rd digit and 2nd with
4th....
temp=v1;
v1=v3;
v3=temp;

temp=v2;
v2=v4;
v4=temp;


incryptValue = v1*1000 + v2*100 + v3*10 + v4*1;// combine
4 separate digit into 1 number
System.out.println("Encrypted data is
"+incryptValue);//display encryption result


//Program for decryption........

int myIncrypt;//take encrypted input from user
System.out.println("Enter encrypted data ");//prompt for user
myIncrypt=myScanner.nextInt();//take value for apply
decryption process

int dv1,dv2,dv3,dv4,decryptValue;

//separate 1 four digit number into 4 separate 1 digit number
dv4=myIncrypt%10;
myIncrypt/=10;

dv3=myIncrypt%10;
myIncrypt/=10;

dv2=myIncrypt%10;
myIncrypt/=10;

dv1=myIncrypt%10;
myIncrypt/=10;

//swap values
temp=dv1;
dv1=dv3;
dv3=temp;

temp=dv2;
dv2=dv4;
dv4=temp;

//apply decryption process
dv1+=10;
dv1-=7;
dv1%=10;

dv2+=10;
dv2-=7;
dv2%=10;

dv3+=10;
dv3-=7;
dv3%=10;

dv4+=10;
dv4-=7;
dv4%=10;

//combine result
decryptValue=dv1*1000+dv2*100+dv3*10+dv4*1;
//display result
System.out.println("decrypted data is"+decryptValue);

}

}

Is This Answer Correct ?    25 Yes 15 No

A company wants to transmit data over the telephone, but it is concerned that its phones may be ta..

Answer / ferial hattar

#include<iostream.h>
void main()
{
int n,a,b,c,d,e,f,g,h,i,j;

cout<<"enter 4 number digit";
cin>>n;

a=n%10;

b=n/10;

c=b%10;

d=b/10;

e=d%10;

f=d/10;


g=((a+a)+7)%10;

h=((c+c)+7)%10;

i=((e+e)+7)%10;

j=((f+f)+7)%10;


cout<<i<<g<<j<<h;

}

Is This Answer Correct ?    11 Yes 28 No

Post New Answer

More Engineering AllOther Interview Questions

what are differences b/w EIA 449 and EIA 530?

0 Answers  


my first question in huawei was ....1)Tell me about your self 2) oops concept 3)logic gates 4)ram and rom ,what is cache memory nd where it is located 5)diffrence between file system and data base 6) procedure of operating system 7)what is c# 8)high level language and machine language 9) and from mobile networkin !!!! hope thz will help you

0 Answers   Huawei,


Describe an impedance matching circuit?

2 Answers  


The graph K3,4 has how many edges. Options:- 3,4,7,12

5 Answers  


what is the differences between DTD's and XML schema?

0 Answers  






who are egoless programmers?

0 Answers  


I am about to face the interview panel of Indian army for UES(for more details put this address http://www.freshershome.com/jobs/index.php?post_id=15715) This is basically a post for engineering job in Indian army? This is an on campus interview. Kindly help me out with some tips or the type of questions I am about to face. Thanks.

5 Answers   Indian Army, Indian Military Services, Infosys, Military Engineer Services, UES,


how u send idocs with out using r.f.c interface

0 Answers   HCL,


what is static identifier in c language?

0 Answers  


Hi All... PLease send me if anyone have "Information Security Officer" Aptitude papers. Please Mail me at mannusanghi@gmail.com

0 Answers  


How I can write a java program output the following 1+2+4+7+......N

0 Answers  


Q1. A. Discuss the various types of variables. B. How to control the file? Q2. A. How the image application? B. Write short notes on trees structures work. Q3. A. How to load and unload child forms. B. When should we use recursive programming Q4. A. Write short notes on “The ole control’s shortcut menu” B. How to test the AX stat class Q5. A. How to use advanced data-bound controls. B. Write notes on manipulating the recordset object Q6. A. What is script control? B. How to down load image properties. C. What is meant by building a recordset.

0 Answers   IBM,


Categories
  • Civil Engineering Interview Questions Civil Engineering (5085)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4452)
  • Electrical Engineering Interview Questions Electrical Engineering (16638)
  • Electronics Communications Interview Questions Electronics Communications (3918)
  • Chemical Engineering Interview Questions Chemical Engineering (1095)
  • Aeronautical Engineering Interview Questions Aeronautical Engineering (239)
  • Bio Engineering Interview Questions Bio Engineering (96)
  • Metallurgy Interview Questions Metallurgy (361)
  • Industrial Engineering Interview Questions Industrial Engineering (259)
  • Instrumentation Interview Questions Instrumentation (3014)
  • Automobile Engineering Interview Questions Automobile Engineering (332)
  • Mechatronics Engineering Interview Questions Mechatronics Engineering (97)
  • Marine Engineering Interview Questions Marine Engineering (124)
  • Power Plant Engineering Interview Questions Power Plant Engineering (172)
  • Textile Engineering Interview Questions Textile Engineering (575)
  • Production Engineering Interview Questions Production Engineering (25)
  • Satellite Systems Engineering Interview Questions Satellite Systems Engineering (106)
  • Engineering AllOther Interview Questions Engineering AllOther (1379)