您的位置:首页 > 其它

Vernam加密法

2015-09-23 18:48 204 查看
[code]#include <stdio.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <sstream>
#include <time.h>

using namespace std;

char clear_text[10000];
string ans;
char key[10000];

int main()
{
    memset(key, 0, sizeof(key));
    ans.clear();

    printf("please enter the clear_text :");
    scanf("%s", clear_text);
    int len = strlen(clear_text);
    printf("please enter key :");
    scanf("%s", &key);
    for (int i = 0;i < len;i++)
    {
        int tmp = (clear_text[i] - 'a' + key[i] - 'a') % 26;
        ans += (char)(tmp + 'a');
    }
    cout << ans << endl;
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: