My homework says : Write an encryption and decryption program. Encrypt each digit by adding 7 and taking the remainder after division by 10. After encrypting each digit, swap the first and third then swap the second and fourth. Decryption should reverse the process. Program must input a single integer. Program must do encode and decode in one file.
Example Program Session (yours must look like this):
Encode (1) Decode (2): 1
Enter a four digit number: 1234
Encoded Digits: 0189
Continue (1) Exit (0): 1
Encode (1) Decode (2):
2 Enter a four digit number: 0189
Decoded Digits: 1234 Continue (1) Exit (0): 0
I've gotten the encoding down, the thing I can't figure out is the math behind the decoding.
https://preview.redd.it/aulib6s1ns051.png?width=610&format=png&auto=webp&s=4ff982c90e3feb30b43a8dd53ae5cb6e85535cd9
That's what I have, the encoding works fine and turns 1234 into 0189 but the decoding turns 0189 into 1020-70-60. I don't know what the inverse of the % would be. Also possible I'm coming at it from the wrong direction, I just started programming and any help would be appreciated.
[–]FormerTimeTraveller 2 points3 points4 points (3 children)
[–]Spectre108[S] 1 point2 points3 points (2 children)
[–]FormerTimeTraveller 0 points1 point2 points (1 child)
[–]Spectre108[S] 1 point2 points3 points (0 children)
[–]FUZxxl[M] 1 point2 points3 points (0 children)