标题:寻找C语言加密算法源码ing
只看楼主
北溟有鱼为鲲
Rank: 2
等 级:论坛游民
威 望:1
帖 子:11
专家分:26
注 册:2018-7-30
 问题点数:0 回复次数:2 
寻找C语言加密算法源码ing
最近写C语言程序需要加密功能,在网上查了一下,能找到的加密算法是TEA加密,但也是C++的
所以麻烦问一下诸位有没有更好的推荐
P.S.在下对密码学一点都不了解,所以这次就功利一点,只要C语言加密算法源代码,写程序时直接拿来就用吧
(* ̄︶ ̄)y
P.P.S.加密算法不用太高级,只要有一定安全性即可,或者各位启发一下我,给个思路呗(涉及到C语言的位操作就算了,我当初把这部分跳过了)
搜索更多相关主题的帖子: C语言 加密 算法 源码 ing 
2018-08-10 17:21
a201187902
Rank: 2
等 级:论坛游民
帖 子:5
专家分:20
注 册:2018-5-1
得分:0 
程序代码:
#include<iostream>
using namespace std;
void menu()
{
    cout << "  1、凯撒加密\n";
    cout << "  2、凯撒解密\n";
    cout << "  3、换字式加密\n";
    cout << "  4、换字式解密\n";
    cout << "  5、多表替代加密\n";
    cout << "  6、多表替代解密\n";
    cout << "\n   请选择: "; 
}
void kaisajia()
{
    cin.get();
    char mi[100];
    int n;
    cout << "请输入明文:";
    gets_s(mi);
    cout << "需要移动的位数:";
    cin >> n;
    for (int i = 0; i < strlen(mi); i++)
        for (int j = 0; j < n; j++)
        {
            if ((mi[i] >= 'a'&&mi[i] <= 'z') || (mi[i] >= 'A'&&mi[i] <= 'Z'))
            {
                if (mi[i] == 'z' || mi[i] == 'Z')
                    mi[i] -= 26;
                mi[i]++;
            }
                
        }
    cout << "得到的密文为:" << mi << endl;
    cin.get();
    cin.get();
    system("cls");
}
void kaisajie()
{
    cin.get();
    char mi[100];
    cout << "请输入密文:";
    gets_s(mi);
    for (int j = 0; j < 26; j++)
    {
        for (int i = 0; i < strlen(mi); i++)
        {
            if ((mi[i] >= 'a'&&mi[i] <= 'z') || (mi[i] >= 'A'&&mi[i] <= 'Z'))
            {
                if (mi[i] == 'z' || mi[i] == 'Z')
                    mi[i] -= 26;
                mi[i]++;
            }
        }
        cout << "明文组合" << j + 1 << ""<<mi<<endl;
    }
    cin.get();
    system("cls");
}
void huanzijia()
{
    char a[28]{ 'd','c','f', 'e', 'h', 'a', 'b', 'o',
        'r', 'g', 't', 'w', 's', 'i','x','z',
        'j','l', 'n', 'm', 'u', 'y', 'k','q','v','p' };
    char b[28]{ 'P','X','Q', 'K', 'Y', 'U', 'M', 'N',
        'L', 'J', 'Z', 'X', 'I', 'S','W','T',
        'G','R', 'O', 'B', 'Q', 'H', 'E','F','C','D' };
    cin.get();
    char mi[100];
    cout << "请输入明文:";
    gets_s(mi);
        for (int i = 0; i < strlen(mi); i++)
        {
            if (mi[i] >= 'a'&&mi[i] <= 'z')
                mi[i] = a[(int)mi[i]-97];
            if (mi[i] >= 'A'&&mi[i] <= 'Z')
                mi[i] = a[(int)mi[i] - 65];
        }
    cout << "密文为:"<<mi << endl;
    cin.get();
    system("cls");
}
void huanzijie()
{
    char a[28]{ 'd','c','f', 'e', 'h', 'a', 'b', 'o',
        'r', 'g', 't', 'w', 's', 'i','x','z',
        'j','l', 'n', 'm', 'u', 'y', 'k','q','v','p' };
    char b[28]{ 'P','X','Q', 'K', 'Y', 'U', 'M', 'N',
        'L', 'J', 'Z', 'X', 'I', 'S','W','T',
        'G','R', 'O', 'B', 'Q', 'H', 'E','F','C','D' };
    cin.get();
    char mi[100];
    cout << "请输入密文:";
    gets_s(mi);
    for (int i = 0; i < strlen(mi); i++)
    {
            if (mi[i] >= 'a'&&mi[i] <= 'z')
            {
                int j = 0;
                while (mi[i] != a[j])
                    j++;
                mi[i] = (char)(j + 97);
            }
            if (mi[i] >= 'A'&&mi[i] <= 'Z')
            {
                int j = 0;
                while (mi[i] != a[j])
                    j++;
                mi[i] = (char)(j + 65);
            }
    }
    cout << "明文为:" << mi << endl;
    cin.get();
    system("cls");
}
void duobiaojia()
{
    cin.get();
    char mi[100];
    int n,a,flag=0,ow=0;
    cout << "请输入明文:";
    gets_s(mi);
    cout << "请问需要多少字符一组:";
    cin >> n;
    if (strlen(mi) % n)
        flag++;
    for (int i = 0; i <strlen(mi)/n+flag; i++)
    {
        cout << "" << i+1 << "组移动字符数:";
        cin >> a;       
        for (int j = 0; j < n; j++)
        {
            if ((mi[j+i*n] >= 'a'&&mi[j + i * n] <= 'z') || (mi[j + i * n] >= 'A'&&mi[j + i * n] <= 'Z'))
            {
                for (int k = 0; k < a; k++)
                {
                    if (mi[j + i * n] == 'z' || mi[j + i * n] == 'Z')
                        mi[j + i * n] -= 26;
                    mi[j + i * n]++;
                }       
            }
        }
    }
    cout << "密文为:" << mi << endl;
    cin.get();
    cin.get();
    system("cls");
}
void duobiaojie()
{
    cin.get();
    char mi[100],ow[100];
    cout << "请输入密文:";
    gets_s(mi);
    strcpy_s(ow, mi);
    int flag = 0;
    for (int n = 1; n < 10; n++) //假设的一组的个数
    {
        if (strlen(mi) > n)
        {
            if (strlen(mi) % n)
                flag++;
                 for (int k = 1; k <26; k++)//假设的步长
                 {      
                        for (int j = 0; j < n; j++) //一组的个数
                        {
                            for (int i = 0; i < strlen(mi) / n + flag; i++) //分组数
                            if ((mi[j + i * n] >= 'a'&&mi[j + i * n] <= 'z') || (mi[j + i * n] >= 'A'&&mi[j + i * n] <= 'Z'))
                            {
                                if (mi[j + i * n] == 'z' || mi[j + i * n] == 'Z')
                                    mi[j + i * n] -= 26;
                                mi[j + i * n]++;
                                cout <<"分组-" << n<<"步长"<<26-k << " 明文:" << mi << endl;
                            }
                                        
                        }   
                
                 }
                
        }
        strcpy_s(mi, ow);
    }
    cin.get();
    system("cls");
}
void main()
{
    while (true)
    {
        menu();
        int n;
        cin >> n;
        system("cls");
        switch (n)
        {
            case 1:
                kaisajia();
                break;
            case 2:
                kaisajie();
                break;
            case 3:
                huanzijia();
                break;
            case 4:
                huanzijie();
                break;
            case 5:
                duobiaojia();
                break;
            case 6:
                duobiaojie();
                break;
            default:
                break;
        }
    }
    system("pause");
}
2018-08-19 13:54
俺是你大爷
Rank: 2
等 级:论坛游民
帖 子:57
专家分:35
注 册:2019-3-12
得分:0 
回复 2楼 a201187902
现场写的?
2019-03-12 13:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-489138-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.270874 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved