?? hill.cpp
字號:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUM 20
#define NUM2 1000
int main()
{
int i,j,k=0,n,p[NUM];
printf("階數: ");
scanf("%d",&n);
printf("\n密鑰: ");
//p=(int*)malloc(n*n*(sizeof(int)));
//q=(int*)calloc(n*n,sizeof(int));
int q[NUM][NUM];
for(i=0;i<n*n;i++)
{
scanf("%d",&p[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
q[i][j]=p[j+k];
//printf("%d ",q[i][j]);
if((j+1)%n==0)
{
k+=n;
// printf("\n");
}
}
}
char word[NUM2];
int length,word2[NUM2][1];
printf("明文: ");
scanf("%s",word);
length=strlen(word);
for(i=0;i<length;i++)
{
//printf("word: %c",word[i]);
word2[i][0]=word[i]-97;
//printf("word2:%d",word2[i][0]);
}
i=0,j=0,k=0;
int count=0,temp[NUM2][1],temp2[NUM2][1];
for(i=0;i<NUM2;i++)
{
for(j=0;j<1;j++)
{
temp[i][j]=0;
temp2[i][j]=0;
}
}
k=strlen(word);
//printf("K: %d\n",k);
int z=0;
j=0;
printf("密文: ");
while(z<k/n)
{
temp[j][0]=word2[j+count][0];
//printf("temp:%d\n",temp[j][0]);
j+=1;
if(j%n==0)
{
//printf("dffsf");
int i,s;
for(i=0;i<n;i++)
{
for(int u=0;u<1;u++)
{
for(s=0;s<n;s++)
{
temp2[i][0]+=q[i][s]*temp[s][0];
temp2[i][0]=(temp2[i][0])%26;
}
printf("%c",temp2[i][0]+65);
}
}
for(i=0;i<n;i++)
{
temp2[i][0]=0;
}
count+=n;
z+=1;
}
if(j%n==0)
j=0;
//printf("%d \n",z);
}
printf("\n");
system("pause");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -