Skip to content

Instantly share code, notes, and snippets.

@harshita-jain28
Created January 14, 2021 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshita-jain28/c2f9ee0182fc61e99f6d0ca941a59763 to your computer and use it in GitHub Desktop.
Save harshita-jain28/c2f9ee0182fc61e99f6d0ca941a59763 to your computer and use it in GitHub Desktop.
#include<iostream>
using namespace std;
string get_key(string str, string key){
if(key.size() >= str.size())
return key;
else{
int str_size = str.size()-key.size();
int key_size = key.size();
while(str_size >= key_size){
key += key;
str_size -= key_size;
}
key += key.substr(0, str_size);
return key;
}
}
string encrypt_pass(string str, string key){
string temp = "";
for(int i=0;i<str.size();i++)
temp += (char) (((int)str[i]-'A' + (int)key[i]-'A') % 26) + 'A';
return temp;
}
int main(){
string password;
cin>>password;
string key = "HELLO";
key = get_key(password, key);
string encrypt = encryption(plaintext, key);
cout<<" encrypted password: "<< encrypt <<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment