Questions tagged [modular-arithmetic]

Modular arithmetic is quite a useful tool in number theory. In particular, it can be used to obtain information about the solutions (or lack thereof) of a specific equation.

In mathematics, modular arithmetic (sometimes called clock arithmetic) is a system of arithmetic for integers, where numbers "wrap around" upon reaching a certain value—the modulus. The modern approach to modular arithmetic was developed by Carl Friedrich Gauss in his book Disquisitiones Arithmeticae, published in 1801.

Time-keeping on this clock uses arithmetic modulo 12. A familiar use of modular arithmetic is in the 12-hour clock, in which the day is divided into two 12-hour periods. If the time is 7:00 now, then 8 hours later it will be 3:00. Usual addition would suggest that the later time should be 7 + 8 = 15, but this is not the answer because clock time "wraps around" every 12 hours; in 12-hour time, there is no "15 o'clock". Likewise, if the clock starts at 12:00 (noon) and 21 hours elapse, then the time will be 9:00 the next day, rather than 33:00. Since the hour number starts over after it reaches 12, this is arithmetic modulo 12. 12 is congruent not only to 12 itself, but also to 0, so the time called "12:00" could also be called "0:00", since 0 ≡ 12 mod 12.

324 questions
0
votes
1 answer

Multiplication of 2 big binary strings modulo another binary string with out converting them to Big Integer

I'm implementing a code for Advanced encryption standard(AES). I'm struck at multiplication modulo operation. The normal conversion of binary string to BigInteger is taking abnormally large amount of time. Any help as to how to code this is ?? The…
prime130392
  • 133
  • 1
  • 2
  • 13
0
votes
1 answer

Modular Inverse involving division of two numbers

I know that (a/b)mod M = ab^-1 mod M and also that when M is prime then b^-1 = b^(M-2) I have to calculate (121/2)mod M where M = 1000000007 (1e9 + 7) Using simple division: (121/2)modM = (60)mod M = 60%M = 60 Using modular Inverse: (121/2)mod M =…
lassaendie
  • 105
  • 8
0
votes
1 answer

Adding elements of two big arrays in java

I have to come up with an algorithm that adds elements of two big arrays(size of each array is 10⁹ of integers that can go up to 10⁹). When declaring two arrays in java with size of 10⁹ each, I get a memory exception! The problem statement:…
Oussama Achech
  • 131
  • 1
  • 11
0
votes
1 answer

How to get mod value from variable and result

variable v = 256478 modular m = 568742 result r = 256478 v (mod) m = r , 256478 (mod) 568742 = 256478 my question how to find mod (m = ?) value from variable and result (some case my program) v (mod) ? = r 256478 (mod) ? = 256478 262713 (mod)…
Prabu r
  • 103
  • 4
0
votes
2 answers

How can modular multiplication and exponentiation be performed in C#?

If I know parameter a, k and p then how do I calculate this in C#? s=a*k^-1 mod p Its for cryptographic purpose and I'm new. Please don't feel offended if the question is not appropriate. Please note that k^-1 is the modular inverse of k (mod p)…
Milon Sarker
  • 478
  • 8
  • 25
0
votes
2 answers

Link between modular arithmetic and bitwise AND in C expression

I came across a C snippet that performs a nifty modular arithmetic operation using bitwise logic: int a,b,c; c = (a + b - 1) & (- b) +b; The value of c is the smallest multiple of b greater than a+b (edited in response to John Bollinger's…
Buck Thorn
  • 5,024
  • 2
  • 17
  • 27
0
votes
1 answer

Karatsuba multiplication algorithm with modular reduction

I am trying to estimate the time it takes to multiply two large bit numbers modulo some large prime. My computational power is limited to adding, multiplying, and storing 32-bit numbers. Due to this I wanted to use the Karatsuba algorithm since the…
0
votes
1 answer

Breaking RSA given we know minimal solution to discrete log mod N

So I'm trying to figure out the connection between the discrete log problem and RSA. I think this is what the following question is trying to do. Suppose you have an oracle which gives you the smallest positive x satisfying the following…
Rose S
  • 5
  • 1
  • 1
  • 3
0
votes
1 answer

Limitations of the mod % operator with big integers

I want to mod out a number that's about 1.7x10^46 by several primes. Things did not look right so I tried hard coding the number mod 3 and 5. It is not giving me the correct answers. Mathematica says they should be 1 and 1, and yet I get 2 and…
0
votes
1 answer

Solving modular equations in maple

I want to ask Maple, for example, for which j the following is true: 10^j mod 543 = 82 How can I ask Maple this? Also, is there a way to solve for j without a computer?
GFauxPas
  • 299
  • 1
  • 14
0
votes
1 answer

How to find antilogarithm for large values?

I want to know how to find antilogarithm of a float. My first approach was to use built-in functions like exp(), pow() both in Python & C, but they gave out of range error. Then I tried to break It in two parts, one integer & other float, then…
0
votes
3 answers

Understanding modular arithmetic in encryption example

I understand modular arithmetic in its basic mathematical form for example: 38 = 2 mod 12 However in the following encryption and decryption code example it is used along with other math and I don't understand what it is used for. def encrypt(key,…
0
votes
1 answer

Modular Arithmetic - Division

How does one calculate (a/b) % m where a = x1*x2*.... and the numbers x1, x2,.. are quite large. If we only had to find a % m , we could have easily done that using (x1%m) * (x2%m) *... but if there's something in the denominator 'b' in our case,…
kash
  • 81
  • 1
  • 7
0
votes
1 answer

Modular Inverse of a number

Recently I have read extended euclid's algorithm which is used to find out the modular inverse of a number N whith respect to MOD such that gcd(N,MOD)=1. But I have a doubt about how to find modular inverse of a number if gcd(N,MOD)!=1?
typedef
  • 33
  • 1
  • 6
0
votes
2 answers

Java Program to calculate Modulo Inverse outputs negative values for numbers greater than 10

import java.util.*; class ModuloInverse { static long mod = 1000000007; public static void main(String[] args) { Scanner in = new Scanner(System.in); long num = in.nextLong(); System.out.println(m_inverse(num,…