当前位置:首页 » 编程语言 » vigenerec语言
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

vigenerec语言

发布时间: 2022-07-13 12:06:57

⑴ 如何用c语言写仿射密码和维吉尼亚密码只用C语言函数完成代码,谢谢。

void *(* func) (void *){}
一般写函数的时候不会在函数名前面加*再括号括起来的。如果是函数指针
那么就是返回void*类型。如果真的是函数定义的话,
感觉不会这么写的,还不如写void ** func (void *) 这种名字呢。

⑵ 用C语言破译Vigenere Cipher,程序有点问题求指教!

j 输出几个数字

⑶ 写一个维吉尼亚加密和解码的C语言程序,具体要求如下。不要用GOTO, 不要有MAGIC NUMBER。

#include <stdio.h>
#define MINCHAR 32
#define CHARSUM 94
int encode(char* key, char* source, char* dest);
int decode(char* key, char* source, char* dest);
char table[CHARSUM][CHARSUM];
int main()
{
int i, j;
char key[256];
char source[256];
char destination[256];
int operation;

FILE *fp;
/* Initial the Vigenere table */
for(i = 0; i < CHARSUM; i++)
for(j = 0; j < CHARSUM; j++)
table[i][j] = MINCHAR + (i + j) % CHARSUM;

printf("please choose one operation code: ");
printf("1. Encode; 2. Decode; Others. Exit. ");
scanf("%d", &operation);
fflush(stdin);
switch (operation)
{
case 1:
printf("please input the key code: ");
gets(key);
fflush(stdin);
printf("please input the source code you want to encode: ");
gets(source);
fflush(stdin);
encode(key, source, destination);
printf("after encode is: ");
printf("%s ", destination);
fp=fopen("key.txt", "w");
fprintf(fp, "%s", key);
fclose(fp);
fp=fopen("source.txt", "w");
fprintf(fp, "%s", source);
fclose(fp);
fp=fopen("destination.txt", "w");
fprintf( fp, "%s",destination);
fclose(fp);
break;
case 2:
printf("please input the key code: ");
gets(key);
fflush(stdin);
printf("please input the source code you want to decode: ");
gets(source);
fflush(stdin);
decode(key, source, destination);
printf("after decode is: ");
printf("%s ", destination);
fp=fopen("key.txt", "w");
fprintf(fp, "%s", key);
fclose(fp);
fp=fopen("source.txt", "w");
fprintf(fp, "%s", source);
fclose(fp);
fp=fopen("destination.txt", "w");
fprintf(fp, "%s", destination);
fclose(fp);
break;
default:
return 0;
}
return 0;
}

int encode(char* key, char* source, char* dest)
{
char* tempSource = source;
char* tempKey = key;
char* tempDest = dest;
do
{
*tempDest = table[(*tempKey) - MINCHAR][(*tempSource) - MINCHAR];
tempDest++;
if (!(*(++tempKey)))
tempKey = key;
} while(*tempSource++);
dest[strlen(source)] = ''
return 1;
}
int decode(char* key, char* source, char* dest)
{
char* tempSource = source;
char* tempKey = key;
char* tempDest = dest;
char offset;
do
{
offset = (*tempSource) - (*tempKey);
offset = offset >= 0 ? offset : offset + CHARSUM;
*tempDest = MINCHAR + offset;
tempDest++;
if (!(*(++tempKey)))
tempKey = key;
} while(*++tempSource);
dest[strlen(source)] = ''
return 1;
}

⑷ 数据文件的维吉尼亚加密程序

#include
#include
void menu()/*菜单*/
{
clrscr();
printf("\n===============================================================================");
printf("\n1.Encrypt the file");
printf("\n2.Decrypt the file");
printf("\n3.Quit\n");
printf("===============================================================================\n");
printf("Please select a item:");
return;
}

char encrypt(char ch1,char ch2)/*加密程序*/
{
if(ch1>='A'&&ch1<='Z'&&ch2>='A'&&ch2<='Z')
{
return 'A'+(ch1-'A'+ch2-'A')%26;
}
if(ch1>='a'&&ch1<='z'&&ch2>='a'&&ch2<='z')
{
return 'a'+(ch1-'a'+ch2-'a')%26;
}
return ch1;
}

