Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("vigenere.in");
- ofstream fout("vigenere.out");
- string text, cod;
- void encrypt_vigenere(const string& plaintext, const string& key)
- {
- string ciphertext;
- unsigned int i, j, ch;
- for(i = 0, j = 0; i < plaintext.length(); ++i, j++) {
- if(j >= key.length())
- j = 0;
- if(plaintext[i] >= 'A' && plaintext[i] <= 'Z')
- ch = ((plaintext[i] - 'A') + (key[j] - 'A')) % 26;
- else
- ch = ((plaintext[i] - 'a') + (key[j] - 'a')) % 26;
- if(isupper(ch))
- ciphertext += (char)(ch + 'A');
- else
- ciphertext += (char)(ch + 'a');
- }
- fout<< ciphertext;
- }
- int main()
- {
- fin>>text>>cod;
- encrypt_vigenere(text, cod);
- return 0;
- }
Add Comment
Please, Sign In to add comment