当前位置:编程学习 > 网站相关 >>

Playfair加密解密算法(C语言)

侠客行
include<stdio.h>
#include<string.h>

int fenlei(char h)//字符分类
{
        int i;
        if(h==i||h==j)
                i=1;
        else if(h==I||h==J)
                i=2;
        else if(h>=a&&h<=z)
                i=3;
        else if(h>=A&&h<=Z)
                i=4;
        else
                i=5;
        return i;
}
void tongyi(char p[],char c[])//密钥字符统一化为小写字母,并将j转换为i
{
        int i,j;
        for(i=j=0;p!=;i++)
        {
                if(fenlei(p)==1||fenlei(p)==2){
                        c[j]=i;
                        j++;
                }
                else if(fenlei(p)==3){
                        c[j]=p;
                        j++;
                }
                else if(fenlei(p)==4){
                        c[j]=p+32;
                        j++;
                }
        }
        c[j]=;
}
void  quchu(char p[],char c[])//去除密钥里的重复字符
{
        int flag=0,v,i,j;
        for(i=j=0;c!=;i++){
                for(v=0;v<j;v++){
                        flag=0;
                        if(p[v]==c){
                                flag=1;
                                break;
                        }
                }
                if(flag==1)
                        continue;
                p[j]=c;
                j++;
        }
        p[j]=;
}
void juzhen(char p[],char k[5][5])//矩阵
{
        int flag,i,j,v,m=0;
        for(i=0,v=0;i<5;i++)
                for(j=0;j<5;j++){
                        if(p[v]!=)
                                k[j]=p[v++];
                        else{
                                for(int c=m;c<26;c++){
                                        flag=0;
                                        for(int n=0;p[n]!=;n++)
                                                if(p[n]==a+c||a+c==j){
                                                        flag=1;
                                                        break;
                                                }
                                        if(0==flag){
                       

补充:综合编程 , 安全编程 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,