char decrypt(char ch1,char ch2)/*解密程序*/
{
if(ch1>='A'&&ch1<='Z'&&ch2>='A'&&ch2<='Z')
{
return 'A'+(ch1-'A'+26-(ch2-'A'))%26;
}
if(ch1>='a'&&ch1<='z'&&ch2>='a'&&ch2<='z')
{
return 'a'+(ch1-'a'+26-(ch2-'a'))%26;
}
return ch1;
}

main()
{
int i;
char key[50];
char ch;
FILE *in,*out;
char infile[20],outfile[20];

textbackground(BLACK);
textcolor(LIGHTGREEN);
clrscr();

clrscr();

sleep(3);

menu();
ch=getch();
while(ch!='3')
{
if(ch=='1')
{
clrscr();
printf("\nPlease input the infile:");
scanf("%s",infile);/*输入需要加密的文件名*/

if((in=fopen(infile,"r"))==NULL)
{
printf("Can not open the infile!\n");
printf("Press any key to exit!\n");
getch();
exit(0);
}

printf("Please input the key:");
scanf("%s",key);/*输入加密密码*/

printf("Please input the outfile:");
scanf("%s",outfile);/*输入加密后文件的文件名*/

if((out=fopen(outfile,"w"))==NULL)
{
printf("Can not open the outfile!\n");
printf("Press any key to exit!\n");
fclose(in);
getch();
exit(0);
}

i=0;
while(!feof(in))
{
fputc(encrypt(fgetc(in),key[i%strlen(key)]),out);
i++;
}

fclose(in);
fclose(out);
printf("\nEncrypt successful!\n");
sleep(1);
}
if(ch=='2')
{
clrscr();
printf("\nPlease input the infile:");
scanf("%s",infile);/*输入需要解密的文件名*/

if((in=fopen(infile,"r"))==NULL)
{
printf("Can not open the infile!\n");
printf("Press any key to exit!\n");
getch();
exit(0);
}

printf("Please input the key:");
scanf("%s",key);/*输入解密密码*/

printf("Please input the outfile:");
scanf("%s",outfile);/*输入解密后文件的文件名*/

if((out=fopen(outfile,"w"))==NULL)
{
printf("Can not open the outfile!\n");
printf("Press any key to exit!\n");
fclose(in);
getch();
exit(0);
}

i=0;
while(!feof(in))
{
fputc(decrypt(fgetc(in),key[i%strlen(key)]),out);
i++;
}

fclose(in);
fclose(out);
printf("\nDecrypt successful!\n");
sleep(1);
}
menu();
ch=getch();
}

clrscr();
logo();
printf("\nGood Bye!\n");
sleep(3);

⑸ c语言编译错误 头文件的问题

先建一个工程,然后再新建一个head file文件,之后在c source 目录下新建.cpp文件,这样在同一工程下应该可以打开。

⑹ 怎么用C语言进行vigenere加密与解密

#include <stdio.h>
int main()
{
char s[50],key[50],e[50];
char choice;
int l,m,i,j=0,k=0;
printf("please choice: 1)jiami 2)jiemi\n");
scanf("%d",&m);
if(m==1)
{
printf("please input the key:\n");
scanf("%s",&key);

printf("please input the 明文:\n");
scanf("%s",&s);

for(l=0;s[l]!='\0';l++)
;

for(i=0;i<l;i++)
{
e[k]=(s[i]-'a'+key[j]-'a')%26+'a';
j++;
k++;
}
puts(e);
system("pause");
}
if(m==2)
{
printf("please input the key:\n");
scanf("%s",&key);

printf("please input the 密文:\n");
scanf("%s",&s);

for(l=0;s[l]!='\0';l++)
;

for(i=0;i<l;i++)
{

e[k]=(s[i]-key[j]+26)%26+'a';
j++;
k++;
}
puts(e);
system("pause");
}
}

我希望下载的你们看一下思想!其实很简单的!定义3个数组,分别放明文,密钥,密文!加密的思想方法是用户输入明文和密钥分别放入两个定义好的数组里面!接下去就是用循环,是该两个数组从数组中第一个存放的数开始进行加密!加密的公式上面有,稍微想一下就应该想的通的,至于解密和加密差不多的,就是公式不一样而已!不过我的那个公式也不是唯一的

⑺ C语言编程实现Vigenere加解密

没有看到Vigenère cipher 的要求 所以ciphertext 无法计算

只实现了检查key和preprocessing的功能

不过从介绍上看,Vigenère cipher 算法应该是上一题的内容 你应该做过了吧?

加过来就可以了

#include<stdio.h>
#include<string.h>

intcheck_key(char*key)
{
while(*key)
{
if(*key<'a'||*key>'z')return1;
key++;
}
return0;
}

voidconvert(char*src,char*dst)
{
inti,j;
char*number[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
for(i=j=0;src[i];i++)
{
if(src[i]<='Z'&&src[i]>='A')
dst[j++]=src[i]-'A'+'a';
elseif(src[i]<='z'&&src[i]>='a')
dst[j++]=src[i];
elseif(src[i]<='9'&&src[i]>='0')
{
strcpy(&dst[j],number[(int)src[i]-'0']);
j+=strlen(number[(int)src[i]-'0']);
}
}
dst[j]=0;
}

intmain()
{
charkey[21];
chartext[31];
charpre_text[151];
while(1)
{
printf("Pleaseinputthekey:");
gets(key);
if(check_key(key))
{
printf("Invalidkey ");
continue;
}
printf("Pleaseinputthetext:");
gets(text);
convert(text,pre_text);
printf("Thepreprocessing:%s ",pre_text);
}
}

⑻ 维吉尼亚密码c语言求改。

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define N 10000
void function(char message[],char key[],int mode); //加解密函数
int main()
{
int choose;
char m[N],key[N];
printf("维吉尼亚加密,请输入1;解密,请输入2:\n");
scanf("%d",&choose);
getchar();
if (choose == 1 || choose == 2)
{
if (choose == 1)
printf("输入明文:\n");
if (choose == 2)
printf("输入密文:\n");
gets(m);
printf("输入密钥:\n");
gets(key);
function(m,key,choose);
}
else
printf("输入错误!\n");
return 0;
}

void function(char message[],char key[],int mode) //加解密函数
{
int i, j = 0; //j控制key的轮回
int len_k = strlen(key); //密钥长度
char s[N];
for(i=0; message[i]!='\0'; i++)
{
if(message[i] == 32) //判断空格
s[i]=' ';
else
{
if (mode == 1)
s[i]=(int(message[i]-'a')+int(key[j%len_k]-'a'))%26+97;
if (mode == 2)
s[i]=(int(message[i]-'a')-int(key[j%len_k]-'a')+26)%26+97;
j++;
}
printf("%c",s[i]);
}
printf("\n");
}

gets(l);//不加这句M就输入不了为什么?
是因为没有这句的话,按的回车键就输成m了。
连用两个输入语句时,需要考虑回车键,就像我代码里的getchar()。

⑼ 使用费杰尔算法进行编程 求源代码

费杰尔/维热纳尔(Vigenere)密码的加密算法如下:

明文M=M1M2M3...Mn
密钥K=K1K2K3...Km
密文C=C1C2C3...Cn (m>=n)
则:Ci = (Mi + Ki) % 26,(i = 1, 2, ..., m)
其中,令26个字母A~Z的序号对应0~25,
Ci 是密文中第i个字母的序号,
Mi 是明文中第i个字母的序号,
Ki 是密钥Key中第i个字母的序号,
注意:若密钥长度小于明文长度,则首先应循环复写密钥直至密钥长度大于等于明文长度。

例如:
M=WELL
K=ABC
则先将密钥扩展为ABCABC,再进行加密得到密文
C=WFNO