ช่วยแก้ไขโค้ดโปรแกรมภาษาซีหน่อยค่ะ T T ตอนนี้มืดมิดเหมือนจอcommand

พอดีต้องทำโปรเจคส่งอาจารย์ค่ะ ใช้ภาษาC โปรแกรมDEVC++ ต้องแปลงไปแปลงกลับจากอันเดิม เป็นเหมือนการเข้ารหัสและถอดรหัส

ตัวเข้ารหัสอันแรกค่ะ ส่งอาจารไปแล้วค่ะ เหลือแต่ตัวถอดรหัสที่กำลังเป็นปัญหาอยู่
ขั้นตอนการเข้ารหัสไม่มีอะไรเลยค่ะ มีแค่ ป้อนข้อความ text แล้วก็ป้อน keyword โดยเรียกใช้ฟังชั่น strstr() ของภาษาซี แล้วมันก็จะไปค้นตำแหน่งของคีย์เวิด แล้วก็นำตำแหน่งของคำจากคีย์เวิดไปแปลงเป็นเลขฐานสอง เช่น คำว่า pu อยู่ตำแหน่งที่8 แต่ในโค้ดเขียนให้ลดลงมาสองตำแหน่งก็จะเป็นตำแหน่งที่5 แทน พอแปลงเลข5เป็นเลขฐานสองได้ 101  //พอดีมันอัพรูปไม่ได้อ่ะค่ะ ขอโทษด้วยค่ะ

"อันนี้โค้ดตอนเข้ารหัสเสร็จไปแล้วค่ะ"
#include<stdio.h>
#include<string.h>
int main()
{
    /////////////////////input String and Searh Key Word////////////
    char keyword[20],str[80];  
    int location;
    printf("Enter your text :\n");
    gets(str);
    printf("\n");
    printf("Enter your characters or words: \n");
    gets(keyword);
    printf("\n");
    location = strstr(str,keyword)-str-2;   //nubtoilangjak'keyword'ma2tumnang
    if (location > 0)
             printf("");                  //maihaisadang value in 'location'
    else printf("Not Found!!!!!");    
     ////////////////////////decimaltobinary//////////////    
     int i, j;
     long dec;
     int bit[32];
     i = 0;
     printf("\n\t\t****************************************");          
     printf("\n\t\t\tEncrypted your Text: ");
     do{
          bit[i++] = location % 2;
          location = location / 2;
     }while (location > 0);

     for(j = i - 1; j >= 0; j--)
          printf("%d", bit[j]);
     printf("\n\t\t****************************************");
    printf("\n\n");
    return 0;
}

"ผลรัน command เข้ารหัส"
Enter your text: The computer security
Enter your charecter/keyword: pu
Searh result: 5
ENCRYPTED YOUR KEYWORD: 101
____________________________________________________________________________________
แต่ที่อยากให้ช่วยจริงๆคือตอนถอดรหัส คือตอนนี้ทำได้แค่นี้อ่ะค่ะ คือมันต้องทำยังไงให้ DECODE ได้ คีย์เวิดคำเดิมคำว่า "pu" หรือคำคีย์เวิดต่างๆที่เรากำหนดตอนเข้ารหัสอ่ะค่ะ รบกวนหน่อยนะคะ T T

ตอนนี้โค้ดถอดรหัสทำได้แค่นี้จริงๆค่ะ ทำต่อไม่เป็นเลย พิมอะไรก็error T T   ภาษาซีนะคะ

#include <stdio.h>
#include <string.h>

int main()
{
      long int binaryNumber,decimalNumber=0,j=1,remainder;
     //////////////////////////////INPUT_TEXT////////////////////////////////////
     char st[80];
     int location;
     printf("Enter your text: \n");
     gets(st);      
     printf("\n");
    ///////////////////////OUTPUT BINARY FROME KEYWORDS ////////////////////////
    printf("Encrypted your keywords binary: \n");
    scanf("%ld",&binaryNumber);
         remainder=binaryNumber;
        decimalNumber=decimalNumber+remainder*j;
    while(binaryNumber!=0){
        j=j*2;
        binaryNumber=binaryNumber/10;
    }
    printf("\n");
    printf("Equivalent decimal value: %ld",decimalNumber);            
      
    /////////////////////////////DECODE_KEYWORDS FROMTEXT//////////////////////////////
    printf("\n");
    printf("\n\t\t****************************************");  
    
    printf("\n\t\t\tDECODE YOUR KEYWORDS: ",decimalNumber);
    
     printf("\n\t\t****************************************");

     printf("\n\n");
     return 0;  
          
}

ตัวอย่าง DECODE ที่ต้องการคือแบบนี้ค่ะ
Enter your text : The computer security
Encrypted your keyword binary: 101
DECODE YOUR KEYWORDS: pu   //output ต้องออกมาแบบนี้ค่ะ ซึ่งจะออกมาตามตำแหน่งคีย์เวิดที่เราใส่เป็นเลขไบนารี ตอนนี้ยังทำไม่ได้เลยค่ะ

**รบกวนทุกท่านที่รู้หน่อยนะคะ หมดปญ.จริงๆค่ะ ถ้าแก้ไม่ได้ก็ตายแน่ๆ T T
แก้ไขข้อความเมื่อ
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่