Ethical Hacking Learn to find vulnerabilities before the bad guys do! Gain real world hands on hacking experience in our state of the art hacking lab. Course designed and taught by expert instructors with years of penetration testing experience. 12 student maximum in every class. Certification attempt included in every package. | Computer Forensics Training at InfoSec Institute Gain the in-demand skills of a certified computer examiner, learn to recover trace data left behind by fraud, theft, and cybercrime perpetrators. Discover the source of computer crime and abuse at your organization so that it never happens again. All of our class sizes are guaranteed to be 12 students or less to facilitate one-on-one interaction with one of our expert instructors. |

| Subject: | Re: modulo question |
|---|---|
| Date: | Wed, 20 Apr 2005 13:26:00 -0700 |
Generally speaking, the modulus operator is defined as a mapping from the integers to a modular ring of numbers. Hence, the result of any operation should be a nonnegative value ranging from zero to n-1 in canonical form.
That said, what your chosen example here is poor simply because +1 and -1 are congruent modulo 2 (i.e, they are the same value). Hence using 1 and 3 would yield more insightful results as -2 and +1 are congruent modulo 3. Below is a quick example from PHP.
1% 3 == 1 -1% 3 == -1 1%-3 == 1 -1%-3 == -1
Note that +1 and -1 are not congruent modulo 3 so we gain more insight into what is happening. Here (and in your C++ example) the sign is a function of the operand (+-1) but not the modulus (3).
For a clear and simple mathematical definition, follow the link below.
http://mathworld.wolfram.com/Congruence.html
In essence, any pair of intergers, a and b, are said to be congruent modulo some integer m if the value a-b is an integral multiple of m. To get a solid grasp on the properties of modular arithmetic I would suggest reading an introductory text on "abstract algebra" at either the senior or graduate level. But I will not recommend that unless you have been trained to read such texts.
As for applications using negative values in the modulus, I cannot come up with any off the top of my head, and coding I favor not doing so as your example illustrates the potentially inconsistent implementations of it (that and I was trained to think of modular arithmetic in terms of positive integers).
hope this helps,
Sean
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | RE: suggesting passwds to users, Scovetta, Michael V |
|---|---|
| Next by Date: | RE: suggesting passwds to users, maburns |
| Previous by Thread: | Re: modulo question, Kelly John Rose |
| Next by Thread: | Recon 2005 - Speakers list, dataworm |
| Indexes: | [Date] [Thread] [Top] [All Lists] |