/* * Create random device datas */ void initArrayDeviceData(unsigned char *arrCharDevice, int row, int col) { int i, j; unsigned short id = 0; if(!arrCharDevice || row<0 || col<0) { return; } for(i=0; i<row; i++,id++) { unsigned int size; unsigned char *tmp = arrCharDevice; convertToChar(arrCharDevice,&id,0,ID_SIZE); //copy id to array arrCharDevice+=ID_SIZE; //point to the next position /* * generate random name */ *arrCharDevice++= rand()%('Z' - 'A') + 'A'; for(j=0; j<NAME_SIZE-2; j++) { *arrCharDevice++=rand()%('z'-'a') + ('a'); } *arrCharDevice++ = '\0'; /* * generate random size between (2^0 -> 2^3)*64 */ size = (unsigned int) ( pow(2, (rand()%4)) * 64 ); convertToChar(arrCharDevice,&size,0,SIZE_SIZE); arrCharDevice+=SIZE_SIZE; } }
BigNumber::operator const char *const() { if(_stringFormat == NULL) { _stringFormat = convertToChar(); } return _stringFormat; }
/** * Release a key. This will print the pressed key in the widget (if possible) * * @param evnt The SDL event. */ void TextInputWidget::keyRelease(SDL_KeyboardEvent evnt) { if (evnt.keysym.sym == SDLK_BACKSPACE) { if (fText.length() > 0) fText = fText.erase(fText.length() - 1, 1); } else if (char* c = convertToChar(evnt.keysym.sym, evnt.keysym.mod)) { fText += *c; delete c; } fLabelWidget->setLabel(fText); }
void rsaDecrypt(rsapvk_t k, rsaem_t c, rsadm_t *m) { int i; // Decryption for (i=0; i<c.size; i++) mpz_powm(c.mess[i], c.mess[i], k.pvk, k.n); // String transformation m->mess = convertToChar(c.mess, c.size, k.k, &i); m->size = i; }
void API::request(std::string url,HttpRequest::Type type){ HttpRequest* request = new HttpRequest(); request->setUrl(url.c_str()); request->setRequestType(type); request->setResponseCallback([this](HttpClient* client, HttpResponse* response){ char* strRpns = convertToChar(response); this->receiveRequest(strRpns); }); request->setTag("request test1"); HttpClient::getInstance()->send(request); request->release(); }
int main() { srand(time(NULL)); unsigned char arrCharDevice[MAX_DEVICE][DEVICE_SIZE]; unsigned char chDevice[] = {0xb,0x0,'F','S','o','f','\0',0x0,0x1,0x0,0x0}; int i,j; device **ppd; device *tmp; linkedlist ll; initializeLL(&ll); //initialize linkedlist initArrayDeviceData(arrCharDevice, MAX_DEVICE, DEVICE_SIZE); //create data array of device ppd = initArrayDevice(arrCharDevice, MAX_DEVICE, DEVICE_SIZE); //create array of device for(i=0; i<MAX_DEVICE; i++) { printDevice(*(ppd+i)); addFirst(&ll, *(ppd+i)); //insert device into linkedlist } FL; printLL(&ll); tmp = (device*)chDevice; FL;printDevice(tmp); insertElement(&ll, tmp, 5); //insert above device into linkedlist FL;printLL(&ll); rmElement(&ll,4); //remove element from linkedlist FL;printLL(&ll); free(tmp); freeLL(&ll); freeArrayDevice(&ppd, MAX_DEVICE); unsigned short asdf = 0xF0AA; unsigned char *asda = (char*)malloc(sizeof(asdf)); FL; PRINT_HEX(asdf); EL; printf("%X", asdf&0xff); EL; convertToChar(asda, &asdf, 0, sizeof(short)); FL; PRINT_HEX(*asda); SP; PRINT_HEX(*(asda+1)); EL; PRINT_UINT(sizeof(aaa)); EL; return 0; }
void egDecrypt(egpvk_t k, egem_t c, egdm_t *m) { int i; mpz_t tmp, inv; mpz_init(tmp); mpz_init(inv); mpz_powm(tmp, c.y1, k.a, k.p); mpz_invert(inv, tmp, k.p); for (i=0; i<c.size; i++) { // Decryption mpz_mul(c.y2[i], c.y2[i], inv); mpz_mod(c.y2[i], c.y2[i], k.p); } m->m = convertToChar(c.y2, c.size, k.k, &i); m->size = i; mpz_clear(tmp); mpz_clear(inv); }
int main(int argc, char * argv[]) { if (argc < 2) { printf("You should provide at least the name of the input image!\n"); return -1; } Choice processingType; switch (argc) { case 2: processingType = FREEIMAGE; printf("Applying FREEIMAGE...\n"); break; case 3: processingType = PITIE; printf("Applying PITIE...\n"); break; case 4: processingType = PITIE; printf("Applying PITIE...\n"); break; case 5: processingType = GOOCH; printf("Applying GOOCH...\n"); break; default: processingType = NONE; printf("Do not know what processing to apply !\n"); return -1; } //Buffer for the new file names char strNewFileName[0x100]; //Load and verify that input image is a True-Color one KImage *pImage = new KImage(argv[1]); if (pImage == NULL || !pImage->IsValid() || pImage->GetBPP() != 24) { printf("File %s does is not a valid True-Color image.\n", argv[1]); return -2; } if (processingType == GOOCH) { Color2Gray * clr2Gray = new Color2Gray(pImage); if (!clr2Gray) { printf("Could not allocate class Color2Gray. \n"); return -1; } char buffer[1000]; memset(buffer, 0, 1000); char * charpointer = new char[1000]; convertToChar(argv[2], &charpointer); strcat(buffer, charpointer); strcat(buffer, " "); convertToChar(argv[3], &charpointer); strcat(buffer, charpointer); strcat(buffer, " "); convertToChar(argv[4], &charpointer); strcat(buffer, charpointer); //convert image with GOOCH algorithm KImage *pImageColor2Gray = clr2Gray->localC2G(buffer); sprintf(strNewFileName, "%s_GoochGray_%s_%s_%s.png", argv[1], argv[2], argv[3], argv[4]); pImageColor2Gray->SaveAs(strNewFileName, SAVE_PNG_DEFAULT); //convert image with BASIC algorithm KImage *pImageBasicGray = clr2Gray->localC2G(buffer, Color2Gray::BASIC_GREY); sprintf(strNewFileName, "%s_BasicGray.png", argv[1]); pImageBasicGray->SaveAs(strNewFileName, SAVE_PNG_DEFAULT); } else if (processingType == PITIE) { KImage *paletteImage = new KImage(argv[2]); if (paletteImage == NULL || !paletteImage->IsValid() || paletteImage->GetBPP() != 24) { printf("Cannot perform Color Grading. \n"); printf("File %s is not a valid True-Color image.", argv[2]); return -2; } ColorTransfer * Pitie = NULL; if (argc == 4) { char * pEnd = NULL; long int iterations = strtol(argv[3], &pEnd, 10); if (iterations == 0L) { printf("Invalid third argument for Pitie Color Grading.\n"); printf("Provide a valid iterations number or accept the default value 10.\n"); return -2; } Pitie = new ColorTransfer(pImage, paletteImage, iterations); } else { Pitie = new ColorTransfer(pImage, paletteImage); } assert(Pitie); KImage * recoloredImage = Pitie->applyRecoloring(); assert(recoloredImage); removeExtension(argv[1]); argv[2] = removeFolder(argv[2]); removeExtension(argv[2]); sprintf(strNewFileName, "%s%s_Pitie.png", argv[1], argv[2]); printf("Result image saved to: %s\n", strNewFileName); recoloredImage->SaveAs(strNewFileName, SAVE_PNG_DEFAULT); } else if (processingType == FREEIMAGE) { //Convert to grayscale and then BlackAndWhite KImage *pImageGrayscale = pImage->ConvertToGrayscale(); //Don't forget to delete the original, now useless image delete pImage; //Verify conversion success... if (pImageGrayscale == NULL || !pImageGrayscale->IsValid() || pImageGrayscale->GetBPP() != 8) { printf("Conversion to grayscale was not successful!"); return -3; } //... and save grayscale image sprintf(strNewFileName, "%s_grayscale.TIF", argv[1]); pImageGrayscale->SaveAs(strNewFileName, SAVE_TIFF_LZW); //Request direct access to image pixels in raw format BYTE **pDataMatrixGrayscale = NULL; if (pImageGrayscale->BeginDirectAccess() && (pDataMatrixGrayscale = pImageGrayscale->GetDataMatrix()) != NULL) { //If direct access is obtained get image attributes and //start processing pixels int intWidth = pImageGrayscale->GetWidth(); int intHeight = pImageGrayscale->GetHeight(); //Create binary image KImage *pImageBinary = new KImage(intWidth, intHeight, 1); if (pImageBinary->BeginDirectAccess()) { //Apply a threshold at half the grayscale range (0x00 is Full-Black, 0xFF is Full-White, 0x80 is the Middle-Gray) for (int y = intHeight - 1; y >= 0; y--) for (int x = intWidth - 1; x >= 0; x--) { //You may use this instead of the line below: // BYTE PixelAtXY = pImageGrayscale->Get8BPPPixel(x, y) BYTE &PixelAtXY = pDataMatrixGrayscale[y][x]; if (PixelAtXY < 0x80) //...if closer to black, set to black pImageBinary->Put1BPPPixel(x, y, false); else //...if closer to white, set to white pImageBinary->Put1BPPPixel(x, y, true); } //Close direct access pImageBinary->EndDirectAccess(); //Save binarized image sprintf(strNewFileName, "%s_Black_and_White.TIF", argv[1]); pImageBinary->SaveAs(strNewFileName, SAVE_TIFF_CCITTFAX4); //Don't forget to delete the binary image delete pImageBinary; } else { printf("Unable to obtain direct access in binary image!"); return -3; } //Close direct access pImageGrayscale->EndDirectAccess(); delete pImageGrayscale; } else { printf("Unable to obtain direct access in grayscale image!"); return -4; } } //Return with success return 0; }
bool CTastaturGER::createString(int iKeyID) { char cToAdd = convertToChar(iKeyID); if (cToAdd == '`' && !bStrichLinks){ bStrichLinks = true; return true; } if (cToAdd == '´' && !bStrichRechts){ bStrichRechts = true; return true; } if (cToAdd == '^' && !bDach){ bDach = true; return true; } if (bStrichLinks){ switch (cToAdd) { case 'a': cToAdd = 'à'; ULDebug("a"); break; case 'e': cToAdd = 'è'; break; case 'i': cToAdd = 'ì'; break; case 'o': cToAdd = 'ò'; break; case 'u': cToAdd = 'ù'; break; case 'A': cToAdd = 'À'; break; case 'E': cToAdd = 'È'; break; case 'I': cToAdd = 'Ì'; break; case 'O': cToAdd = 'Ò'; break; case 'U': cToAdd = 'Ù'; break; default: cToAdd = '`'; break; } sLeseString += cToAdd; bStrichLinks = false; return true; } if (bStrichRechts){ switch (cToAdd) { case 'a': cToAdd = 'á'; break; case 'e': cToAdd = 'é'; break; case 'i': cToAdd = 'í'; break; case 'o': cToAdd = 'ó'; break; case 'u': cToAdd = 'ú'; break; case 'A': cToAdd = 'Á'; break; case 'E': cToAdd = 'É'; break; case 'I': cToAdd = 'Í'; break; case 'O': cToAdd = 'Ó'; break; case 'U': cToAdd = 'Ú'; break; default: cToAdd = '´'; break; } bStrichRechts = false; sLeseString += cToAdd; return true; } if (bDach){ switch (cToAdd) { case 'a': cToAdd = 'â'; break; case 'e': cToAdd = 'ê'; break; case 'i': cToAdd = 'î'; break; case 'o': cToAdd = 'ô'; break; case 'u': cToAdd = 'û'; break; case 'A': cToAdd = 'Â'; break; case 'E': cToAdd = 'Ê'; break; case 'I': cToAdd = 'Î'; break; case 'O': cToAdd = 'Ô'; break; case 'U': cToAdd = 'Û'; break; default: cToAdd = '^'; break; } bDach = false; sLeseString += cToAdd; return true; } if (cToAdd == 10) { /*char tab2[1024]; strcpy(tab2, sLeseString.c_str()); ULDebug(tab2);*/ //sLeseString = ""; return false; } if (cToAdd == 24){ return true; //Taste Ohne Belegung = nix. } if (cToAdd == 8) { if (sLeseString.size() > 0) sLeseString.resize(sLeseString.size() - 1); return true; } sLeseString += cToAdd; return true; }
char TDataToChar(const TData *context) { if (context) return convertToChar(context->data, context->type); return 0; }
/** * @brief Check is a button is pressed on the keypad * @param None * @retval None */ char readKeypad(void) { int row = 0; int col = 0; /* the keyLock prevent a button to be triggered more than once when it is pushed only once */ if(keyLock){ /* check if a button is pressed and in which row the button is */ if (HAL_GPIO_ReadPin(GPIOC, col1) == GPIO_PIN_RESET){ debounce++; /* debounce for button pressed */ if(debounce > 400){ keyLock = 0; col = 1; row = findRow(); a = convertToChar(col, row); //printf("%c\n", a); return a; } } else if (HAL_GPIO_ReadPin(GPIOC, col2) == GPIO_PIN_RESET){ debounce++; /* debounce for button pressed */ if (debounce > 400){ keyLock = 0; col = 2; row = findRow(); a = convertToChar(col, row); //printf("%c\n", a); return a; } } else if (HAL_GPIO_ReadPin(GPIOC, col3) == GPIO_PIN_RESET){ debounce++; /* debounce for button pressed */ if (debounce > 400) { keyLock = 0; col = 3; row = findRow(); a = convertToChar(col, row); //printf("%c\n", a); return a; } } } else{ /* debounce for when the button is depressed */ if( HAL_GPIO_ReadPin(GPIOC, col1) == GPIO_PIN_SET && HAL_GPIO_ReadPin(GPIOC, col2) == GPIO_PIN_SET && HAL_GPIO_ReadPin(GPIOC, col3) == GPIO_PIN_SET){ debounce--; } /* unlock the keypad after the button press */ if(debounce < 0){ keyLock = 1; } } return 'n'; }