-
-
Save harshita-jain28/c2f9ee0182fc61e99f6d0ca941a59763 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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