Could anybody suggest me how to write a code in C for calculating 15 bytes of base value powered to 64 bytes of exponent value?
Exponentation?
Collapse
X
-
ya wat u said is right. but my problem is , in my application i do have value of 15 byte value.(i.e the total no. is 15 byte value) and even exponent value is 64 byte value.so now how to perform calculation for that. have to divide into bytes and calculate or any other method is there?Comment
-
Then convert these big integers into floating point. You will lose a lot of accuracy, but you will be able to compute an approximation.
Another approach is to apply the mathematical rules for using logarithms to multiply and exponentiate.
Another approach is to use a bignum library, but heed newb16's warning about the amount of memory it will take to hold the result.Comment
-
now 'm' is the plain text to be encrypted and n is 512 bit modulus value.e is 64 byte Encryption exponent value. so how should i deal this?Comment
-
Ah! If you had said mod earlier, this entire discussion could have been much shortened.
There are 2 problems:
A. Multiplying a 64 byte number by a 64 byte number and getting the modulus in a 64 byte result.
B. Algorithm for calculating the exponent.
A. I would take the largest unsigned primitive supported by your environment, (long or long long?) and use the primitive half that size for multiplications (cast as the larger type). Store the result in a 128-byte buffer, then calculate the mod of it.
Example. Multiplying a 2-unit number by another 2-unit number.
Eg, if you had ab * cd where each letter represents an unsigned int, the lowest uint would be:
1: low (b*d)
- the next uint would be
2: high(b*d) + low (a*d) + low(b*c).
- the next uint would be
3: remainder (from 2:) + high(a*d) + high(b*c) + low(a*b)
4: remainder (from 3:) + high(a*b)
where low() gets the lowest bits of the result, and high() gets the higher bits of the result.
B. See methods 4 then 5 in
Calculating Large Exponents
The code is pseudocode, and you will have to apply % to your temporary results.Comment
-
Ah! If you had say mod earlier, this entire discussion could have been much shortened.
There are 2 problems:
A. Multiplying a 64 byte number by a 64 byte number and getting the modulus in a 64 byte result.
B. Algorithm for calculating the exponent.
A. I would take the largest unsigned primitive supported by your environment, (long or long long?) and use the primitive half that size for multiplications (cast as the larger type). Store the result in a 128-byte buffer, then calculate the mod of it.
Example. Multiplying a 2-unit number by another 2-unit number.
Eg, if you had ab * cd where each letter represents an unsigned int, the lowest uint would be:
1: low (b*d)
- the next uint would be
2: high(b*d) + low (a*d) + low(b*c).
- the next part would be
3: remainder (from 2:) + high(a*d) + high(b*c) + low(a*b)
4: remainder (from 3:) + high(a*b)
where low() gets the lowest bits of the result, and high() gets the higher bits of the result.
B. See methods 4 then 5 in
Calculating Large Exponents
The code is pseudocode, and you will have to apply % to your temporary results.
The base value is of 15 bytes length. i have to encrypt 15 bytes length of data.Comment
Comment