Your App Should Read a Four Digit Integer With the Third and Swap the Second Digit With the Forth

#1

  • New D.I.C Head

Reputation: 0

  • View blog
  • Posts: 2
  • Joined: 06-December nineteen

Encryption and Decryption on 4-digits integer

Posted 06 December 2019 - 10:35 PM

So this is my question,
/*
(Cryptography) A company wants to transmit data over the telephone,
but is concerned that its phones could be tapped.
All of the data are transmitted as four-digit integers.
The company has asked you to write a plan that encrypts
the data then that it tin can exist transmitted more securely.
Your program should read a 4-digit integer and encrypt it as follows:

Replace each digit by (the sum of that digit plus 7) modulus 10.
Then, swap the beginning digit with the third,
swap the second digit with the fourth and impress the encrypted integer.
*/

my lecturer said to include decryption too, i did only i simply get the value after encrypt and decrypt. Can anyone help me on how to bandy the kickoff digit with the 3rd and sec digit with the forth?

so this is my coding;

#include<stdio.h> #include<math.h> int main(void) {     //encryrption:      int num,num1,i,eastward=0,d=0;     int choice;     printf("enter 4 digit number:\due north");     scanf("%d",&num);     num1=num;          printf( "enter (1) to encrypt (2) to decrypt\n");     scanf( "%d", &option); 	 	if  ( selection == 1 )  	{ 		//encryption:     	for(i=3;i>=0;i--) 		{         	num1=(num)/(pow(10,i));         	num1=(num1+7)%x;         	east=(x*e)+num1;    		}     		printf("encryption = %d\n",east); 	} 	else 	{      	//decryption:     	for(i=iii;i>=0;i--)    		{        		 num1=e/pow(ten,i);        		 num1=((num1-seven)%10);         	d=(x*d)+num1; 		}	     	        printf("decryption = %d",d); 	} 	     render 0; }            

:code:

View Posttasyajas, on 06 December 2019 - 10:31 PM, said:

So this is my question,
/*
(Cryptography) A company wants to transmit data over the phone,
but is concerned that its phones could exist tapped.
All of the data are transmitted equally four-digit integers.
The visitor has asked you to write a program that encrypts
the information so that it tin can be transmitted more deeply.
Your programme should read a 4-digit integer and encrypt it as follows:

Supervene upon each digit by (the sum of that digit plus 7) modulus 10.
Then, swap the first digit with the 3rd,
swap the 2nd digit with the 4th and impress the encrypted integer.
*/

my lecturer said to include decryption too, i did but i only go the value after encrypt and decrypt. Can anyone help me on how to swap the beginning digit with the tertiary and sec digit with the forth?

so this is my coding;

#include<stdio.h>
#include<math.h>
int main(void)
{
//encryrption:

int num,num1,i,e=0,d=0;
int selection;
printf("enter 4 digit number:\n");
scanf("%d",&num);
num1=num;

printf( "enter (1) to encrypt (2) to decrypt\n");
scanf( "%d", &option);

if ( choice == 1 )
{
//encryption:
for(i=three;i>=0;i--)
{
num1=(num)/(pw(10,i));
num1=(num1+vii)%10;
e=(10*e)+num1;
}
printf("encryption = %d\n",e);
}
else
{

//decryption:
for(i=3;i>=0;i--)
{
num1=e/prisoner of war(10,i);
num1=((num1-7)%10);
d=(ten*d)+num1;
}
printf("decryption = %d",d);
}

render 0;
}

i also did another coding which i can swap those digits just it is a elementary coding and my lecturer wants me to inlcude array/looping T.T aaaaaa help me
this is my coding;

