444,190 Members | 1,653 Online Need help? Post your question and get tips & solutions from a community of 444,190 IT Pros & Developers. It's quick & easy.

# reversing the Mod operator

 P: n/a I am writing an encryption program that takes a digit and yields its modulus. For example, 7 Mod 4 yields 3. How can I reverse this procedure and get the original digit back in order to write a decryption program? Oct 13 '06 #1
5 Replies

 P: n/a On Oct 13, 9:44 pm, Candace

 P: n/a This is for a class that I am taking. I'm just learning to program. The instructions said "Your program should read a four-digit Integer entered by the user and encrypt it as follows: Replace each digit by (the sum of that digit and 7) modulo 10. Then write a program that inputs an encryption four-digit Integer and decrypts it to form the original number." Do you think I could be miss-understanding the instructions? Or are you reading it as the same meaning that I am? "Candace" wrote: I am writing an encryption program that takes a digit and yields its modulus. For example, 7 Mod 4 yields 3. How can I reverse this procedure and get the original digit back in order to write a decryption program? Oct 13 '06 #3

 P: n/a I agree, for crypting. Take a look at the post by "IZZY" about 128 bit encryption function he posted. Search this newsgroup for Variable = EncryptString128Bit(txt_Password.Text, EncryptionKey) Miro "Josip Medved" I am writing an encryption program that takes a digit and yields itsmodulus.For example, 7 Mod 4 yields 3. How can I reverse this procedure and gettheoriginal digit back in order to write a decryption program? Since there can be same result for multiple numbers (e.g. 7 MOD 4 = 3 and 3 MOD 4 = 3) there is no way. BTW. Why would you even consider this? You have lots of crypting algorithms already available that do good job. -- Greetings, Josip Medved http://www.jmedved.com Oct 13 '06 #4

 P: n/a Candace wrote: This is for a class that I am taking. I'm just learning to program. The instructions said "Your program should read a four-digit Integer entered by the user and encrypt it as follows: Replace each digit by (the sum of that digit and 7) modulo 10. Then write a program that inputs an encryption four-digit Integer and decrypts it to form the original number." Do you think I could be miss-understanding the instructions? Or are you reading it as the same meaning that I am? Try looking at the problem a little differently, and I think you'll get it. What Mod 10 actually does to a whole number is remove everything except the rightmost digit, right? Suppose your original digit is 5. You have to add 7. Try incrementing 5 by 1, seven times, in your head - but remember, you can never reach double digits. When you pass nine, start back at zero. 5 becomes 6, 7, 8, 9, 0, 1, 2. So 2 is your encrypted version of 5. To decrypt: 2 becomes 1, 0, 9, 8, 7, 6, 5. Now see if you can find a mathematical way to decrypt a single digit in *one* line of code. If you can't, I'll tell you - but you learn more this way; gotta exercise the brain to get really good at this stuff. :) Oct 13 '06 #5

 P: n/a I see. This is a classic Caesar encryption, a method that is more than 2000 years old. :) The encryption works by shifting the alphabet a certain number of steps, for example using a shift of +1 would turn "BAR" into "CBS". To decrypt you simply use the negative shift, i.e. the shift -1 turns "CBS" into "BAR". The characters that are shifted outside of the alphabet just wraps over at the other end, that's where the modulo comes in. With this lesson of history and cryptography, I hope that you understand what your program is actually supposed to be doing, only using digits instead of letters. :) Candace wrote: This is for a class that I am taking. I'm just learning to program. The instructions said "Your program should read a four-digit Integer entered by the user and encrypt it as follows: Replace each digit by (the sum of that digit and 7) modulo 10. Then write a program that inputs an encryption four-digit Integer and decrypts it to form the original number." Do you think I could be miss-understanding the instructions? Or are you reading it as the same meaning that I am? "Candace" wrote: >I am writing an encryption program that takes a digit and yields its modulus.For example, 7 Mod 4 yields 3. How can I reverse this procedure and get theoriginal digit back in order to write a decryption program? Oct 14 '06 #6

### This discussion thread is closed

Replies have been disabled for this discussion. 