473,503 Members | 11,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reversing the Mod operator

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 4146
On Oct 13, 9:44 pm, Candace <Cand...@discussions.microsoft.comwrote:
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?
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 #2
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
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" <jm*****@jmedved.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
On Oct 13, 9:44 pm, Candace <Cand...@discussions.microsoft.comwrote:
>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?

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
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
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 the
original digit back in order to write a decryption program?
Oct 14 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3852
by: joesoap | last post by:
Hi can anybody please tell me what is wrong with my ostream operator??? this is the output i get using the 3 attached files. this is the output after i run assignment2 -joesoap #include...
4
5943
by: Kevin | last post by:
Hello, I need to some help in reversing an 2-dimensional array. I am working with gif images and I am trying to make the mirror image. I was hoping that someone could help give me a headstart...
11
8002
by: Tim Marshall | last post by:
I use Terry Kreft's & Stephen Lebans colour dialog procedures for users to pick colours for various control properties in certain apps. Is there a way to take the colour code that is displayed in...
45
5150
by: Ajay | last post by:
Hi all,can you please tell the most efficient method to reverse a byte.Function should return a byte that is reversed.
3
9470
by: dru | last post by:
Problem: Reversing the elements of an array involves swapping the corresponding elements of the array: the first with the last, the second with the next to the last, and so on, all the way to the...
4
2692
by: hello12 | last post by:
Hello, I am new to java and i was having a hard time figuring out on how to do certain string manipulations. I was asked to read in a text file and reverse the words. So far, I have put all...
8
4741
by: arnuld | last post by:
i have created a solutions myself. it compiles without any trouble and runs but it prints some strange characters. i am not able to find where is the trouble. ...
16
2057
by: Scott | last post by:
Yeah I know strings == immutable, but question 1 in section 7.14 of "How to think like a computer Scientist" has me trying to reverse one. I've come up with two things, one works almost like it...
7
5085
by: benn686 | last post by:
Anyone know of an efficient way of reversing the bits of a word??
1
3292
by: rajkumarbathula | last post by:
Hi Could any one help me out in reversing rows/elements of DataTable or String or DataList by using any simple statement? Thanks
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.