Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. string crypt(string line, string type, string alphabet, int k){
  2. if(!strcmp(type.c_str(),"decode")){
  3. if(k>alphabet.size()) k=-(k%alphabet.size());
  4. if(k<=alphabet.size()) k=-k;
  5. }
  6.  
  7. for(int i=0;i<strlen(line.c_str());i++){
  8. for(int j=0;j<alphabet.size();j++){
  9. if(line[i]==alphabet[j]){
  10. if(k>alphabet.size()) k=k%alphabet.size();
  11. int shift=(j+k+alphabet.size())%alphabet.size();
  12. line[i]=alphabet[shift];
  13. break;
  14. }
  15. }
  16. }
  17. return line;
  18. }
  19.  
  20. void text(string alphabet, string type,int k, string source, string dest){
  21. string line;
  22. ifstream fin(source.c_str());
  23. getline(fin,line);
  24. line=crypt(line,type,alphabet,k);
  25. fin.close();
  26. ofstream fout(dest.c_str());
  27. for(int i=0;i<strlen(line.c_str());i++){
  28. fout<<line[i];
  29. }
  30. fout.close();
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement