Advertisement
akevintg

Pulsa Captcha (fork & pipe)

Nov 4th, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.87 KB | None | 0 0
  1. /*
  2. SOAL
  3. =========================================================================================================================
  4. Input :
  5. No Handphone [10-12], depan harus 08, kalo ketik exit dia keluar
  6. Pilih provider [XL || Telkomsel || Indosat] case TIDAK sensitif
  7. pilih pulsa [10000 || 25000 || 50000 || 100000]
  8. Masukan CAPTCHA (*) case sensitive
  9.  
  10. Output:
  11. Detail pemesanan
  12. ==================
  13. No HP : no hp dengan sensor 3 no terkahir
  14. Provider : pilihan provider//sudah di HURUF BESARKAN SEMUA
  15. Pulsa : Rp. pilihan pulsa,00
  16. No transaksi : [2 kata pertama merk Provider]+[3 digit no hp terakhir]+[2 kata pertama dari CAPTCHA di huruf kecilkan]
  17.  
  18. //format captca adalah random 2 huruf+no terakhir di no hp+2kata pertama provider HURUF BESAR
  19.  
  20. Contoh accepted input :
  21. No HP : 087840094200
  22. Provider : telKomsEL
  23. Pulsa : 50000
  24. Captcha (GF200XL) : GF200TE
  25.  
  26. Output :
  27. No HP : 087840094***
  28. Provider : TELKOMSEL
  29. Pulsa : Rp. 50000,00
  30. No Transaksi : TE200gf
  31.  
  32. PENJELASAN :
  33. input ->captcha, GF dari random 2 huruf, 200 dari 3 no belakang hp, XL kode provider
  34. output -> no hp di sensor 3 paling belakang
  35. provider di huruf besarkan semuanya
  36. pulsa ditambahkan Rp. ,00
  37. No transaksi, TE dari telkomsel, 200 3 no belakang, gf randomnya dikecilin hurufnya
  38.  
  39. *hint, ASCII A-Z itu 65-92;
  40.  
  41.  
  42. */
  43. #include <stdio.h>
  44. #include <ctype.h>
  45. #include <string.h>
  46. #include <time.h>
  47. #include <unistd.h>
  48. #include <stdlib.h>
  49.  
  50. struct data {
  51.     char no[15];
  52.     char provider[10];
  53.     int pulsa;
  54.     char captcha[10];
  55. };
  56.  
  57. int main(){
  58.     struct data cust;
  59.     pid_t pFork;
  60.     int pipes[2],i,j,flag;
  61.     char cpt[10];
  62.     if(pipe(pipes)<0){
  63.         printf("Error Pipe");
  64.         exit(1);
  65.     }
  66.     int r1,r2;
  67.     pFork=fork();
  68.     if(pFork==0){
  69.         printf("\nChild Process\n=========================\n\n");
  70.         do{
  71.             flag=0;
  72.             printf("No Handphone [10...12][08xxxxxx][exit to close]: ");
  73.             scanf("%s",cust.no);getchar();
  74.             if(strlen(cust.no)<10||strlen(cust.no)>12)
  75.                 flag=1;
  76.             if(cust.no[0]!='0'||cust.no[1]!='8')
  77.                 flag=1;
  78.             for(j=0;j<strlen(cust.no);j++){
  79.                 if(!isdigit(cust.no[j]))
  80.                     flag=1;
  81.             }
  82.             if(strcasecmp(cust.no,"exit")==0){
  83.                 printf("Program is Quiting\n");
  84.                 exit(1);
  85.             }
  86.         }while(flag==1);
  87.         do{
  88.             flag=0;
  89.             printf("Pilih Provide [XL || Telkomsel || Indosat]: ");
  90.             scanf("%s",cust.provider);getchar();
  91.             if(strcasecmp(cust.provider,"xl")!=0&&strcasecmp(cust.provider,"telkomsel")!=0&&strcasecmp(cust.provider,"indosat"))
  92.                 flag=1;
  93.         }while(flag==1);
  94.         do{
  95.             flag=0;
  96.             printf("Pilih Pulsa [10000 || 25000 || 50000 || 100000]: ");
  97.             scanf("%d",&cust.pulsa);getchar();fflush(stdin);
  98.             if(cust.pulsa!=10000&&cust.pulsa!=25000&&cust.pulsa!=50000&&cust.pulsa!=100000)
  99.                 flag=1;
  100.         }while(flag==1);
  101.         srand(time(NULL));
  102.         r1=rand()%26+65;
  103.         r2=rand()%26+65;
  104.         cpt[0]=r1;
  105.         cpt[1]=r2;
  106.         cpt[2]=cust.no[strlen(cust.no)-3];
  107.         cpt[3]=cust.no[strlen(cust.no)-2];
  108.         cpt[4]=cust.no[strlen(cust.no)-1];
  109.         cpt[5]=toupper(cust.provider[0]);
  110.         cpt[6]=toupper(cust.provider[1]);
  111.         cpt[7]='\0';
  112.         do{
  113.             flag=0;
  114.             printf("Masukan Captcha (%s)[case sensitive]: ",cpt);
  115.             scanf("%s",cust.captcha);getchar();
  116.             if(strcmp(cust.captcha,cpt)!=0)
  117.                 flag=1;
  118.         }while(flag==1);
  119.         close(pipes[0]);
  120.         write(pipes[1],(struct data*)&cust,sizeof(cust));
  121.     }
  122.     else if(pFork>0){
  123.         close(pipes[1]);
  124.         read(pipes[0],(struct data*)&cust,sizeof(cust));
  125.         printf("\nParent Process\n=========================\n\n");
  126.         char noTemp[10];
  127.         strncpy(noTemp,cust.no,strlen(cust.no)-3);
  128.         printf("No HP : %s***\n",noTemp);
  129.         printf("Provider : ");
  130.         for(j=0;j<strlen(cust.provider);j++)
  131.             printf("%c",toupper(cust.provider[j]));
  132.         printf("\nPulsa : Rp. %d,00\n",cust.pulsa);
  133.         printf("No Transaksi : %c%c%c%c%c%c%c\n",toupper(cust.provider[0]),toupper(cust.provider[1]),
  134.             cust.no[strlen(cust.no)-3],cust.no[strlen(cust.no)-2],cust.no[strlen(cust.no)-1],
  135.             tolower(cust.captcha[0]),tolower(cust.captcha[1]));
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement