El cifrado
#include <iostream>
#include<vector>
#include<math.h>
using namespace std;
void cifrado(vector<string>& s,int k){
int val;
int s_size=s.size();
for(int i=0;i<s_size;i++){
int s_0=s[i].size();
for(int j=0;j<s_0;j++){
if(s[i].at(j)>=97){
val=s[i].at(j)-'a';
val=(val+k)%26;
s[i].at(j)='a'+val;
}
if(s[i].at(j)<97){
val=s[i].at(j)-'A';
val=(val+k)%26;
s[i].at(j)='A'+val;
}
}
}
}
int main() {
/* This is a program to take an input
* string from the user and encrypt it by
* My personal method.
*
*/
cout<<"Enter the number of words that you want to input and encrypt."<<endl;
int n;
cin>>n;
cout<<"Enter the sentence which you want to encrypt."<<endl;
vector<string> str(n);
for(int i=0;i<n;i++){
cin>>str[i];
}
cout<<"Now enter the level of encryption, from 0 to 30. "<<endl;
int k;
cin>>k;
cout<<"The encrypted string is ";
cifrado(str,k);
for(string s:str){
cout<<s<<" ";
}cout<<endl;
return 0;
}
Comments
Post a Comment