Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int encryptioncheck(string koodi){
- string::size_type pituus = 0;
- pituus = koodi.length();
- if (pituus != 26){
- cout << "Error! The encryption key must contain 26 characters." << endl;
- return EXIT_FAILURE;
- }
- std::locale loc;
- std::string str=koodi;
- for (std::string::iterator it=str.begin(); it!=str.end(); ++it)
- {
- if (std::isalpha(*it,loc) and std::islower(*it,loc))
- continue;
- else
- std::cout << "Error! The encryption key must contain only lower case characters." << endl;
- return EXIT_FAILURE;
- }
- for (char a = 'a'; a < 'z'; a++) {
- if (koodi.find(a) == std::string::npos) {
- std::cout << "Error! The encryption key must contain all alphabets a-z." << std::endl;
- return EXIT_FAILURE;
- }
- }
- return 0;
- }
- char encrypt(string encryption, char c) {
- string alphabet = "abcdefghijklmnopqrstuvwxyz";
- string::size_type encrypted = alphabet.find(c);
- return encryption[encrypted];
- }
- int main()
- {
- string encryption_key = " ";
- string encrypted = "";
- cout << "Enter the encryption key: ";
- cin >> encryption_key;
- if (encryptioncheck(encryption_key) == EXIT_FAILURE){
- return EXIT_FAILURE;
- }
- else {
- string text = " ";
- cout << "Enter the text to be encrypted: ";
- cin >> text;
- for (char& c : text) {
- encrypted += encrypt(encryption_key, c);
- }
- cout << "Encrypted text: " << encrypted << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement