導航:首頁 > 文檔加密 > 大寫字母加密編程

大寫字母加密編程

發布時間:2022-08-22 21:28:21

1. C語言 簡單對字母進行加密

1、在我們的編輯頁面輸入以下代碼。

2. C語言題編程實現對鍵盤輸入的大寫英文字母進行加密。字母

#include<stdio.h>
#include<ctype.h>
intmain()
{inti;
chars[200];
gets(s);
for(i=0;s[i];i++)
if(isalpha(s[i]))
{s[i]+=3;
if(s[i]%0x20>26)s[i]-=26;
}
puts(s);
return0;
}

3. C語言設計一個用簡單的加密程序,即用字母替換的方式加密,程序運行中發現問題,求解釋。

原因就是char是1個位元組的,你不能超過127(hi,樓上的,不是128哦,是-128~127不要誤人子弟),你到後面的vwxyz已經溢出,所以是亂碼。
我的解決方法就很簡單,就是換成unsigned char 數組,這樣取值范圍增大到(0~255)就可以了,既簡單又不破壞原有的結構

還有
else if(str[i]<'a')
{
str[i]+=26;
}
這句話是廢話,可以刪掉

我修改過的版本
#include <stdio.h>
#include <string.h>
#include <ctype.h>

void EncodeString(unsigned char *str,int key)
{
int length,i;//length為傳入字元串長度,i用作循環計數器
length=strlen(str);
for(i=0;i<length;i++)//對字元串中的每個字元依次進行加密
{
if(isupper(str[i]))//對大寫字母加密
{
str[i]+=key%26;
if(str[i]>'Z')
{
str[i]-=26;
}

}
else if(islower(str[i]))//對小寫字母加密
{
str[i]+=key%26;
if(str[i]>'z')
{
str[i]-=26;
}

}

}
}

void main()
{
unsigned char arr[50],buffer;//arr[50]用來接收字元串信息,buffer用來接收緩沖區中的回車
int key;//key為加密秘鑰
printf("This program encodes messages using a cyclic cipher.\n");
printf("To stop, enter 0 as the key.\n");
while(1)//程序一直運行,直到輸入密鑰0為止
{
printf("Enter the key: ");
scanf("%d",&key);
scanf("%c",&buffer);
if(0==key)
{
break;//輸入密鑰為0,則退出程序
}
printf("Enter a message: ");
scanf("%s",arr);
scanf("%c",&buffer);
EncodeString(arr,key);
printf("Encoded message: %s\n",arr);
}
}

4. 用循環語句輸出26個大寫字母加序數5循環加密

下面輸出 26個大寫字母 加序數5循環加密
每行輸出: 原字母,加密後的字母,加密後的一個byte里存放的十六進制。
#include <stdio.h>
int main()
{
int i;
for (i=0;i<26;i++)
printf("%c %c %#x\n",'A'+i,'A'+(i+5)%26,'A'+(i+5)%26);
return 0;
}

A F 0x46
B G 0x47
C H 0x48
D I 0x49
E J 0x4a
F K 0x4b
....
U Z 0x5a
V A 0x41
W B 0x42
X C 0x43
Y D 0x44
Z E 0x45

5. C語言對字元進行加密

if(e>='A'&&e<='W')//
e+=3;
elseif(e>='X'&&e<='Z')
e-=23;
else
{
...//donotencryptordosomethingelse
}

6. C++ 編寫一個程序,將一個包含大小寫字母的純字母明文串轉換為純大寫字母的加密串輸出。

#include <iostream>
using namespace std;

int i;

void main(void)
{
void process(char s[],char s1[]);
void show(char s[],char s1[]);
char s[20];
char s1[20];
process(s,s1);
show(s,s1);
}
void process(char s[],char s1[])
{
i=0;
while ((s[i]=getchar())!='\n'&&i<20)
{
if (s[i]>='A' && s[i]<='Z')
{
s1[i]=s[i]+3;
if (s1[i]>'Z' && s1[i]<='Z'+3)
s1[i]=s1[i]-26;
}
else
{
s1[i]=s[i]-29;
if (s1[i]>'Z'&& s1[i]<='Z'+3)
s1[i]=s1[i]-26;
}
i++;
}
}
void show(char s[],char s1[])
{
int j;
for(j=0; j<=i; j++)
cout<<s[j];
cout<<endl;
for(j=0; j<=i; j++)
cout<<s1[j];
cout<<endl;
}

7. c語言對大寫英文字母加密

#include <stdio.h>
#include <string.h>
int main()
{
char passwd[100],encrypted[100];
int i,j,k,t,move;
while(1)
{
printf("Enter message to be encrypted:");

gets(passwd);

move=3;
for(i=0; i<strlen(passwd); i++)
{
if(passwd[i] >= 'A' && passwd[i] <= 'Z')
{

passwd[i] = ((passwd[i]-'A')+move)%26+'A';

} else if(passwd[i] >= 'a' && passwd[i] <= 'z')
{

passwd[i] = ((passwd[i]-'a')+move)%26+'a';

}

}

printf("%s",passwd);

printf("\n");

}
return 0;
}
這道題實際上就是C語言版的凱撒加密(字母往後面移動1-25之間的任意一位數)

閱讀全文

與大寫字母加密編程相關的資料

熱點內容
ubuntu1404安裝php 瀏覽:628
lua能編譯嗎 瀏覽:106
思仙怎麼看伺服器 瀏覽:656
php微信圖片防盜鏈 瀏覽:796
安卓1怎麼讀音 瀏覽:287
農業app怎麼開通快捷支付 瀏覽:908
pythonredisdict 瀏覽:383
如何攻擊別人網賭伺服器 瀏覽:878
隱私與應用加密的圖案密碼 瀏覽:34
陳情令王一博解壓 瀏覽:35
c編譯器使用說明 瀏覽:703
鄭州前端程序員私活有風險嗎 瀏覽:14
小型螺桿機壓縮機 瀏覽:518
成人解壓最好的方法 瀏覽:50
最小製冷壓縮機 瀏覽:490
xampp支持python 瀏覽:367
深圳周立功單片機 瀏覽:61
圓上點與點之間角度演算法 瀏覽:869
怎麼知道微信關聯了哪些app 瀏覽:702
android事件驅動 瀏覽:888