① 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]='