當前位置:首頁 » 編程語言 » C語言加密字元怎麼寫
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

C語言加密字元怎麼寫

發布時間: 2022-11-01 12:36:41

1. c語言對字元進行加密

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

2. C語言字元串加密

#include<stdio.h>
#include<string.h>
chartable1[]="abcdeik;w";
chartable2[]="dwk;iabce";
intInit(charc)
{
for(inti=0;i<strlen(table1);i++)
if(c==table1[i])
returni;
return-1;
}
voidEncrypt(char*s)
{
inti,j;
for(i=0;s[i]!='';i++)
{
j=Init(s[i]);
if(j>-1)
s[i]=table2[j];
}
return;
}
intmain()
{
chars[128];
scanf("%s",s);
Encrypt(s);
printf("%s ",s);
return0;
}

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

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

4. c語言字元加密

題目沒有講清楚,是對所有字元加密,還是只對英文字母加密?數字字元要不要加密?移位的規則怎麼樣都沒有說清楚。
下面的程序是只對英文字母進行移位加密,並且統一都是移位4位。
#include
#include
int main()
{ char s[200];
int i,j;
gets(s);
for(i=0;s[i];i++)
if(isalpha(s[i]))
s[i]=(s[i]%32+3)%26+'A'+isupper(s[i])*32;
puts(s);
return 0;
}

5. C語言怎麼加密字元

#include<stdio.h>
#include<string.h>
intmain()
{
charstr[]="00000",str2[]="00000",*p=str,*p2=str2;
printf("輸入5個字母:");
while(*p!=0)
{
scanf("%c",p);
if(*p==' ')
continue;
if(*p<'A'||(*p>'Z'&&*p<'a')||*p>'z')//輸入驗證,必須是字母
{
printf("只能輸入字母,請重新輸入 ");
p=str;
p2=str2;
fflush(stdin);//輸入有錯重新輸入前清空緩沖區。fflush屬於c擴展函數,正常使用沒問題,如需在linuxggc上使用,考慮多次調用getchar函數來清空
}
else
{
*p2=(*p)+4;
if(*p2>90&&*p2<97)//大寫字母加4,最大位不超出
*p2='A'+(*p2-90)-1;
if(*p2>122)//小寫字母加4,最大位不超出
*p2='a'+(*p2-122)-1;
p2++;
p++;
}
}

printf("原字元串為:%s 加密後的字元串為:%s ",str,str2);
return0;
}

6. C語言如何進行字元加密

進行字元加密是很多種的。
數據加密的基本過程就是對原來為明文的文件或數據按某種演算法進行處理,使其成為不可讀的一段代碼為「密文」,使其只能在輸入相應的密鑰之後才能顯示出原容,通過這樣的途徑來達到保護數據不被非法人竊取、閱讀的目的。 該過程的逆過程為解密,即將該編碼信息轉化為其原來數據的過程。

7. C語言字元串按要求加密 求教

void encryp(char *plain,char *cipher)這個函數你寫復雜了,如下就可以了——

void encryp(char *plain,char *cipher){
int i;

for(i=0;plain[i];i++)

cipher[i]=plain[i]-24;

cipher[i]='\0';

}

這樣加密就完結了。

8. C語言 字元串加密

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
intmain(void)
{
charc[100];
intk;
intlen,i,temp;

scanf("%s",c);
scanf("%d",&k);

len=(int)strlen(c);
k=k%26;

for(i=0;i<len;i++)
{
if(c[i]>='a'&&c[i]<='z')
{
if(c[i]+k>'z')
{
temp='z'-c[i];
temp=k-temp-1;
c[i]='a'+temp;
}
else
{
c[i]+=k;
}
}
elseif(c[i]>='A'&&c[i]<='Z')
{
if(c[i]+k>'Z')
{
temp='Z'-c[i];
temp=k-temp-1;
c[i]='A'+temp;
}
else
{
c[i]+=k;
}
}
else
{
/*donothing*/
}
}

printf("%s ",c);

return0;
}

9. C語言字元串加密

1.main()
{char password[80];
int i;
scanf("%s",password);
for(i=0;password[i]!='\0';i++)
password[i]=password[i]+13;
}
2.#include "stdlib.h"
struct pw
{char ch1,ch2;
struct pw *next;}
main()
{struct pw p,head;
int i;
head=(struct pw *)malloc(sizeof(struct pw));
p=head;
for(i=1;i<=10;i++)
{scanf("%c",&p->ch1);
p->ch2=p->ch1+13;
p->next=(struct pw *)malloc(sizeof(struct pw));
p=p->next;
p->next=NULL;}
p=head;
}

10. C語言字元串加密

問題不小,你表面用的是C
但是,好多地方不符合C的語法
,,比如:
for
(int
i=0;
str[i]
!=
'\0';
i++)
還有,就是你好像沒有弄清楚
,你要做什麼似的,有好多無用的東西,
就像你的函數里的,key
,雖然你提到key了,但是你根本沒有使用key,你只是使用45來進行加密,,還有就是一個文件
的大小,是不確定的,你用一個100個字元的字元串來存,有點那個不安全了,,如果稍長一點就會出問題,產生運行時錯誤。其實你這個加密和解密是一個可逆過程,用一個函數,就可以了,具體你想要的也不是太明白,就給你弄了一個簡單一點加密和解密程序
,輸入輸出不是同一個文件
,不知道是不是你想要的。
#include

#include

#include

void
Decrypt()
{
char
fname[FILENAME_MAX];
char
fname2[FILENAME_MAX];
FILE*
fp;
FILE*
fp1;
int
key;
char
c;
printf("輸入要加/解密文件的路徑:\n");
scanf("%s",
fname);
printf("請輸入密鑰:\n");
scanf("%d",&key);
strcpy(fname2,fname);
strcat(fname2,".txt");
if(
(fp
=
fopen(fname,"r+"))
==
NULL)
{
printf("error");
exit(1);
}
if(
(fp1
=
fopen(fname2,"w+"))
==
NULL)
{
printf("error");
exit(1);
}
while(
(c
=
fgetc(fp))
!=
EOF)
{
c
=
c^key;
fputc(c,fp1);
}
fcloseall();
}
int
main()
{
Decrypt();
return
0;
}
如果想看一些好一點的加密演算法
,我這里有一些,聯系我發給你
,,