Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> #include <string> #include <cstdlib >
- using namespace std ;
- void
- inputError (){ c o u t <<” u s a g e : ”<< e n d l ; cout<<”./a1q3a.o {e,d}”<<endl; exit (1);
- 
- } void normalize(string ⇤txt , int size){
- char ⇤c; for (int i=0;i<size;i++){
- c=&(⇤txt )[ i ]; if ((⇤c>=’a’)&&(⇤c<=’z’)){
- } ⇤ c =96; else if((⇤c>=’A’)&&(⇤c<=’Z’)){
- } ⇤ c =64;
- else{⇤c=0;
- } }
- } int main(int argc, const char ⇤ argv[]){
- if (argc !=2){ inputError ();
- }
- string cmd=argv [1]; bool encode =1;
- if (cmd==”e”){ }
- else if (cmd==”d”){ encode =0;
- }
- else{inputError (); }
- string input , key , output ;
- 11
- CO 487: Assignment #1
- Denis Miroshnikov 20447593
- 
- i f ( encode ){ cout<<”Plain”;
- }
- else{cout<<”Cipher”; }
- cout<<”text :”<<endl<<endl ; getline(cin ,input); cout<<endl<<”Key:”<<endl<<endl ; getline(cin ,key);
- int size=min(input.size(),key.size());
- normalize(&input , size ); normalize(&key , size );
- output.resize(size,’ ’); char c;
- for(int j=0;j<size ; j++){
- i f ( encode ){ c=(input [ j ]+key [ j ])%27;
- }
- e l s e {c = ( i n p u t [ j ] k e y [ j ] ) ; if (c<0){
- c +=27;
- } }
- if (c){ output [ j]=c+64;
- }e l s e {o u t p u t [ j ] = c + 3 2 ;
- } }
- cout<<endl ; if (! encode){
- cout<<”Plain”;
- }else{cout<<”Cipher”; }
- 
- 12
- CO 487: Assignment #1
- Denis Miroshnikov 20447593
- 
- cout<<”text :”<<endl<<endl ;
- cout<<output<<endl ; }
Advertisement
Add Comment
Please, Sign In to add comment