int roman_numeral_to_integer(const char* roman) { int result = 0; int length = strlen(roman); for (int i = 0; i < length; i++) { if (i + 1 < length && digit_to_int(roman[i]) < digit_to_int(roman[i + 1])) { result -= digit_to_int(roman[i]); } else { result += digit_to_int(roman[i]); } } return result; }
int integridade() { FILE *arq; arq = fopen("textoclaro.txt", "r+"); if (arq == NULL) { printf("Impossivel abrir o arquivo!\n"); } else { printf("Arquivo aberto com sucesso! (Integridade)\n"); } char c,ant ='0',qnt[10],ant2 ='0'; int conts=0,aux =0; //inicializando a vetor qnt while(aux<10) { qnt[aux] = '\0'; aux++; } aux =0; while((c=fgetc(arq)) != EOF) { if(c == 'i') { conts++; } if((ant== '%') && (ant2!='%')) { while(c !='%') { qnt[aux] = c; aux++; c=fgetc(arq); } } ant2 = ant; ant = c; } int digito,i; int numero=0, mult =1; while(aux >= 0) { aux--; digito = digit_to_int(qnt[aux]); numero = numero + digito*mult; mult = mult*10; } if(numero == conts) { return 1; } else { return 0; } fclose(arq); }
// parse binary, hex and decimal numbers BOOL parse_number(const uint8_t *str, uint8_t len, uint16_t *result) { uint8_t base = 10; uint8_t i; uint8_t c; uint8_t digit; *result = 0; for (i=0;i<len;i++) { c = str[i]; if (*result == 0) { if ((i == 0 || i == 1) && c == 'b') // 0b/b for binary { if (len < 2) return FALSE; base = 2; continue; } else if (i==0 && c == 'h') // h for hex { if (len < 2) return FALSE; base = 16; continue; } else if (i == 1 && c == 'x') // 0x for hex { if (len < 3) return FALSE; base = 16; continue; } } digit = digit_to_int(c); if (digit < base) *result = (*result) * base + digit; else return FALSE; } return TRUE; }
DMZ_INTERNAL void expiry_string_to_expiry_month_and_year(char *expiry_string, GroupedRects &group, int *expiry_month, int *expiry_year) { int month = -1; int year = -1; switch (group.pattern) { case ExpiryPatternMMsYY: if (expiry_string[0] != ' ' && expiry_string[1] != ' ' && expiry_string[3] != ' ' && expiry_string[4] != ' ') { month = digit_to_int(expiry_string[0]) * 10 + digit_to_int(expiry_string[1]); year = digit_to_int(expiry_string[3]) * 10 + digit_to_int(expiry_string[4]); } break; case ExpiryPatternMMs20YY: case ExpiryPatternXXsXXsYY: case ExpiryPatternXXsXXs20YY: case ExpiryPatternMMdMMsYY: case ExpiryPatternMMdMMs20YY: case ExpiryPatternMMsYYdMMsYY: default: break; } // http://support.celerant.com/celwiki/index.php/Reverse_expiration_date suggests that non-US cards // might sometimes reverse month and year. Since MMYY and YYMM are distinguishable as of 2013, // and since we're going to ignore dates in the past, let's swap ours accordingly. if (month > 12 && year > 0 && year <= 12) { int temp = month; month = year; year = temp; } // Only accept dates where month is in [1,12], // and the date is >= the current month/year, // and the year is within the next 5 years. (TODO: somehow determine whether 5 is a reasonable number) // Ignore valid dates if they're no later than the best date we've already found. int full_year = year + 2000; if (month > 0 && month <= 12 && (full_year > *expiry_year || ((full_year == *expiry_year) && month > *expiry_month))) { time_t now = time(NULL); struct tm *time_struct = localtime(&now); int current_year = time_struct->tm_year + 1900; int current_month = time_struct->tm_mon + 1; if (full_year < current_year + 5 && (full_year > current_year || (full_year == current_year && month >= current_month)) ) { *expiry_month = month; *expiry_year = full_year; } #if DMZ_DEBUG || CYTHON_DMZ else { // For current testing, which includes several expired cards, allow dates in the past. if (year > 60) { full_year= year + 1900; } if (full_year < current_year + 5) { *expiry_month = month; *expiry_year = full_year; } else { #if DEBUG_EXPIRY_CATEGORIZATION_RESULTS dmz_debug_print("%02d/%04d is a disallowed date.\n", month, full_year); #endif } } #endif } }