int hex2(uint8_t **buffer, uint8_t *value) { uint8_t v; if ((hex1(buffer, &v)) < 0) { return -1; } *(value) = (v << 4); if ((hex1(buffer, &v)) < 0) { return -1; } *(value) |= v; return 0; }
static int parse_hex_color(color_t c, const char *s) { if (*s == '#') s ++; uint8_t h[2*COLOR_COUNT]; unsigned i = 0; while (i < 2*COLOR_COUNT) { int8_t x = hex1(s[i]); if (x < 0) break; h[i++] = x; } if (i >= 2*COLOR_COUNT) { for_color (i) c[i] = h[2*i] << 4 | h[2*i+1]; return 2*COLOR_COUNT; } if (i >= COLOR_COUNT) { for_color (i) c[i] = h[i] << 4 | h[i]; return COLOR_COUNT; } return -1; }
// File Operation Example void file_ex () { // Degree 163 Binary Field from fips186-2 use_NIST_B_163 (); EC_Domain_Parameters dp = NIST_B_163; ECPrivKey privKeyA (dp, OS2IP(SHA1("A's password"))); ECPubKey pubKeyA (privKeyA); DER derA1 (pubKeyA); std::ofstream key_outfile ("pubKeyA.key", std::ios::binary); if (!key_outfile) { std::cout << "Error can't open file!\n"; return; } key_outfile << derA1; key_outfile.close(); std::ifstream key_infile ("pubKeyA.key", std::ios::binary); if (!key_infile) { std::cout << "Error can't open file!\n"; return; } OCTETSTR derA2_v; char c; OCTET o; while (key_infile.get (c)) { o = (unsigned char)c; derA2_v.push_back (o); } std::cout << std::endl; key_infile.close(); DER derA2 (derA2_v); HexEncoder hex1 (derA1); HexEncoder hex2 (derA2); std::cout << "derA1: " << hex1 << std::endl; std::cout << "derA2: " << hex2 << std::endl; if (!(derA1.v == derA2.v)) { std::cout << "Error\n"; return; } else { std::cout << "OK\n"; } return; }
void loop() { static int8_t value=0; uint8_t n; // blink LED for(n=0; n<3; n++) { ledOn(); delay(200); ledOff(); delay(200); } uint8_t row,col; // display row an colun test initDisplay(); for(row=0; row<5; row++) { for(col=0; col<7; col++) { setRow(row); setCol(col); delay(100); } } // show hello _putchar('H'); showMatrix(200); _putchar('E'); showMatrix(200); _putchar('L'); showMatrix(400); _putchar('O'); showMatrix(200); //**************** key display example *************************** do { n=_getchar(); value=getKey(); _putchar(n); showLeds(value); } while(n!='i'); //**************** key sound display example *************************** tone(CH2_SPEAKERPIN, frequencyTable[0],50); do { n=_getchar(); value=getKey(); tone(CH2_SPEAKERPIN, frequencyTable[value],50); delay(50); _putchar(n); showLeds(value); } while(n!='i'); // key code test do { n=scanKey(); //initDisplay(); //setCol(0); //setRowPattern(n); if(n<0x10) hex1(n); else _putchar('n'); showLeds(n); showMatrix(100); //delay(1000); } while(n!=HASHKEY); }