实现一个或几个加解密程序

替代算法:
(1)替代密码算法的原理是使用替代法进行加密,就是将明文中的字符用其它字符替代后形成密文

#include "stdio.h"
#include<math.h>
#include<string.h>
#include"conio.h"
#define N 500
void main()
{
    int i=0,k,m,n,l;
    char str1[N],str2[N];
   // textbackground(RED);
   // textcolor(LIGHTGREEN);
   // clrscr();
    printf("This is a code password program......\n");
    printf("Please input proclaimed in writing(M)::\n");
    gets(str1);
    printf("Please input the key(K)(int)::\n");
    scanf("%d",&k);
    m=strlen(str1);
    printf("The M length is %d\n",m);
    printf("ciphertext(C) is ::\n\n");
    for(i=0;i<m;i++)
    {
    	n=(int)str1[i];
    	if(str1[i]==' ')
    	{
    		printf(" ");
    		str2[i]=str1[i];
    	}
    	else if(n>96&&n<123)
    	{
    		n=(n-97+k)%26;
    		if(n<0)
    		n=26+n;
    		l=(char)(n+97);
    		printf("%c",l);
    		str2[i]=l;
    	}
    	else if(n>64&&n<91)
    	{
    		n=(n-65+k)%26;
    		if(n<0)
    		n=26+n;
    		l=(char)(n+97);
    		printf("%c",l);
    		str2[i]=l;
    	}
    }
    str2[i]='\0';
    /*-------------------*/
    printf("\n\nThe C length is %d ",strlen(str2));
    printf("When the ciphertext is '%s',\nThe password program is...::\n\n",str2);m=strlen(str2);
     for(i=0;i<m;i++)
     {
     	n=(int)str2[i];
     	if(str2[i]==' ')
     	{
     		printf(" ");
     	}
     	else if(n>96&&n<123)
     	{ n=(n-97-k)%26;
     		if(n<0)
     		n=26+n;
     		l=(char)(n+97);
     		printf("%c",l);
     	}
     	else if(n>64&&n<91)
     	{
     		n=(n-65-k)%26;
     		if(n<0)
     		n=26+n;
     		l=(char)(n+97);
     		printf("%c",l);
     	}
     }
     str1[i]='\0';
     getch();
}

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值