首页 > 解决方案 > 包括 Vigenere Cipher 中的空格?

问题描述

我正在尝试创建一个对 Vigenere Cipher 进行解码/编码的程序。它适用于所有字母(AZ),但我不知道如何在密码中包含空格。

#include<bits/stdc++.h> 
using namespace std; 
  
string generateKey(string str, string key) 
{ 
    int x = str.size(); 
  
    for (int i = 0; ; i++) 
    { 
        if (x == i) 
            i = 0; 
        if (key.size() == str.size()) 
            break; 
        key.push_back(key[i]); 
    } 
    return key; 
    
} 
  
// This function returns the encrypted text 
string cipherText(string str, string key) 
{ 
    string cipher_text; 
  
    for (int i = 0; i < str.size(); i++) 
    { 
        // converting in range 0-25 
        char x = (str[i] + key[i]) %27; 
  
        // convert into alphabets(ASCII) 
        x += 'A'; 
        cout << cipher_text << endl;
        cipher_text.push_back(x); 
    } 
    return cipher_text; 
} 

标签: c++encryptionvigenere

解决方案


推荐阅读