473,654 Members | 3,089 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 4153
On Oct 13, 9:44 pm, Candace <Cand...@discus sions.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 = EncryptString12 8Bit(txt_Passwo rd.Text, EncryptionKey)

Miro
"Josip Medved" <jm*****@jmedve d.comwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
On Oct 13, 9:44 pm, Candace <Cand...@discus sions.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
3867
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 "BitString.h"
4
5965
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 in how I can accomplish this. Also, I don't know the the size of the array before hand as the image can be any size. I already have the my read and write gif functions working, but I just need to know how to reverse the contents.
11
8062
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 a backcolor/forecolor/etc property and calculate the "reverse colour"? In other words, If a user picks 255 (red) for a control backcolor, I'd like to be able to calculate the opposite or negative of that colour and assign the control's...
45
5194
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
9481
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 middle of the array. Given an array a , an int variable n containing the number of elements in a , and two other int variables, k and temp , write a loop that reverses the elements of the array. Do not use any other variables besides ...
4
2704
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 the words in the text file into an arraylist. For example... Hello World. ---> must be printed out as --> olleH .dlroW right now when i print my arraylist i am getting I was thinking of somehow...
8
4751
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. --------------------------------- PROGRAMME -------------------------------- /* K&R2 section 1.9 exercise 1.19
16
2074
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 should except that every traversal thru the string I've gotten it to repeat the "list" again. This is what it looks like: for char in x: mylist.append(char)
7
5094
by: benn686 | last post by:
Anyone know of an efficient way of reversing the bits of a word??
1
3302
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
8709
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8494
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8596
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7309
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2719
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 we have to send another system
2
1597
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.