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

Exponentiation with fractional power in a prime finite field

I'm trying to do some exponentiation in the finite field modulo prime GF(8191) and I'm not sure why I don't get consistent results. I compare those formulas: with and which should return the same result (at least it does in ) The Sage code is…
Eric
  • 1,138
  • 11
  • 24
1
vote
1 answer

RSA digital signature failing

I am trying to implement the RSA Blind digital signature scheme, using the BigInteger class for generating large prime numbers. Samantha generates the public key, the private key, chooses a message, masks it, then signs it and then Victor verifies…
Bogdan Kandra
  • 150
  • 1
  • 14
1
vote
2 answers

Optimizing code to map numbers 1 - 25 uniformly to 5 colors

I am currently learning JavaScript, and I made this code (and it works fine) but I know that there must be a way to automate this better. I'm little bit fuzzy on loops, but from what I know of them, I don't know that one could be used in this…
1
vote
4 answers

Sum of the digits of a number?

I am a newbie to programming .here I have been solving a simple problem in functional programming (OZ) which is finding the sum of the Digits of a 6 digit positive integer. Example:- if n = 123456 then output = 1+2+3+4+5+6 which is 21. here I found…
læran91
  • 283
  • 1
  • 15
1
vote
1 answer

Left to right binary modular exponentiation in Javacard

I am thinking to implement left to right binary modular exponentiation in Javacard. I know that there are libraries which can perform RSA encryption etc. but in my case I just need to perform the modular exponentiation. The only thing that I am…
TechJ
  • 512
  • 2
  • 5
  • 16
1
vote
2 answers

Sum of remainders over the entire array for several queries

I am looking at this challenge: You are provided an array A[ ] of N elements. Also, you have to answer M queries. Each query is of following type- Given a value X, find A[1]%X + A[2]%X + ...... + A[N]%X…
user249117
  • 37
  • 6
1
vote
0 answers

Sliding Windows Frequency Exponential Maximum Sum

I encountered Return Gift problem and tried to solve it by the following approach - I have made a 2d array where the row represents the numbers in the array and column represents the index from where the window is starting. Basically, dp[i][j]…
1
vote
1 answer

Calculating (A pow B) mod M for very large A and B (stored in string)

Link to the problem: https://www.hackerearth.com/problem/algorithm/rhezo-and-big-power/description/ I saw the best submission in which the person calculated A%M (just like how we do on paper), and B%(M-1); then these two came in Integer range and he…
1
vote
1 answer

Multiplicative inverse in Charm Crypto

In Charm Crypto, how would I go about getting at the multiplicative inverse for ZR? I have roughly the following code: a = group.random(G) e = group.random(ZR) x = a ** e somestuff() y = x ** (1/e) where a is not stored on purpose. However while -e…
1
vote
3 answers

Is there a shorthand for modulation in reverse?

Say I have array indices 0 through 5 If I'm incrementing a counter over this array, I could do something like i % 6 To make sure it never goes out of index. Is there a shorthand notation for the same thing for decrementing? I'm asking in general,…
Jason
  • 808
  • 6
  • 25
1
vote
1 answer

Excel column to Int and vice-versa - improvements sought

In the code below, I am happy with the functionality i.e. the code produces the output that I expect. However, comparing the length of toCol to toInt - I am interested in knowing if you could offer something to trim it (i.e. toCol ) down. Many…
Foo
  • 35
  • 4
1
vote
0 answers

Why does % give different answers when an arithmetic expression has floating points?

I recently started learning java and this question keeps on bugging me.. class Example{ public static void main(String args[]){ double d; d=4.1 % 1.1; System.out.println("4.1%1.1 : "+d); d=5.5 % 1.1; …
Dilini Peiris
  • 446
  • 1
  • 6
  • 16
1
vote
1 answer

Modular Exponentiation with big numbers

I'm Trying to implement modular exponentiation algorithm. I have some class: template< typename T> class SomeMathFun { ..... } and it has method: static T ModularExp(T base, T exp, T modulo) { T result(1); base %= modulo; while…
NonSense
  • 173
  • 1
  • 2
  • 13
1
vote
1 answer

Modular exponentation in C

Help! I need to implement a C program (using only string, stdlib, and stdio libraries) which use modular exponentiation of really big numbers, some of them is 260 digits. I'm thinking of using a linked list but I cannot find a good reference on how…
Xael Yvette
  • 77
  • 1
  • 9
1
vote
1 answer

multiplication by 14 in GF(256)

I'm coding AES Invert mixcolumns operation and I need to multiply numbers by 14 in GF(256). This is what I have come up with (p is the result and q the number to multiply by 14): #include #include #include #include…
2A-66-42
  • 554
  • 1
  • 5
  • 18