void ByteUtil::InvertBitInByteData(byte *byteData, int countBits, int indexBit) { int countBytes = GetByteLenForDataLen(countBits); int indexByte = static_cast<int>( floor(static_cast<double>( indexBit / BYTE_BIT_LEN )) ); int posBitInByte = indexBit % BYTE_BIT_LEN; byte &b = byteData[indexByte]; InvertBit(b, posBitInByte); };
void TransferImageData(XImage *source, XImage *destination) { Position x, y; for (x = 0; x < min(source->width, destination->width); x++) for (y = 0; y < min(source->height, destination->height); y++) if (GetBit(source, x, y) != GetBit(destination, x, y)) InvertBit(destination, x, y); }
void main(void) { int i,j,k,e; unsigned long int gword,ini_gword; ini_gword=MakeGolayWord(1234); ini_gword=0; printf("\n Single errors"); for(j=0;j<23;j++) { gword=ini_gword; InvertBit(&gword,j); e=CorrectGolayCode(&gword); if((e!=1)||(gword!=ini_gword)) printf("\nError!"); } printf("\n Double errors"); for(i=0;i<23;i++) { for(j=i+1;j<23;j++) { gword=ini_gword; InvertBit(&gword,i); InvertBit(&gword,j); e=CorrectGolayCode(&gword); if((e!=2)||(gword!=ini_gword)) printf("\nError!"); } } printf("\n Triple errors"); for(k=0;k<23;k++) { for(i=k+1;i<23;i++) { for(j=i+1;j<23;j++) { gword=ini_gword; InvertBit(&gword,k); InvertBit(&gword,i); InvertBit(&gword,j); e=CorrectGolayCode(&gword); if((e!=3)||(gword!=ini_gword)) printf("\nError!"); } } } }
XImage * ConvertToBitmapImage(BitmapWidget BW, XImage *image) { XImage *bitmap_image; char *data; Position x, y; data = CreateCleanData(Length(image->width, image->height)); bitmap_image = CreateBitmapImage(BW, data, (Dimension) image->width, (Dimension) image->height); for (x = 0; x < min(image->width, bitmap_image->width); x++) for (y = 0; y < min(image->height, bitmap_image->height); y++) if ((XGetPixel(image, x, y) != 0) != GetBit(bitmap_image, x, y)) InvertBit(bitmap_image, x, y); return bitmap_image; }
int main() { int ret = 0; size_t len = STR_LEN; char E[STR_LEN], D[STR_LEN], N[STR_LEN]; uchar source[MSG_LEN]; uchar encrypted[MSG_LEN], decrypted[MSG_LEN]; // Buffers public_key pub; private_key priv; MPI_CHK(rsa_generate_keys(65537, pub, priv, 1024)); MPI_CHK(mpi_write_string(&pub.e, 10, E, &len)); len = STR_LEN; MPI_CHK(mpi_write_string(&pub.n, 10, N, &len)); len = STR_LEN; MPI_CHK(mpi_write_string(&priv.d, 10, D, &len)); printf("e = %s\nd = %s\nn = %s\n", E, D, N); printf("Enter message to encrypt:\n"); scanf("%[^\n]", source); len = strnlen((const char *)source, MSG_LEN) + 1; // Length of string + zero-char try { MPI_CHK(rsa_encrypt_block(source, len, encrypted, MSG_LEN, pub)); print_buffer("Encrypted", encrypted, MSG_LEN); MPI_CHK(rsa_decrypt_block(encrypted, MSG_LEN, decrypted, MSG_LEN, priv)); print_buffer("Decrypted", decrypted, MSG_LEN); MPI_CHK(rsa_sign_block(source, len, encrypted, MSG_LEN, priv)); print_buffer("Signature", encrypted, MSG_LEN); MPI_CHK(rsa_check_block(encrypted, MSG_LEN, decrypted, MSG_LEN, pub)); print_buffer("Preimage", decrypted, MSG_LEN); source[0] = InvertBit(source[0], 2); printf("Corrupted:\n%s\n\n", source); MPI_CHK(rsa_sign_block(source, len, encrypted, MSG_LEN, priv)); print_buffer("Signature of corrupted", encrypted, MSG_LEN); } catch (char *e) { printf("Error: %s\n", e); } cleanup: mpi_free(&pub.e); mpi_free(&priv.d); mpi_free(&priv.n); return ret; }
void main() { char j, a; unsigned int *seed; backupPageZero(); GenerateTables(); DiscLoad("FONT.BIN"); // testing //sedoric("!LOAD(\"TEAM.BIN\")"); //cls(); #ifdef debug printf("char : %d, short %d, int %d, long %d, float %d\n", sizeof(char), sizeof(short), sizeof(int), sizeof(long), sizeof(float)); printf("taper sur une touche pour continuer\n"); a = (char)getchar(); #endif io_needed = 1; loadCharacters(); #ifdef debug printf("taper sur une touche pour continuer\n"); a = (char)getchar(); #endif loadLaby(); if (ca==0) { if (c[x+y*XMAX] != 0) { unsigned char nb = 255; // un coffre ou un combat a été fini char cas = c[x+y*XMAX]; if (cas>=21 && cas<=28) nb = cas - 21; else if (cas >=30 && cas <= 50) nb = cas - 30 + 8; // les 8 premiers bits stockent les coffres if (nb < 40) { SetBit(combats_coffres[ville-1], nb); //printf("Coffre ou Combat %d fini!\n", nb); c[x+y*XMAX] = 0; } } } #ifdef debug for (a=0; a<8; a++) for (j=0; j<40; j++) if(TestBit(combats_coffres[a], j)) printf("Bit %d is set\n", j); // testing // SetBit(combats_coffres[ville-1], 0); #endif printf("Taper sur une touche pour continuer\n"); get(); seed = (unsigned int *) 630; // timer srand(*seed); #ifdef debug printf("timer vaut %d\n", *seed); printf("alea vaut %d\n", rand()); printf("taper sur une touche pour continuer\n"); a = (char)getchar(); #endif // Sedoric(command2); // 330 CASE=C(X,Y) prep(); drawLaby(); ca = c[x+y*XMAX]; // manageCell(); // 320 GOSUB 500:GOSUB 1000 while(1) { // 380 GET A$ //a = (char)getchar(); //printf("x=%d, y=%d, s=%d ca=%d\n", x,y,s,ca); a = get(); switch(a) { //#ifdef debug case 'F': // pour debug case 'f': // 390 IF A$="F" THEN END a = 'F'; text(); io_needed = 1; saveCharacters(); restorePageZero(); printf("sauvegarde ok\n"); SwitchToCommand("!DIR"); // évite une erreur bizarre return; break; //#endif case ' ': // 400 IF A$=" "AND F(1)>1 AND F(1)<7 THEN GOSUB 3000:GOTO 330 if(f[0]>1&&f[0]<7) { #ifdef debug for (j=0;j<4;j++) { printf("cle(%d,%d) = %d ", 3, j, cles[3][j]); } #endif // 3000 REM ClÈ // 3010 IF F(1)=2 THEN 3030 // 3020 IF CLEF(VIL,(F(1)-2))=0 THEN ZAP:PRINT TX$(4):GOTO 3050 // 3030 F(1)=0:GOSUB 600:PING // 3050 RETURN if (f[0] == 2) { f[0]=0; forward(); ping(); // on avance deux fois prep(); printf("On passe la porte\n"); wait(180); drawLaby(); forward(); } else { ////// MODIF Maximus ******* if(cles[ville-1][f[0]-3]==0) { zap(); printf("Ou est la cl{ ?\n"); } else { #ifdef debug printf("Porte %d cle(%d,%d) %d ", f[0], ville-1, (f[0]-3), cles[ville-1][f[0]-3]); a = (char)getchar(); #endif InvertBit(&dedans,f[0]-3); f[0]=0; forward(); ping(); // on avance deux fois prep(); printf("On passe la porte\n"); wait(180); drawLaby(); forward(); } } } break; case 'I': case 'i': case 'Z': case 'z': // 410 IF A$="I" OR A$="i" THEN GOSUB 600:GOTO 330 forward(); break; case 'J': case 'j': case 'Q': case 'q': // 420 IF A$="J" OR A$="j" THEN S=S-1:IF S=0 THEN S=4 s--; if(s<0) s=3; prep(); drawLaby(); break; case 'L': case 'l': case 'D': case 'd': // 430 IF A$="L" OR A$="l" THEN S=S+1:IF S=5 THEN S=1 s++; if(s>3) s=0; prep(); drawLaby(); break; case 'C': case 'c': // 435 IF A$="C" THEN GOTO 21000 text(); io_needed = 1; saveCharacters(); restorePageZero(); SwitchToCommand("CAMP"); break; //#ifdef debug case 'A': case 'a': printf("alea vaut %d\n", rand()); break; case 'K': case 'k': for (j=0;j<4;j++) { cles[ville-1][j] = !cles[ville-1][j]; } break; case 'V': case 'v': text(); io_needed = 1; saveCharacters(); restorePageZero(); SwitchToCommand("VILLE"); break; //#endif default: puts("I:avance, J:droite, L:gauche\nESPACE: ouvrir porte"); wait(200); } // 450 GOTO 300 } }