Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. string crypt(string line, string type, string alphabet, int &k){
  2.  
  3.   if(k>alphabet.length()) k=k%alphabet.size();
  4.   if(!strcmp(type.c_str(),"decode")){
  5.      k=k*(-1);
  6.   }
  7.     for(int i=0;i<strlen(line.c_str());i++){
  8.         int j=-1;
  9.         while (line[i]==alphabet[++j]);
  10.         int shift shift=(j+k+alphabet.length())%alphabet.length();
  11.         line[i]=alphabet[shift];
  12.     }
  13.   return line;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement