① c語言 替換 簡易密碼代換
#include <stdio.h>
void main()
{
int i=0, j=0;
char a[100] = {0};
scanf("%s",a);
while ('\0' != a[i])
{
a[i] += 4;
if (a[i] > 'z')
{
a[i] -= 26;
}
else if (a[i] > 'Z' && a[i] < 'e')
{
a[i] -= 26;
}
++i;
}
printf("%s",a);
}
驗證無問題
② 映射表加密程序(替換密碼)
有單表替換加密解密c語言程序希望對你能有所幫助
#include<stdio.h>
char a[100];
char d[]={""};
void encryption();
void decryption();
void encryption()
{int i,j;
char b[100];
printf("please input a plaintext:\n");
gets(b);
printf("the ciphertext is:\n");
for(i=0;i<100;i++)
{if(b[i]==' ')
printf("%c",b[i]);
else if(b[i]!='\0')
{for(j=0;j<53;j++)
{if(d[j]==b[i])
printf("%c",a[j]);
}
}
else
break;}
printf("\n");
}
void decryption()
{char c[100];
int i,j,k;
printf("please input the ciphertext:\n");
gets(c);
printf("the plaintext is:\n");
for(i=0;i<100;i++)
{if(c[i]==' ')
printf("%c",c[i]);
else if(c[i]!='\0')
for(j=0;j<27;j++)
{if(a[j]==c[i])
{k=j+97;
printf("%c",k);
}
}
else break;
}
printf("\n");
}
void main()
{int i;
printf("please input 26 letters to form a key:\n");
scanf("%s",a);
list:printf("please choose a function:1.encryption 2.decryption 3.exit\n");
scanf("%d",&i);
getchar();
switch(i){
case 1:encryption();
goto list;break;
case 2:decryption();
goto list;break;
case 3:exit(1);
}
}
③ c語言實現密碼替代
看b[i]=(char)(a[i]+k); 這句就知道了,就是將每個字母變成其後第k個字母,比如k=2,那麼a變成c,b變成d,。。。。x變成z。那麼此時,y,z就沒法變了,所以就用if(b[i]>122){b[i]=(char)(b[i]-26); 把y變成a,z變成b.
④ 用C語言或者其他語言編寫替代密碼和置換密碼
給你,自己再稍微改造一下吧:
#include "stdio.h"
#include "conio.h"
main()
{
int k,i=0;
char a[100],b[100];
printf("qing shu ru ni de mi wen \n");
gets(a);
printf("qing shu ru mi shi \n");
scanf("%d",&k);
printf("\n");
do{
b[i]=(char)(a[i]+k);
if(b[i]>122){
b[i]=(char)(b[i]-26);
}
i++;
}while(a[i]!='\0');
puts(b);
getch();
}
⑤ 用c語言編使用密鑰的單表代替密碼的加和解密
期待看到有用的回答!
⑥ 使用密碼表加密 用C語言
密碼加密,有很多種方法的,最簡單的是單表仿射,也有多表置換之類的。一般都有一個變換公式的。。
你這里看不出來用哪一種方法的。。所以不好寫代碼。建議,拿本密碼學之類的書,看下。
⑦ C語言程序。急!
在單表置換密碼中,密鑰是由字母與空格組成的 如shana
在沒有密鑰作用前,置換表如下
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
在密鑰的作用下,置換表將發生變化,具體如下
將密鑰填入置換表,如果遇到重復的字元則忽略,接著按原表順序填充,忽略重復字元,如下表
a b c d e f g h i j k l m n o p q r s t u v w x y z
S H A N B C D E F G I J K L M O P Q R T U V W X Y Z
首先將SHAN填入表中,因為A已經在前面出現,所以忽略,接著將除去S H A N四個字元的字母表按順序填充
C語言程序:
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#defineMAX101 /*明文字元串的最大長度*/
char*encrypt(char*source,char*key);
intcontain(char*source,intn,charch);
voidmain()
{
char*source; /*明文*/
char*dest; /*密文*/
char*key; /*密鑰*/
source=(char*)malloc(sizeof(char)*MAX);
dest=(char*)malloc(sizeof(char)*MAX);
key=(char*)malloc(sizeof(char)*MAX);
printf("請輸入明文字元串:");
gets(source);
printf("請輸入密鑰:");
gets(key);
dest=encrypt(source,key);
printf("密文字元串:");
puts(dest);
}
/*加密明文(單表置換加密),返回密文*/
char*encrypt(char*source,char*key)
{
char*dest;
inti,j;
intlen1=strlen(source);
intlen2=strlen(key);
charch;
dest=(char*)malloc(sizeof(char)*MAX);
source=strupr(source);
key=strupr(key);
for(i=0;i<len1;i++)
{
dest[i]=NULL;
}
dest[i]='