Guest User

Untitled

a guest
Mar 22nd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. //Vigenere Cipher
  6.  
  7. int main(){
  8. string s,keyWord;
  9. cin>>s>>keyWord;
  10. for(int i=0;i<keyWord.length();i++){
  11. if(keyWord[i]>=97&&keyWord[i]<=122)
  12. keyWord[i]-=32;
  13. }
  14. string key=keyWord;
  15. while(key.length()<s.length())
  16. key+=keyWord;
  17. char a[26][26];
  18. char c;
  19. char d='A';
  20. for(int i=0;i<26;i++){
  21. c=d;
  22. for(int j=0;j<26;j++){
  23. a[i][j]=c;
  24. if(c=='Z'){
  25. c='A';
  26. c--;
  27. }
  28. c++;
  29. }
  30. d++;
  31. }
  32. string plainText;
  33. for(int i=0;i<s.length();i++){
  34. int x=key[i]-65;
  35. for(int j=0;j<26;j++){
  36. if(a[x][j]==s[i]){
  37. plainText[i]=j+65;
  38. break;
  39. }
  40. }
  41. cout<<plainText[i];
  42. }
  43. return 0;
  44. }
Add Comment
Please, Sign In to add comment