广告合作
  • 今日头条

    今日头条

  • 百度一下

    百度一下,你就知道

  • 新浪网

    新浪网 - 提供新闻线索,重大新闻爆料

  • 搜狐

    搜狐

  • 豆瓣

    豆瓣

  • 百度贴吧

    百度贴吧——全球领先的中文社区

  • 首页 尚未审核订阅工具 订阅

    C语言实现替代密码算法

    来源:网络收集  点击:  时间:2024-09-13
    【导读】:
    替代密码算法的原理是使用替代法进行加密,就是对明文中的字符用其他字符替代后形成密文。例如,明文字母 a, b, c, d, 用 d, e, f , g 做对应替换后形成密文。工具/原料moreLinux系统vi编辑器gcc编译器方法/步骤1/3分步阅读

    创建文件:tihuanmima.c

    2/3

    编辑源代码;代码如下

    #includestdio.h

    #includestring.h

    #includestdlib.h

    char plain;

    char cipher;

    int k;

    int jiami(){

    printf(请输入明文:);

    scanf(%s,plain);

    printf(请输入密钥(即k的值):);

    scanf(%d,k);

    printf(明文是:%s\n,plain);

    printf(密文是:);

    for(int i=0;istrlen(plain);i++){

    if(plain=97){

    char temp=plain;

    temp=(temp+k)%122;

    if(temp0temp=k)

    printf(%c,temp+96);

    if(temp==0)

    printf(%c,temp+122);

    else

    printf(%c,temp);

    }else{

    char temp=plain;

    temp=(temp+k)%90;

    if(temp0temp=k)

    printf(%c,temp+64);

    if(temp=0)

    temp=122;

    else

    printf(%c,temp);

    }

    }

    printf(\n);

    return 0;

    }

    int jiemi(){

    printf(请输入密文:);

    scanf(%s,cipher);

    printf(请输入密钥(即k的值):);

    scanf(%d,k);

    printf(密文是:%s\n,cipher);

    printf(明文是:);

    for(int i=0;istrlen(cipher);i++){

    char temp=cipher;

    temp=temp-k;

    if(temp97)

    printf(%c,123-(97-temp));

    else

    printf(%c,temp);

    }

    printf(\n);

    return 0;

    }

    int main(){

    int a;

    while(1){

    printf(按1加密,按2解密,按3退出);

    scanf(%d,a);

    if(a==1)

    jiami();

    if(a==2)

    jiemi();

    if(a==3){

    exit(0);

    }

    }

    }

    3/3

    使用gcc进行编译,然后用ls命令找到a.out(这个是gcc自己生成的可执行文件)并且执行

    注意事项

    在使用的时候应当要注意自己的Linux版本是否可以使用gcc,不同版本的linux的gcc使用不尽相同

    本文关键词:

    版权声明:

    1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。

    2、本站仅提供信息发布平台,不承担相关法律责任。

    3、若侵犯您的版权或隐私,请联系本站管理员删除。

    4、文章链接:http://www.1haoku.cn/art_1211422.html

    相关资讯

    ©2019-2020 http://www.1haoku.cn/ 国ICP备20009186号05-07 16:20:49  耗时:0.034
    0.0338s