當前位置:首頁 » 編程語言 » 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