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. 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 build the script that displays the encrypted integer.
# Python 3.9.5
def encryption_number(number):
enc_num = ''
for i in str(number):
enc_dig = (int(i) + 7) % 10
enc_num += str(enc_dig)
enc_num = enc_num[2] + enc_num[3] + enc_num[0] + enc_num[1]
return enc_num
def main():
number = 1234
print(encryption_number(number))
if __name__ == '__main__':
main()
Comments
Leave a comment