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
1
vote
1 answer

My cryptanalyis of an affine cipher isn't working 100% of the time

I have to create a function that takes input as letters from a frequency analysis of the English language, "p1" and "p2", as well as a frequency analysis of the cipher-text, "C1" and "C2", as well as the alphabet length I am using "AL". I have…
user11138547
1
vote
1 answer

Populate cells based on x by y cell value

I'm trying to populate cells based on values from two different cells. Values in the cell needs to be (n-1) where n is the input and then repeated based on the amount of the other cell. For example, I have input: x y 2 5 Output should…
1
vote
1 answer

finding modular inverse of a large number

Given a GP sum (1-((n-1)/n)^r) = P/Q , how to calculate this P/Q fraction when r is large and output (P*Q^(-1))%1000000007 where Q^(-1) is modular inverse of Q modulo 1000000007 I can calculate (n-1)^r and n^r using modular exponentiation and then…
cooldude
  • 63
  • 10
1
vote
1 answer

How to calculate `x^3 + ax + b mod p` with Golang big.Int

I'm trying to find the Y coordinate for an elliptic point. I understand the formula is y^2≡x^3+ax+b mod p. However I'm unsure of how I would actually program this in Go. xCubed.Exp(X, 3, nil) AX.Mul(A,X) N.Add(XPow3, AX) // x^3 + ax N.Mod(N, P) //…
NotAnApple
  • 21
  • 4
1
vote
1 answer

How to express this mathematical equality in python

How do I do this calculation in python? This is what I tried but I guess it's wrong: v=(pow(g,s,p)*pow(modinv(b, p), h, p))%p
lastpeony4
  • 549
  • 1
  • 9
  • 22
1
vote
1 answer

(Scheme) Tail recursive modular exponentiation

I have an assignment to make a tail-recursive function that takes 3 integers(possibly very large), p q and r, and calculates the modulo of the division (p^q)/r. I figured out how to do make a function that achieves the goal, but it is not tail…
1
vote
1 answer

Formula that counts every 9th row

I need a formula that counts every 9th row in the D column starting with D209. So far I have: =sumif(ArrayFormula(mod((row(D1:D)-row(D1)+1),9)),0,D1:D) The formula works right by counting every 9th row but I'm having a hard time getting the formula…
1
vote
3 answers

Find inverse mod in ruby

Is there a function or method to find the inverse mod of say x and y in ruby? Something like inverse(x,y) in the crypto library from python. I'm trying to use it to find d for a rsa implementation.
Alloysius Goh
  • 141
  • 1
  • 1
  • 6
1
vote
1 answer

Python Advanced Modular Arithmetic Algorithm

I have this program: #!/usr/bin/python3 def bounce(modulo: int, here: int, add: int) -> int: # additive version # modulo = 2n > 0, 0 <= here < n, add is any integer # cycle { # {0, 1, 2, 3, ..., n - 1, n - 2, n - 3, ..., # …
YoungCoder5
  • 845
  • 1
  • 7
  • 14
1
vote
2 answers

Why this modular GCD fails on large inputs?

This question actually comes from a Competitive Programming site called codechef. The question is as follow. Given integers A, B and N, you should calculate the GCD of A^N+B^N and |A−B|. (Assume that GCD(0,a)=a for any positive integer a). Since…
coder3101
  • 3,920
  • 3
  • 24
  • 28
1
vote
2 answers

How the Private keys are distributed safely?

I am going through RSA Algorithm and I have few questions. The questions can be silly, Please help me. My understanding of RSA Algorithm. My Question is, How does a Receiver get his private keys P and Q. For a particular Public Key, If every…
Pawan Kumar
  • 1,443
  • 2
  • 16
  • 30
1
vote
4 answers

Java - custom integer division function

I wrote a simple piece of code - ceil1. Since it failed my test cases after rewriting same code - ceil worked. public class Test { public static void main(String args[]){ System.out.println(ceil(3, 2)); //getting 2 …
Amit G
  • 2,293
  • 3
  • 24
  • 44
1
vote
1 answer

How do I draw a border to the right of every cell which is in the Nth column?

For example, if n=4, I want to draw a border after every fourth column. So it looks like this if n=4 (and this is for all the columns): I tried conditional formatting but it draws the border to the right of that cell, and not for the entire column.
1
vote
2 answers

How to implement modular exponentiation?

I am trying to calculate something like this: a^b mod c, where all three numbers are large. Things I've tried: Python's pow() function is taking hours and has yet to produce a result. (if someone could tell me how it's implemented that would be…
1
vote
0 answers

Is SOD(A^b) % mod == SOD(bigmod(A,b,mod))?

I have to calculate A^b where A^b can be a huge number then find The SOD(Sum of divisors) of that number. So, If I calculate SOD(bigmod(A,b,mod)) will this return the same value as SOD(A^b) % mod Asking for this As I am getting WA and could not get…
sabertooth
  • 582
  • 1
  • 7
  • 23