Questions tagged [modular-arithmetic]

99 questions
5
votes
1 answer

modulo with n instead of 0 without using if-statement

Is there a way to to express the following without using an if statement, but with mathematical operations instead? { 5 if x % 5 = 0, x % 5 otherwise }
maddingl
  • 153
  • 2
4
votes
3 answers

How to reverse in modular arithmetic

Given an RGB color {127, 255, 212} where scale is 0-255, VBA's RGB function find a long integer x such that IntegerPart@{Mod[x,256],Mod[x/256,256],Mod[x/256^2,256]} is equal to {127,255,212}. In this particular case the x=13959039 How do i…
user13892
  • 9,375
  • 1
  • 13
  • 41
3
votes
2 answers

Evaluate modular fractions

If I have a list of numbers l = {256/11, 258/11, 263/11, 263/11, -22, -22, 251/11, 0, 261/11, -22, 265/11, 259/11, 0, 259/11} which I want to evaluate mod 26, how do I do that? I know I can do Mod[l, 26], but that just gives me {256/11, 258/11,…
Matt G
  • 349
  • 2
  • 9
2
votes
0 answers

Effective way of iterating multiplication modulo p

I am trying to compute discrete logarithms modulo p (in a naive way). I have three approaches LogMod1[a_, b_, p_] := Block[{j = 0}, While[PowerMod[a, j, p] != b && j < p, j++]; j]; LogMod2[a_, b_, p_] := Block[{j = 0, aa = 1}, While[aa != b…
gerald
  • 233
  • 1
  • 5
2
votes
1 answer

A Difficult Application of Modular Arithmetic

Looking to input a $p$ for the first line: p=6; Build a list of primes from the 3rd to $p-1$: plist=Table[Prime[n],{n,3,p-1}]; Then build a list as follows: bmod=Outer[Mod,{3*Prime[p]},plist] Here's the code so far with the…
1
vote
2 answers

Modular arithmetic in Mathematica?

I want to implement something like 1 + 1 = 0; i.e., simple modular arithmetic in Mathematica. This seems like it should be a really easy built-in option, but I can't find any info on it anywhere. I think probably I'm just overlooking…
quantum_loser
  • 329
  • 1
  • 9
0
votes
1 answer

Solving for $d$ in $x= E^d \bmod(n)$

With regards to Public Key Cryptography, I have been tasked with the problem of attacking some information given in an assignment and discovered a private key used to digitally sign a…
Matt
  • 19
0
votes
1 answer

Eliminate an expression with Mod operation

The target below should equal 0, since 2x + c = a + b + c = 6c, and Mod[6c,3] == 0 But Mathematica seems to be unable to simplify this expression containing Mod? It says "target-1/4\ Mod[c+2\ x,3] is not a well-formed equation." Eliminate[{a == b +…
-2
votes
1 answer

Want code for a modular operation

Given numbers a1 and a2 and a positive integer k, such that a3 = Mod[a1 a2, k], a4 = Mod[a1 a3, k] and so on, I want the Mathematica code that can compute the value of {a1, a2, a3, a4, ..., an} stopping at a point where a particular condition is…
myg
  • 3
  • 6