Exemplo n.º 1
0
bool shaderProgram::loadProgramFromFile(const char *vertexFilename, const char *fragmentFilename) {
    std::string vertexSource = loadStringFromFile(vertexFilename);
    if (vertexSource.empty()) return false;

    std::string fragmentSource = loadStringFromFile(fragmentFilename);
    if (fragmentSource.empty()) return false;

    return loadProgramFromSource(vertexSource.c_str(), fragmentSource.c_str());
}
Exemplo n.º 2
0
 size_t replaceInFile(const std::string & filename, const std::string & oldstr, const std::string & newstr)
     {
     std::string s = loadStringFromFile(filename);
     size_t r = replace(s, oldstr, newstr);
     if (r) { saveStringToFile(filename, s, false); }
     return r;
     }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
    switch (message)    {
	case WM_CREATE: {
		database->reserve(50);
		initInterface();
		genb = CreateWindowA("BUTTON", loadStringFromFile("tech\\button").c_str(), WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_FLAT, 355, 260, 150, 75, hWnd, HMENU(ID_BUTTON_GEN), NULL, NULL); SendMessage(genb, WM_SETFONT, (WPARAM)hFont, (LPARAM)MAKELONG(TRUE, 0));
		right = CreateWindowW(L"BUTTON", L"←", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_FLAT, 325, 260, 30, 75, hWnd, HMENU(ID_BUTTON_RIGHT), NULL, NULL); SendMessage(right, WM_SETFONT, (WPARAM)hFont, (LPARAM)MAKELONG(TRUE, 0));
		left = CreateWindowW(L"BUTTON", L"→", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_FLAT, 505, 260, 30, 75, hWnd, HMENU(ID_BUTTON_LEFT), NULL, NULL); SendMessage(left, WM_SETFONT, (WPARAM)hFont, (LPARAM)MAKELONG(TRUE, 0));
	}
    case WM_COMMAND: {
			if ((HIWORD(wParam)==0)&&(LOWORD(wParam)==ID_BUTTON_GEN)) {
				database->push_back(hero());
				current_hero = database->size()-1;
				hdc = GetDC(hWnd);
				ResultOnScreen(hdc,hFont);
				ReleaseDC(hWnd, hdc);
			}
			if ((HIWORD(wParam) == 0) && (LOWORD(wParam) == ID_BUTTON_LEFT)) {
				if (current_hero >= 0 && current_hero < database->size()-1) {
					current_hero++;
					hdc = GetDC(hWnd);
					ResultOnScreen(hdc, hFont);
					ReleaseDC(hWnd, hdc);
				}
			}
			if ((HIWORD(wParam) == 0) && (LOWORD(wParam) == ID_BUTTON_RIGHT)) {
				if (current_hero > 0 && current_hero <= database->size()) {
					current_hero--;
					hdc = GetDC(hWnd);
					ResultOnScreen(hdc, hFont);
					ReleaseDC(hWnd, hdc);
				}
			}
			SetFocus(hWnd);
			InvalidateRect(hWnd, NULL, TRUE);
        }
        break;
	case WM_PAINT: {
			hdc = BeginPaint(hWnd, &ps);
			InterfaceOnScreen(hFont, hdc);
			ResultOnScreen(hdc, hFont);
			EndPaint(hWnd, &ps);
		}
        break;
	case WM_KEYDOWN:  if (wParam == VK_ESCAPE) { DestroyWindow(hWnd); } break;
	case WM_DESTROY: PostQuitMessage(0); break;
	default: { return DefWindowProc(hWnd, message, wParam, lParam); }  }
    return 0;
}
int main (int argc, char* argv[]){
	int i,start,end, strlength;
	int m[SIZE], c[SIZE];
	char text[SIZE];
	int rank, jumlahProc;
	int N, sigma_N, found;
	int p,q,e,d;
	int status_prima;
	loadStringFromFile("text.txt",text); //membaca text
    strlength=strlen(text);
    printf("banyak karakter : %i\n",strlength);
	MPI_Init (&argc, &argv);
	MPI_Status status;
	MPI_Comm_rank (MPI_COMM_WORLD, &rank); // baca id prosesor
	MPI_Comm_size (MPI_COMM_WORLD, &jumlahProc);  // baca banyak prosesor
	int RANKSIZE = strlength/(jumlahProc-1);
	int modRANKSIZE=strlength%(jumlahProc-1);
	
	/*if(modRANKSIZE!=0){
		printf("tidak diproses");
		MPI_Abort(MPI_COMM_WORLD,911);
	}*/
	if(rank==0){
		p=19;
		q=17;
		e=23;
		N=p*q;
		sigma_N=(p-1)*(q-1);
		status_prima=koprima(e,sigma_N);
		if(status_prima==1){
			for(i=0;i<SIZE;i++){
				m[i]=text[i];
			}
			MPI_Bcast (&e, 1, MPI_INT, 0, MPI_COMM_WORLD);
			MPI_Bcast (&N, 1, MPI_INT, 0, MPI_COMM_WORLD);
			MPI_Bcast (&m[0],strlength, MPI_INT, 0, MPI_COMM_WORLD);
			
			for (i=1; i<jumlahProc; i++){
				start= (i-1)*RANKSIZE;
				end=(i*RANKSIZE)-1;
				MPI_Send(&start,1,MPI_INT,i,0,MPI_COMM_WORLD);
				MPI_Send(&end,1,MPI_INT,i,0,MPI_COMM_WORLD);
			}
			for (i=1; i<jumlahProc; i++){
				start= (i-1)*RANKSIZE;
				MPI_Recv(&c[start],RANKSIZE,MPI_INT,i,0,MPI_COMM_WORLD,&status);
				printf("%d receive dari array enkripsi . Messagesource = %d\n", rank, status.MPI_SOURCE);
			}
			
			FILE* data;
			data=fopen("ENKRIPSI_RSA.txt","wb");
			for(i=0;i<strlength;i++){
				fprintf(data,"%i\n",c[i]);
			}
			fclose(data);
			
			d=kunci_rahasia(e,sigma_N);
			dekripsi(c,d,N,strlength,"DESKRIPSI_RSA.txt");
			
		}
	
	}
	else {
		MPI_Status status;
		MPI_Bcast (&e, 1, MPI_INT, 0, MPI_COMM_WORLD);
		MPI_Bcast (&N, 1, MPI_INT, 0, MPI_COMM_WORLD);
		MPI_Bcast (&m[0], strlength, MPI_INT, 0, MPI_COMM_WORLD);
		MPI_Recv(&start,1,MPI_INT,0,0,MPI_COMM_WORLD,&status);
		MPI_Recv(&end,1,MPI_INT,0,0,MPI_COMM_WORLD,&status);
		printf("%d receive vaiabel e = %d dan N = %d dari induk\n",e,N,rank);    
		printf("start : %d",start);
		printf("end : %d",end);
		for(i=start;i<=end;i++){
			c[i]=BigMod(m[i],e,N);
			printf("rank ke%i %i %i\n ",rank,i,m[i]);
		}
		MPI_Send(&c[start],RANKSIZE,MPI_INT,0,0,MPI_COMM_WORLD);
	}

	MPI_Finalize();
	return 0;
}