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

negative exponent in modular exponentiation for RSA

I am trying to write an RSA code in python3.6 for educational purposes. The key generation and message encryption work fine, but I have a problem with decryption. As I understand the decryption algorithm is M = Cd mod n, where M is the message, C is…
0
votes
0 answers

Intel modular arithmetic using AVX or SSE

Is it possible to do modular arithmetic on integers with AVX or SSE? i.e. perform several mods all at once. Bipman
Bipman
  • 53
  • 8
0
votes
1 answer

I have the encode function for an ascii cipher, but need help to how to decode it

I am working on a puzzle which involves decoding a cipher. I have been given the function used to encode the ciphertext, but I am not sure how I can reverse engineer this to find the decode function. This is the function, in JavaScript: function…
alexcons
  • 531
  • 3
  • 8
  • 18
0
votes
2 answers

BInary Eucledian algorithms goes to infinite loop

i have implemented binary eucledian algorithm in matlab, here is code function d=EuclidBinary(a,b) if a==0 d=b; return ; elseif b==0 d=a; return; elseif mod(a,2)==0 && mod(b,2)==0 …
user466534
0
votes
1 answer

Modular multiplication and overflow in R

I have a vector with approximately 1000 elements from roughly 1 to 10 and I want the product of all elements multiplied together modulo 10^6. I.e., I want something akin to x <- as.integer(runif(1000, 1, 10)) prod(x) %% 1000000 However, since…
MSR
  • 3
  • 1
0
votes
2 answers

How can I do modular arithmetic with decimal values in Python?

Say I want to do something like 9.9 % 13 The normal python modulo will give me an output of 9.9. Are there any modules I can import that will instead give me an output of 6 (or more generally an integer value)?
UBears
  • 371
  • 1
  • 4
  • 18
0
votes
1 answer

Python Napier Calculator Issue

So, I've been working at this for hours and hours, this is a homework assignment and I just can't figure out why the code doesn't execute completely. I provided all the code to see if there was something I missed outside of the 'assign2' function.…
0
votes
1 answer

How to calculate the expression

Given the equation-> (index+rotation)%rot=f; if i konw the values of f , rotation , rot what is the formula to calculate index.I am not so good in mathematics but i want to know to calculate index in my programming.
user1438832
  • 493
  • 3
  • 10
0
votes
0 answers

Lagrange's Four Square theorem under modulus

Given an integer n, print out all possible combinations of integer values of A,B,C and D which solve the equation A^2+B^2+C^2+D^2=N under modulus user given integer p int sum(int n) { int a, b, c, d, na, nb, nc, nd; int count = 0; for (a =…
Buckster
  • 41
  • 12
0
votes
0 answers

Modulo operation difference between Swift and Python

I am trying to port a modular inverse operation from Python to Swift, and my modulo operation is producing different results. I am wondering if someone can point out why I am getting different results? I am using this as my BInt Library. PYTHON…
user1848601
0
votes
1 answer

RSA encryption python not working with small primes

I have implemented RSA encryption and decryption code which is working for values p,q,d = 61,53,17. I took these values as they are mentioned in wikipedia. I beleive that p and q should be prime and d is chosen such that d and phi(n) are relatively…
0
votes
1 answer

Why does the modulo operator behave differently from mathematical faction MOD

There is an anomaly between the usual approach and the programming approach in the division of a negative number by a negative number as mentioned in the pictures bellow. Mathematical demonstration of anomaly: (Sorry for bad handwriting :) Hope it…
hecate
  • 620
  • 1
  • 8
  • 33
0
votes
2 answers

Modulo for large numbers that are squared

I have a large number I want to take the remainder of. For example 300^31. When I try to use % operator it says I cant use it on doubles, since it works only for integers. Is there any function for that calculation? I tried to use a=pow(b,x)%d;
Sick654
  • 79
  • 9
0
votes
0 answers

Modular Inverse higher than -1

Im trying to solve 2^(-5) mod 19. How to do this using EEA? I tried for like 1h and cant get the result.
0
votes
0 answers

Subtracting finite rings in Assembly

For the finite ring R2 = {00000000,00000001..,11111111} find: 11010111 - 10101010 = N2 = ___________. I am trying to answer this question. I cannot subtract normally in assembly so, using the formula, i get: (11010111 + ~10101010) mod (1000000) =…
groot
  • 31
  • 1
  • 6