導航:首頁 > 文檔加密 > 輸入字元加密為後四位

輸入字元加密為後四位

發布時間:2023-07-22 18:55:07

① c語言:有一行電文,按如下規律加密,將每個字母變為其後的第四個字母,非字母字元不變,電文從鍵盤輸入,

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

#define N 100
void main()
{
char a[N];
int i,len;

memset(a,'\0',N);//初始化數組a

printf("輸入電文\n");
gets(a);

len=strlen(a);

if(len>N)//如果輸入的電文超過定義數組定義長度,截取到數組定義長度
len=N;
//加密
for(i=0;i<len;i++)
{
if(isalpha(a[i]))//如果是字母
{
if(isalpha(a[i]+4))//+4不超出字母範圍
a[i]+=4;
else//超出字母範圍
a[i]=a[i]+4-26;

}
}

printf("加密後的電文\n");
puts(a);
printf("\n");
getchar();
}

② C語言字元串加密 後移四位 並最後輸入Y持續上一個過程 輸入N結束

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

intmain(intargc,char*argv[])
{
chars[50]={""};
scanf("%s",s);
inti;
intlen=strlen(s);
while(1)
{
for(i=0;i<len;i++)
{
intn;
if(s[i]>=65&&s[i]<=90)
{
n=s[i]+4;
if(n>90)
{
n=n-26;
}
s[i]=n;
}
elseif(s[i]>=97&&s[i]<=122)
{
n=s[i]+4;
if(n>122)
{
n=n-26;
}
s[i]=n;
}
}
printf(" %s 繼續嗎?(Y/N):",s);
charc;
fflush(stdin);
scanf("%c",&c);
if(c=='y'||c=='Y')
{
continue;
}
elseif(c=='n'||c=='N')
{
break;
}
}
return0;
}

③ 編寫一個簡單的加密程序:輸入四位整數,按照以下加密演算法處理後,生成加密後的四位整數輸出。 加密演算法:

//原理: a異或b異或b 等於 a

//b就是密碼

# include <windows.h>
int __stdcall wWinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPWSTR lpCmdLine, __in int nShowCmd )
{
int numInput[4] = {1, 2, 3, 4}; //輸入數據
int key[4] = {6, 2, 9, 8}; //密碼
int enp[4], disenp[4]; //加密與解密後的數據
for(int i = 0; i < 4; ++i)
{
enp[i] = numInput[i] ^ key[i];
disenp[i] = enp[i] ^ key[i];
}
wchar_t strDsp[56];
wsprintf(strDsp, L"原數據%d:%d:%d:%d", numInput[0], numInput[1], numInput[2], numInput[3]);
::MessageBox(::GetForegroundWindow(), strDsp, strDsp, 0);
wsprintf(strDsp, L"加密後%d:%d:%d:%d", enp[0], enp[1], enp[2], enp[3]);
::MessageBox(::GetForegroundWindow(), strDsp, strDsp, 0);
wsprintf(strDsp, L"解密後%d:%d:%d:%d", disenp[0], disenp[1], disenp[2], disenp[3]);
::MessageBox(::GetForegroundWindow(), strDsp, strDsp, 0);
return 0;
}

④ 編寫程序,將一個長度不超過100的字元串加密和解密。密碼規則:用原來的字母後面第4個字母代替原來的字母

首先是賦值錯誤,應該scanf("%s",str);
而不是把str[100]當首地址

其次輸入字元長度不一定是100,所以字元長度也要不確定,所以在判斷的時候應該
char lock(char str[])
{
int i;
for(i=0;i<=100&&str[i]!='\0';i++)
。。。

char unlock(char str[])
{
int j;
for(j=0;j<=100&&str[j]!='\0';j++)
。。。

閱讀全文

與輸入字元加密為後四位相關的資料

熱點內容
pdf少年時 瀏覽:948
兩個同名文件夾同步 瀏覽:625
拍照文件夾哪個好用 瀏覽:84
文件夾和書包 瀏覽:505
解壓歸檔拿登記證 瀏覽:218
去體驗解壓房 瀏覽:608
單片機一鍵中斷響應 瀏覽:641
唐浩明pdf 瀏覽:839
程序員土木 瀏覽:71
android如何與web伺服器交互 瀏覽:604
蘋果小風扇app怎麼下 瀏覽:951
杭州it程序員對身體好不好 瀏覽:534
高新區編程加盟找哪家 瀏覽:27
伺服器什麼樣的好賣 瀏覽:147
單片機原理及應用第二版例題答案 瀏覽:967
base64encoderjava 瀏覽:489
linux視頻轉換 瀏覽:701
linux與unixshell編程指南 瀏覽:138
vb6反編譯程序錯誤 瀏覽:126
伺服器弄掛有什麼影響 瀏覽:307