modulus

Fast multiplication modulo 2^16 + 1

自古美人都是妖i 提交于 2019-12-08 21:01:19
问题 The IDEA cipher uses multiplication modulo 2^16 + 1 . Is there an algorithm to perform this operation without general modulo operator (only modulo 2^16 (truncation))? In the context of IDEA, zero is interpreted as 2^16 (it means zero isn't an argument of our multiplication and it cannot be the result, so we can save one bit and store value 2^16 as bit pattern 0000000000000000 ). I am wondering how to implement it efficiently (or whether it is possible at all) without using the standard modulo

PHP float modulus not working

天大地大妈咪最大 提交于 2019-12-08 15:20:51
问题 I wrote a function to add commas and zeros to a number if necessary, but I've gotten stuck at the modulus function. According to my PHP: float(877.5) % 1 == 0 //true Shouldn't 877.5 % 1 == 0.5 ? 回答1: It's giving you the reminder of the division what you need is fmod, fmod — Returns the floating point remainder (modulo) of the division of the arguments echo fmod(877.5, 1); // 0.5 回答2: No, the modulus operator tells you the remainder of the division. Anything divided by 1 does not have a

MySQL MOD() is broken: Is this the best alternative?

牧云@^-^@ 提交于 2019-12-07 20:05:24
问题 At least in MySQL v5.1.73 (CentOS 6.6), MOD() function returns a bogus result... unless someone can explain how this is actually correct. mysql> select MOD(-385.4784399 ,1440); +-------------------------+ | MOD(-385.4784399 ,1440) | +-------------------------+ | -385.4784399 | +-------------------------+ 1 row in set (0.01 sec) Is this the best alternative? mysql> select -385.478439885319 - 1440 * FLOOR(-385.478439885319/1440); +----------------------------------------------------------+ |

Modulus of Product of two integers

徘徊边缘 提交于 2019-12-07 19:56:08
问题 I have to find c, c = (a*b) mod m a,b,c,m are 32-bit integers. But (a*b) can be more than 32 bits. I am trying to figure out a way to compute c, without using long or any data type > 32 bit. Any ideas? What if m is a prime number, can things be simplified? Note: based on a few comments, c = ((a mod m) * (b mod m)) mod m, but in my case even this multiplication will overflow 回答1: I happen to have this 256 by 128 bit division code with a random-based test and I'm sure you can reduce it

Accurate floating point arithmetic in JavaScript

十年热恋 提交于 2019-12-07 17:07:13
问题 I am creating number spinner widget in JavaScript to essentially mimic the number field in webkit. When you change the number, it needs to check to see if the value is not only within the accepted range, but also that it's in step: <input type="number" min="0" max="100" step="1" /> If a user enters 5.5 the field will truncate this to the closest step lower than the value, which in this case is 5 . For a step of 2 , if the user entered 5.5 , the result would be 4 . The equation I was planning

Getting place values of a number w/ modulus?

前提是你 提交于 2019-12-07 09:36:34
问题 I need to get the place value of a random number submitted by a user. This number can by anything from 0-1000000000000000 (zero to one trillion) . I think this can be achieved by using the JavaScript modulus % operator. The problem, I don't really know how to use it, nor do I understand it. Here is the Fiddle. (All I know is 10%3 returns 1 because 3*3 = 9 and 10-9 = 1 ) I figured out the ones, tens, hundreds, and thousands: var ones = Math.floor(num % 10), tens = Math.floor(num / 10 % 10),

Modular Exponentiation in Java

假如想象 提交于 2019-12-07 06:33:29
问题 I need a way to calculate: (g^u * y^v) mod p in Java. I've found this algorithm for calculating (g^u) mod p: int modulo(int a,int b,int c) { long x=1 long y=a; while(b > 0){ if(b%2 == 1){ x=(x*y)%c; } y = (y*y)%c; // squaring the base b /= 2; } return (int) x%c; } and it works great, but I can't seem to find a way to do this for (g^u * y^v) mod p as my math skills are lackluster. To put it in context, it's for a java implementation of a "reduced" DSA - the verifying part requires this to be

What is the structure of the public key of a signed assembly in C#?

你说的曾经没有我的故事 提交于 2019-12-06 13:51:48
问题 Using this code to retrieve the public key bytes... var pubKey = AppDomain.CurrentDomain.DomainManager.EntryAssembly .GetName().GetPublicKey(); What is this common structure at the start (first 32 bytes) of the key? It's not ASN.1 and it might not be variable. I can google it and get repeats. // 00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 Is it all reversed or just part of it (e.g. the modulus at the end)? 52 53 41 31 is a string of RSA1 . My key's modulus is 1024

BigIntegers, gcd , modulus inverse to find public key

≡放荡痞女 提交于 2019-12-06 13:42:46
So, Im using java to find the public key of a RSA password. Right now Im unsure what I'm doing and also if it's correct. I have this information for the public key. C = 5449089907 n = p*q = 8271344041 q = 181123 p = n/q = 45667 d = 53 phi(n) = (p-1)(q-1) = 8271117252 What complicates things are the BigIntegers, the numbers are way to huge for int and longs, so I have to use the clumsy BigIntegers. As far as I understand I have the following equation to solve. e*5198987987 - x*8271117252 = 1 I'm trying to use euklidske algorithm to solve it. In Java i think i can use the following method : I

openssl: how can i get public key from modulus

点点圈 提交于 2019-12-06 13:05:09
I generate a pair of keys using openssl: shell> ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/Users/mike/.ssh/id_rsa): /path/to/test_rsa Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /path/to/test_rsa. Your public key has been saved in /path/to/test_rsa.pub. And then, I generate modulus from private key: shell> openssl rsa -in /path/to/test_rsa -noout -modulus > /path/to/modulus.txt Now, is there any way to get test_rsa.pub(public key) just from modulus? You can get the public key