| 1396 | } |
| 1397 | |
| 1398 | unsigned int Integer::Encode(byte *output, unsigned int outputLen, Signedness signedness) const |
| 1399 | { |
| 1400 | if (signedness == UNSIGNED || NotNegative()) |
| 1401 | { |
| 1402 | for (unsigned i=0; i<outputLen; i++) |
| 1403 | output[i]=GetByte(outputLen-i-1); |
| 1404 | } |
| 1405 | else |
| 1406 | { |
| 1407 | // take two's complement of *this |
| 1408 | Integer temp = Integer::Power2(8*STDMAX(ByteCount(), outputLen)) + *this; |
| 1409 | for (unsigned i=0; i<outputLen; i++) |
| 1410 | output[i]=temp.GetByte(outputLen-i-1); |
| 1411 | } |
| 1412 | return outputLen; |
| 1413 | } |
| 1414 | |
| 1415 | unsigned int Integer::DEREncode(byte *output) const |
| 1416 | { |