當前位置:首頁 » 編程語言 » c語言解碼程序

c語言解碼程序

發布時間: 2024-12-05 04:46:24

『壹』 用c語言實現算術編碼和解碼

Turbo c 2.0編譯通過

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#defineLENGTH100 /*字元串(編碼前或編碼後)的最大長度*/

/*編碼*/
voidencode(char*strsource);
/*解碼*/
voiddecode(char*strcode);

voidmain()
{
charcode[LENGTH]="BILLGATES";
encode(code);
printf("\nencodedstringis:%s\n",code);
decode(code);
printf("\ndecodedstringis:%s\n",code);
getch();
}
voidencode(char*strsource){
char*p=strsource,tmp[LENGTH]={'\0'},buffer[3];
while(*p){
itoa(*p++,buffer,10);
strcat(tmp,"%");
strcat(tmp,buffer);
}
strcpy(strsource,tmp);
}

voiddecode(char*strcode){
inti=0;
char*p,*s=strcode,tmp[LENGTH]={'\0'};
char*cSplit="%";
p=strtok(s,cSplit);
while(p)
{
tmp[i++]=atoi(p);
p=strtok(NULL,cSplit);
}
strcpy(strcode,tmp);
}

『貳』 C語言或C++編寫二維碼的解碼部分詳細的源代碼及說明

1、二維碼有很多種標准,可謹輪以控制存儲數據的信息量,也可以控制容錯的數據量[使得部分污損的二維碼可以被正常讀取。通常的做法是調用二維碼設計方提供的組件,如果是自己生成二維碼,應該可以生成可以看起來很像的東西。

2、常式:

<pre name="code" class="cpp">int Fb_QrDisp(int iPenX,int iPenY,QRcode*pQRcode)

{

T_PixelDatasg_tOriginPixelDatas;

T_PixelDatasg_tZoomPixelDatas;

//intiZoom;

inti;

g_tOriginPixelDatas.iWidth= pQRcode->width;

g_tOriginPixelDatas.iHeight=pQRcode->width;

g_tOriginPixelDatas.iLineBytes=g_tOriginPixelDatas.iWidth;

g_tOriginPixelDatas.aucPixelDatas= pQRcode->data;

/*

if(pQRcode->version< = 1)

{

iZoom= 2;

}

else

{

iZoom= 2;

}

g_tZoomPixelDatas.iWidth = pQRcode->width*iZoom;

g_tZoomPixelDatas.iHeight=pQRcode->width*iZoom;

g_tZoomPixelDatas.iLineBytes=g_tZoomPixelDatas.iWidth;

g_tZoomPixelDatas.aucPixelDatas= malloc(g_tZoomPixelDatas.iWidth* g_tZoomPixelDatas.iHeight);

if(g_tZoomPixelDatas.aucPixelDatas== NULL)

{

printf("g_tZoomPixelDatas->aucPixelDatasmalloc failed "神嘩);

return-1;

}

PicZoom(&g_tOriginPixelDatas,&g_tZoomPixelDatas);

#if 0

printf("g_tZoomPixelDatas.iWidth=%d,g_tZoomPixelDatas.iHeight=%d ", g_tZoomPixelDatas.iWidth,g_tZoomPixelDatas.iHeight);

for(i=0;i<(g_tZoomPixelDatas.iWidth*g_tZoomPixelDatas.iHeight);i++)

{

printf("0x%x,",g_tZoomPixelDatas.aucPixelDatas[i]);

}

printf(" ");

#endif

*/

Disp_FixelPic(iPenX,iPenY,&g_tZoomPixelDatas);

return 0;

}

因為stmf429運行起來後內存祥瞎信不夠,這里不用申請內存再擴充放大二維碼數據的方法,而是直接描點。所以這里注釋掉了放大部分。

『叄』 C語言對文件字元串進行解碼

#include<stdio.h>
main(){
FILE*fp1,*fp2;
chara[100];
charsecret[]="Kirschsaft!";
inti,j;
fp1=fopen("source.txt","r");
fp2=fopen("result.txt","w");
if(fp1==NULL||fp2==NULL)
return;
while(fgets(a,100,fp1)!=NULL){
for(i=0,j=0;a[i]!=' ';i++,j++){
if(j==11)
j=0;
if((int)a[i]>=32){
a[i]=a[i]^secret[j];
if((int)a[i]<32){
a[i]=a[i]+32;
}
}
}
for(;j>0&&j<11;j++,i++){
a[i]=secret[j];
}
a[i++]=' ';
a[i]='';
fprintf(fp2,"%s",a);
}
}

應該是限制高3位,使得每個字元的ASCII碼大於0010 0000,即32。

我的策略是如果做完異或之後的ASCII碼小於32就給他加32.

熱點內容
河池都安伺服器ip地址是什麼 發布:2025-08-20 16:00:13 瀏覽:873
做自媒體剪輯需要什麼配置的電腦 發布:2025-08-20 15:37:38 瀏覽:388
密碼法的立法目地是什麼 發布:2025-08-20 15:27:13 瀏覽:456
不小心刪除微信怎麼恢復聊天記錄安卓 發布:2025-08-20 15:27:05 瀏覽:449
車載安卓系統指的是什麼 發布:2025-08-20 15:23:47 瀏覽:713
安徽鯤鵬伺服器雲空間 發布:2025-08-20 15:19:37 瀏覽:790
怎樣刪除手機大存儲 發布:2025-08-20 15:10:36 瀏覽:270
android關閉 發布:2025-08-20 15:09:44 瀏覽:61
陸上公務艙選哪個配置 發布:2025-08-20 15:04:48 瀏覽:680
win10錯誤5拒絕訪問 發布:2025-08-20 15:03:52 瀏覽:261