導航:首頁 > 文檔加密 > 輸入字元串加密程序編寫

輸入字元串加密程序編寫

發布時間:2022-06-07 05:01:40

① C語言編程問題:從鍵盤上輸入一個字元串按照以下規則對其加密

#include<stdio.h>

#include<string.h>

intmain(){

inti;

chars[80];

printf("請輸入字元串:");

while(scanf("%s",s)==1)

{

printf("加密前:%s ",s);

i=0;//i定義在此處便於第二次運行

while(s[i])

{if(s[i]>='A'&&s[i]<='Z')

s[i]=(s[i]-'A'+3)%26+'A';

elseif(s[i]>='a'&&s[i]<='z')

s[i]=(s[i]-'a'+3)%26+'a';

++i;}

printf("加密後:%s ",s);

printf("請輸入字元串[<Ctrl+Z><ENTER>結束程序]:");

}

return0;

}

② 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;
}

③ 輸入一個字元串作為密碼,程序實現密碼加密.

#include <stdio.h>
#include <stdlib.h>
int main(){
char* str = malloc(21);
char *p = str;
int i ;
//memset(str,0,21);
printf("輸入字元串:");
scanf("%s",str);
while(*str != ''){
if(*str>=97 && *str<=122){//小寫變大寫
*str -= 32;
}else if(*str>=65 && *str<=90){//大寫變小寫
*str += 32;
}else if(*str>=48 && *str<=57){//數字加密
if(*str==48){
*str = 57;
}else if(*str==49){
*str = 56;
}else if(*str==50){
*str = 55;
}else if(*str==51){
*str = 54;
}else if(*str==52){
*str = 53;
}else if(*str==53){
*str = 52;
}else if(*str==54){
*str = 51;
}else if(*str==55){
*str = 50;
}else if(*str==56){
*str = 49;
}else if(*str==57){
*str = 48;
}
}
str++;
}
printf("%s ",p);
return 0;
}

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

1 子函數的修改。只要減掉24 即可,其餘語句多餘。
void encryp(char *plain,char *cipher)
{
int temp;
while(*plain!='\0')
{
temp=*plain-24;
*cipher=temp;
plain++;
cipher++;
}
*cipher='\0';
}
2 對輸出句的修改。改為按數字格式(知識點)輸出即可。
{ int i=0; // 增加一變數 i =0;
。。。。。。。。
while(ch2[i]!='\0')
printf("%d",ch2[i++]);
return 0;
}

⑤ Java 編寫加密類,實現對輸入字元串進行加密,加密演算法如下: 1.每個字元

不懂請追問

public class Q {
public static String encrypt(String str){
StringBuilder sb=new StringBuilder(str);
for(int i=0;i<sb.length();i++){
char c=sb.charAt(i);
sb.setCharAt(i,(char)(c+i));
}
sb.reverse();
return sb.toString();
}
public static void main(String[] args) {
String s="abc";
s=encrypt(s);
System.out.println(s);
}
}
有用請採納
ps:友情提供測試方法

⑥ c語言編寫字元串加密函數 不要寫得太難啊

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

char*encrypt(char*text){
charc;
char*p=text;
for(;*text;++text){
c=*text;
if(isdigit(c))
*text='0'+'9'-c;
elseif(islower(c)){
c=c+3;
if(c>'z')
c=c-26;
*text=c;
}elseif(isupper(c)){
c=c+3;
if(c>'Z')
c=c-26;
*text=c;
}
}
returnp;
}

intmain(){
chartext[100];
printf("輸入明文:");
scanf("%s",text);
printf("密文:%s ",encrypt(text));
getchar();
}

⑦ C++ 編程,編寫一個程序,通過根據輸入鍵重新排列輸入字元串中的字元來加密用戶輸入消息,求代碼

#include <iostream>

#include <string>


int main() {


std::strings, key;

getline(std::cin, s);

getline(std::cin, key);

int lenS = s.length();

int lenKey = key.length();

if (lenS % lenKey)

for (int i = 0; i < (lenKey - lenS % lenKey); i++)

s.append(" ");

lenS = s.length();


std::string tmp = s;

for (int i = 0; i < lenS ; i++)

tmp[key[i % lenKey] - '0' + lenKey * (i / lenKey)] = s[i];


std::cout << tmp << std::endl;

return 0;

}

⑧ 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;
}
如果想看一些好一點的加密演算法
,我這里有一些,聯系我發給你
,,

閱讀全文

與輸入字元串加密程序編寫相關的資料

熱點內容
黑馬程序員培訓效果如何 瀏覽:908
本地集成編譯 瀏覽:526
韓國電影哪個app可以看 瀏覽:701
玖月授權什麼app什麼梗 瀏覽:783
怎麼使用伺服器上的ip地址是什麼情況 瀏覽:748
手機密碼加密後怎麼解密 瀏覽:343
華為雲的伺服器的ip地址怎麼訪問不 瀏覽:365
webstormvue在線實時編譯生效 瀏覽:184
3225pdf 瀏覽:171
java中的常用類 瀏覽:394
安卓手機oppo反向色調怎麼開 瀏覽:138
羅志祥pdf 瀏覽:224
美國戰爭pdf 瀏覽:243
任務欄右擊如何顯示常用文件夾 瀏覽:100
海克斯康三次元編程 瀏覽:748
什麼app可以上門喂貓 瀏覽:889
老程序員抓彈幕 瀏覽:655
刷地鐵卡應該下個什麼app 瀏覽:154
安卓版谷歌瀏覽器為什麼用不了 瀏覽:505
消除類游戲的演算法 瀏覽:468