Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello, I'm new to programming and I was wondering if anyone can help me with this question?


A company wants to transmit data over the telephone, but it is concerned that its phones may be tapped. All of its data are 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.
The encryption process proceeds 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. The integer obtained will be the encrypted integer.
You are to implement this encryption by writing a function named encrypt that will accepts a four-digit integer as parameter and return the encrypted integer to the caller.

Write another function named decrypt that accepts an encrypted four-digit integer and decrypts it to form the original number.
Implement both the methods in a program/module named security.py. Include in this module the main function that will prompt user for original data and invoke the encrypt function for encryption, and invoke the decrypt function for decryption by passing the encrypted integer. In both cases, you are to display the result, in exactly 4-digit format.

What I have tried:

def main():

IntInput = int(input("Enter an integer number here: "))

a = IntInput / 1000
b = ( IntInput / 100 ) % 10
c = ( IntInput / 10 ) % 10
d = IntInput % 10
Posted
Updated 30-Sep-18 22:33pm

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Read the instructions, and think about what they are telling you to do: at the moment you seem to have ignored most of them ...
Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 
You need to define two functions:
1. encrypt - which accepts an integer, converts it as described in your question, and returns the encrypted value.
2. decrypt - which reverses the above process.

So your program will look something like:
Python
def encrypt(self, number):
    # add the encrypting code here

def decrypt(self, number):
    # add the decrypting code here

    # start of main function

while True:
    number = int(input("Please enter a number greater than 999: "))
    if number < 1000:
        break
    xnumber = encrypt(number)
    print("Encrypted value =", xnumber)
    number = decrypt(xnumber)
    print("Decrypted value =", number)
 
Share this answer
 
v2
Quote:
I'm new to programming and I was wondering if anyone can help me with this question?

So, you show no attempt to solve the problem yourself, you have no question, you just want us to do your HomeWork.
HomeWork problems are simplified versions of the kind of problems you will have to solve in real life, their purpose is learning and practicing.

Take a sheet of paper and a pencil, and solve the problem by hand. The way your solved the problem by hand is basically your algorithm.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900