std::string
DMYWCalendarService< C, W, O >::JDToDate( std::string calendarName,
                                          CalendarService::Format format )
{
    CGIInput & cgiInput = CGIInput::Instance();
    long julianDay = std::atol( cgiInput[ "julianDay" ].c_str() );
    int day, month;
    long year;
    C::JulianDayToDMY( julianDay, &day, &month, &year );
    int dayOfWeek = (int)ModP( (julianDay + W::DayOfWeekOfJD0()),
                               (long)W::DaysInWeek() );
    std::string options = O::Get( format );
    switch ( format )
    {
    case CalendarService::JSON:
    {
        JSONObject jsonObj;
        jsonObj[ "calendar" ] = ToJSON( calendarName );
        jsonObj[ "options" ] = options;
        jsonObj[ "julianDay" ] = ToJSON( julianDay );
        jsonObj[ "day" ] = ToJSON( day );
        jsonObj[ "month" ] = ToJSON( month );
        jsonObj[ "year" ] = ToJSON( year );
        jsonObj[ "dayOfWeek" ] = ToJSON( dayOfWeek );
        return ToJSON( jsonObj );
    }
    default:
        throw Exception( "Unexpected format" );
    }
}
string
HinduLunisolarCalendarService::JDToDate( string calendarName,
                                         CalendarService::Format format )
{
    CGIInput & cgiInput = CGIInput::Instance();
    long julianDay = atol( cgiInput[ "julianDay" ].c_str() );
    int day, month;
    long year;
    bool dayLeap, monthLeap;
    HinduLunisolarCalendar::JulianDayToDLMLY( julianDay,
                                              &day, &dayLeap, &month,
                                              &monthLeap, &year );
    int dayOfWeek = (int)ModP( (julianDay + HinduWeek::DayOfWeekOfJD0()),
                               (long)HinduWeek::DaysInWeek() );
    switch ( format )
    {
    case CalendarService::JSON:
    {
        JSONObject jsonObj;
        jsonObj[ "calendar" ] = ToJSON( calendarName );
        jsonObj[ "julianDay" ] = ToJSON( julianDay );
        jsonObj[ "day" ] = ToJSON( day );
        jsonObj[ "dayLeap" ] = ToJSON( dayLeap );
        jsonObj[ "month" ] = ToJSON( month );
        jsonObj[ "monthLeap" ] = ToJSON( monthLeap );
        jsonObj[ "year" ] = ToJSON( year );
        jsonObj[ "dayOfWeek" ] = ToJSON( dayOfWeek );
        return ToJSON( jsonObj );
    }
    default:
        throw Exception( "Unexpected format" );
    }
}
Пример #3
0
Point ECDSA::Double(Point P) {
  Point r;

  BigInt numerator = BigInt(3) * (P.x ^ 2) + a;
  numerator = ModP(numerator);

  BigInt denominator = BigInt(2) * P.y;
  denominator = ModP(denominator);

  BigInt lambda = numerator * Inverse(denominator);
  lambda = ModP(lambda);

  r.x = (lambda ^ BigInt(2)) - (BigInt(2) * P.x);
  r.x = ModP(r.x);

  r.y = (lambda * (P.x - r.x)) - P.y;
  r.y = ModP(r.y);

  return r;
}
Пример #4
0
Point ECDSA::Add(Point P, Point Q) {
  Point r;

  BigInt numerator = Q.y - P.y;
  numerator = ModP(numerator);

  BigInt denominator = Q.x - P.x;
  denominator = ModP(denominator);

  BigInt lambda = numerator * Inverse(denominator);
  lambda = ModP(lambda);

  r.x = (lambda ^ BigInt(2)) - P.x - Q.x;
  r.x = ModP(r.x);

  r.y = (lambda * (P.x - r.x)) - P.y;
  r.y = ModP(r.y);

  return r;
}