#include <stdio.h> #include<math.h> int main(void) { 	//obtain digits of number 	 	int encrypted, decrypted; 	int i, option, value; 	int data, encpData, decpData; 	int digit1, digit2, digit3, digit4; 	 	printf( "enter (ane) to encrypt (ii) to decrypt\n"); 	scanf( "%d", &choice); 	 	if  ( choice == 1 )  	{ 	printf ("Enter 4-digit integer to be encrypted: "); 	scanf ("%d", &data); 	 	// Replace each digit with the result of adding vii to the digit and getting 	// the residuum after dividing the new value by 10 	 	for(i=three;i>=0;i--) 	 	encpData = value = data; 	digit1 = (value/(pow(10,i))+7)%ten;  	value = value%1000; 	digit2 = (value/100+seven)%ten;  	value = value%100; 	digit3 = (value/x+seven)%10;  	value = value%10; 	digit4 = (value+seven)%ten;  	 	encrypted = digit3*1000+digit4*100+digit1*10+digit2; //bandy digit1-digit3 and digit2-digit4; generate consequence number 	printf("Encrypted value is %d", encrypted); 	}		 		 	else 	{ 	printf ("Enter 4-digit integer to exist decrypted: "); 	scanf ("%d", &data);  	decpData = value = data; 	digit1 = (value/1000+ten)-7;  	value = value%1000; 	digit2 = (value/100+ten)-7;  	value = value%100; 	digit3 = (value/10+10)-seven;  	value = value%10; 	digit4 = (value+ten)-7; 	 	decrypted = digit3*1000+digit4*100+digit1*10+digit2; //swap digit1-digit3 and digit2-digit4; generate result number 	printf("Decrypted value is %d", decrypted); 	} 	 	render 0; 	 }            

:code:

This post has been edited by modi123_1: 07 December 2019 - 05:29 AM
Reason for edit:: In the future delight utilize the [lawmaking] tag push button in the editor


Is This A Good Question/Topic? 0

  • +

#2 modi123_1 User is online

Reputation: 16484

  • View blog
  • Posts: 65,358
  • Joined: 12-June 08

Re: Encryption and Decryption on 4-digits integer

Posted 07 Dec 2019 - 06:07 AM

Your second looks heavily lifted from here:
https://www.dreaminc...asic-c-program/

.. and it doesn't work just visually - say in that for loop.

#3 Skydiver User is offline

Reputation: 7916

  • View blog
  • Posts: 26,433
  • Joined: 05-May 12

Re: Encryption and Decryption on four-digits integer

Posted 07 Dec 2019 - 07:17 AM

Plagiarists never turn a profit unless your company proper noun is "Apple"...

#4 modi123_1 User is online

Reputation: 16484

  • View blog
  • Posts: 65,358
  • Joined: 12-June 08

Re: Encryption and Decryption on iv-digits integer

Posted 07 December 2019 - x:09 AM

Indeed.. reminds me of a saying I used to say a lot.. "Plagiarists never profit unless your company proper noun is 'Apple tree'".

https://i.imgur.com/5RQ4g20.jpg

:D

#v Salem_c User is online

Reputation: 2555

  • View blog
  • Posts: 4,742
  • Joined: 30-May 10

Re: Encryption and Decryption on four-digits integer

Posted 07 December 2019 - 02:38 PM

@ tasyajas

Kickoff small, compile ofttimes, test all the time.

Begin past putting your requirements into the lawmaking as comments.

#include <stdio.h> #include <stdlib.h> #include <string.h>  int main ( ) {   // read a 4-digit integer and encrypt it as follows:   // TODO: use a fixed number for initial testing   int num = 1234;   int digits[4] = { 0 };    // 1. Separate num into digits    // 2. Replace each digit by (the sum of that digit plus seven) modulus ten.    // three. So,   // swap the showtime digit with the third,   // bandy the 2d digit with the fourth    // 4. and print the encrypted integer.   printf("D1=%d, D1=%d, D1=%d, D1=%d\n",          digits[0], digits[1], digits[two], digits[3] ); }            

Then y'all tackle each comment in turn .
In a series of measured steps, y'all work your way towards the answer.

In one case you've got that chip working, and then you can plough it into say

int encrypt(int num) {     // the code that was previously in master }  int main ( ) {     int num = 1234;     int e = encrypt(num); }            

There's no point trying to become 'nail - answer' in one unmarried edit.
It's not how yous're going to solve this problem, and it's non how anyone solves real globe problems anyway.

Learning how to intermission problems down into manageable steps is just as important every bit knowing where the curly braces go.

austinlegis1979.blogspot.com

Source: https://www.dreamincode.net/forums/topic/418004-encryption-and-decryption-on-4-digits-integer/

0 Response to "Your App Should Read a Four Digit Integer With the Third and Swap the Second Digit With the Forth"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel