modulus

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

若如初见. 提交于 2019-12-06 10:41:17
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); +----------------------------------------------------------+ | -385.478439885319 - 1440 * FLOOR(-385.478439885319/1440) | +---------------------------------------------

Modulus of Product of two integers

半腔热情 提交于 2019-12-06 05:56:13
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 I happen to have this 256 by 128 bit division code with a random-based test and I'm sure you can reduce it trivially to 128 by 64 bit division and then to 64 by 32: #include <limits.h> #include <stdio.h> #include <stdlib.h>

Generate RSA Public key from modulus and exponent in bytes in Objective-c

血红的双手。 提交于 2019-12-06 02:26:21
I'd searching many websites trying to understand how does RSA works. I have a modulus "A89F25A56FA6DA258C8CA8B40427D927B4A1EB4D7EA326BBB12F97DED70AE5E4480FC9C5E8A972177110A1CC318D06D2F8F5C4844AC5FA79A4DC470BB11ED635699C17081B90F1B984F12E92C1C529276D8AF8EC7F28492097D8CD5BECEA16FE4088F6CFAB4A1B42328A1B996F9278B0B7E3311CA5EF856C2F888474B83612A82E4E00D0CD4069A6783140433D50725F" and exponent "03" and i have to decrypt information formated in hex bytes. My questions are: How do i create a public key? Once i have the public key do i have to encode in base64 or the public key is ready to decrypt?

C: The Math Behind Negatives and Remainder

一世执手 提交于 2019-12-05 21:33:21
This seems to be the #1 thing that is asked when dealing with Remainder/Mod, and I'm kind of hitting a wall with it. I'm teaching myself to program with a textbook and a chuck of C code. Seeing as I don't really have an instructor to say, "No, no. It actually works like this", I thought I'd try my hand here. I haven't found a conclusive answer to the mathematical part of this, though. So... I'm under the impression that this is a pretty rare occurrence, but I'd still like to know what it is that happens underneath the shiny compiling. Plus, this textbook would like for me to supply all values

Modular Exponentiation in Java

狂风中的少年 提交于 2019-12-05 12:06:13
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 solved. Assuming that the two factors will not overflow, I believe you can simplify an expression like

How to calculate modulus of the form (a*b)%c?

▼魔方 西西 提交于 2019-12-05 09:13:40
How to calculate modulus of the form (a*b)%c? i want to calculate modulus of multiplication of two int numbers where they are almost in the stage of overflow... here c is also int (a * b) % c == ((a % c) * (b % c)) % c What about ((a % c) * (b % c)) % c ? Depending on your architecture this could be faster or slower than casting to a bigger type. You may cast a and c to long long , so the multiplication won't overflow. ((long long)a * (long long)b) % c 来源: https://stackoverflow.com/questions/5915808/how-to-calculate-modulus-of-the-form-abc

Repeating letters like excel columns?

a 夏天 提交于 2019-12-05 06:07:58
I want to create a list of string that resemble the column letters in Microsoft Excel. For example, after 26 columns, the next columns become AA , AB , AC , etc. I have tried using the modulus operator, but I just end up with AA , BB , CC , etc... import string passes_through_alphabet = 0 for num, col in enumerate([_ for _ in range(40)]): if num % 26 == 0: passes_through_alphabet += 1 excel_col = string.ascii_uppercase[num%26] * passes_through_alphabet print(num, excel_col) 0 A 1 B 2 C 3 D ... 22 W 23 X 24 Y 25 Z 26 AA 27 BB 28 CC ... You can use itertools.product for this: >>> import

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

时光总嘲笑我的痴心妄想 提交于 2019-12-04 18:35:05
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 bit, so I was looking for something that described the length. 0x0400 ( 00 04 B.E.) would be 1024 (bits

How to find remainder without division or modulo operator in MIPS assembly

余生颓废 提交于 2019-12-04 17:23:33
I want to find a way to know if an integer is divided by 3 or 7 without using division, because it is very slow in MIPS assembly. I have done a lot of research but found nothing. There's a method described by Granlund & Montgomery that requires the modular / multiplicative inverse of the (odd) divisor modulo 2**b . (Some parts of this paper have been improved recently ) The divisors: (d) = 3, 7 (odd numbers) are an easy case. Assuming 32 bit (unsigned) arithmetic, the inverses modulo 2**32 yield 2863311531 (0xAAAAAAAB) and 3067833783 (0xB6DB6DB7) respectively. There's an online calculator here

How to sort an array of odd numbers in ascending order, but keep even numbers at their position?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 04:35:34
问题 I want to sort only odd numbers without moving even numbers. For example, when I write : sortArray([5, 3, 2, 8, 1, 4]) The expected result is : [1, 3, 2, 8, 5, 4] I am new to JavaScript and I came across a challenge on the Internet that has me perplexed. I normally wouldn't post asking for a solution on the Internet, BUT I have tried for hours and I would like to learn this concept in JavaScript. The challenge states : You have an array of numbers. Your task is to sort ascending odd numbers