modular-arithmetic

Elliptic curve addition in Jacobian coordinates

╄→尐↘猪︶ㄣ 提交于 2019-12-23 20:24:53
问题 I try to add two points on an elliptic curve over a prime field, converting these points from affine/to-affine coordinates, but do not manage to get a correct result (the curve I am testing has a=0). Anyone can see what's wrong? // From Affine BigInteger X1=P.x; BigInteger Y1=P.y; BigInteger Z1=BigInteger.ONE; BigInteger X2=Q.x; BigInteger Y2=Q.y; BigInteger Z2=BigInteger.ONE; // Point addition in Jacobian coordinates for a=0 // see http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0

Adding elements of two big arrays in java

无人久伴 提交于 2019-12-23 04:58:05
问题 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: http://bit.ly/1XWbUca 回答1: by analyzing the input constraints you can see that you can get 2*10^5 * 10^9 array accesses in the worst case if you implement the solution using two arrays of ints. So that approach will not do. If you somehow solve your MLE

Adding hexadecimal strings in JavaScript efficiently

蓝咒 提交于 2019-12-23 03:35:07
问题 In JavaScript, I have two variables that contain a hexadecimal number as a string, each. E.g.: var a = 'a3bc', b = '1d0f'; Now I want to add them (so, the result should be 'c0cb' ). To make things a little bit easier, let's put some constraints on this: The numbers always consist of the same number of digits (i.e., the strings are of same length). The numbers are prefixed with 0 s if necessary, so it will be '001a' , not just '1a' . On the other side, there are constraints that make things a

How to Convert from a Residual Number System to a Mixed Radix System?

冷暖自知 提交于 2019-12-21 20:48:28
问题 I understand the concept of a Residual Number System and the concept of a Mixed Radix system, but I'm having difficulty getting any of the conversion methods I find to work in a simple case study. I started at Knuth's Art of Computer Programming but that had a bit too much on the theory of the conversion, and once Euler was mentioned I was lost. Wikipedia has a nice section on the subject, which I tried here and here but both times I couldn't get back to the number where I started. I found a

Sympy: Solving Matrices in a finite field

家住魔仙堡 提交于 2019-12-18 16:25:08
问题 For my project, I need to solve for a matrix X given matrices Y and K. (XY=K) The elements of each matrix must be integers modulo a random 256-bit prime. My first attempt at solving this problem used SymPy's mod_inv(n) function. The problem with this is that I'm running out of memory with matrices of around size 30. My next thought was to perform matrix factorization, as that might be less heavy on memory. However, SymPy seems to contain no solver that can find matrices modulo a number. Any

Modular arithmetics and NTT (finite field DFT) optimizations

自作多情 提交于 2019-12-16 20:03:57
问题 I wanted to use NTT for fast squaring (see Fast bignum square computation), but the result is slow even for really big numbers .. more than 12000 bits. So my question is: Is there a way to optimize my NTT transform? I did not mean to speed it by parallelism (threads); this is low-level layer only. Is there a way to speed up my modular arithmetics? This is my (already optimized) source code in C++ for NTT (it's complete and 100% working in C++ whitout any need for third-party libs and should

How to calculate x^y mod z? [duplicate]

怎甘沉沦 提交于 2019-12-13 07:58:12
问题 This question already has answers here : Calculating (a^b)%MOD (6 answers) Closed 4 years ago . I am wondering how to calculate x^y mod z. x and y are very large (can't fit in 64 bit integer) and z will fit 64 bit integer. And one thing don't give answers like x^y mod z is same as (x mod z)^y mod z. 回答1: Here is the standard method, in pseudo-code: function powerMod(b, e, m) x := 1 while e > 0 if e % 2 == 1 x := (b * x) % m e := e - 1 else b := (b * b) % m e := e / 2 return x The algorithm is

Modular exponentiation implementation in Python 3

£可爱£侵袭症+ 提交于 2019-12-11 07:54:25
问题 Basically this is a homework question. I'm supposed to implement these two pseudo-code algorithms in Python3. I'm doing something wrong and I can't figure out what (it seems like this should be simple so I'm not sure what/where I botched this. It could be my algorithm or my lack of experience with Python. I'm not sure which.). Please tell me what I did wrong, don't post any code. If I get code for an answer I'll get pegged for plagiarism (which I very much do not want). The first algorithm

Unidirectional ElGamal Proxy Re-Encryption implementation

心不动则不痛 提交于 2019-12-08 06:24:39
问题 I've implemented an ElGamal scheme in JavaScript (the code is awful, just wanted to test it quick) based on this explanation. var forge = require('node-forge'); var bigInt = require("big-integer"); var bits = 160; forge.prime.generateProbablePrime(bits, function(err, num) { // Create prime factor and convert to bigInt var factor = bigInt(num.toString(10)); // Find a larger prime of which factor is prime factor // Determine a large even number as a co-factor var coFactor = bigInt.randBetween(

Final subtraction in montgomery modular multiplication for an RSA cryptosystem

强颜欢笑 提交于 2019-12-07 16:18:09
问题 I'm confused about how one might supposedly bypass the final subtraction of the modulus in radix-2 montgomery modular multiplication, when used in a modular exponentiation algorithm. The following two papers put forward the conditions for bypassing the subtraction. Montgomery Exponentiation with no Final Subtractions: Improved Results Montgomery Multiplication Needs no Final Subtractions I don't understand exactly what is required in terms of the "preprocessing and postprocessing" to