cout << ,nn, ,nn,;; return -; return -; 6 int menu int menu ) cout << ,tt Caesar Cipher n,; n, ; cout << ,tt22222222222222222n, ,tt22222222222222222n,;; cout << ,ncryption ................ 091n,; 091n,; cout << ,Becryption ................ 0+1n,; 0+1n,; cout << ,it o8 ................ 0&1n, 0&1n,;; cout << ,n t >> , ; , ; int choice int choice ; cin >> choice ; return choice return choice ; 6
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD /* * Type : Monoalphab Monoalphabetic etic Substitution Cipher * AEne Cipher */ /* to ncrypt Fith AEne Cipher : c % m * p 'ey )mod n 8here m is Multiplirer @ p is character in plaintet @ 'ey is shi(t number @ n is alpha siGe ote : to choose the right right m @ it must the the CB)m@n % 9 @ i.e m and n is relati!e relati!e prime number number @ i.e must use CB method to chec' To T o Becryption 8ith AEne AEne Cipher : p % mH * ) c 2 'ey )mod n 8here mH is is the the in!erse in!erse o( m ote : to obtain the mH it must use tended uclid=s Method */ #include #include #include #include using namespace namespace std; std; class AEneCipher class AEneCipher public : public : bool chec'"ey bool chec'"ey )int )int m m @ int int n n ; // chec' to see i( CB)m@n %% 9 @ return true i( that @ (alse i( not int CB ) int int m m @ int int n n ; // return reatest comman Bi!isor int getIn!erse )int int m m @int @int n n ; // return mH by using tended uclid method string encryption )string plainTet plainTet @ int int m m @ int int 'ey 'ey @ int int n n ; string decryption )string cipherTet @ int int m m @ int int 'ey 'ey @ int int n n ; 6; int AEneCipher int AEneCipher :: CB )int )int @ int int y y i( ) ) y %% - return return ; else return CB)y@5y; return CB)y@5y; 6 int AEneCipher int AEneCipher :: getIn!erse )int ) int m m @ int int n n int sint s- % 9 @ s9 % - ; int tint t- % - @ t9 % 9 ; // sa!e this number in !aribale int rint r- % m ; int r9 int r9 % n ;
// J9 is the Joution int J % r- / r9 ; int r+ % r- 5 r9 ; int s+ @ t+ ; 8hile ) r+ > - s+ % s- 2 )s9 * J ; s- % s9 ; s9 % s+ ; t+ % t- 2 )t9 * J ; t- % t9 ; t9 % t+ ; r- % r9; r9 % r+ ; J % r- / r9 ; r+ % r- 5 r9 ; 6 return s9 ; 6 bool AEneCipher :: chec'"ey )int m @int n i( ) CB)m@n %% 9 return true ; else return (alse; 6 string AEneCipher :: encryption )string plainTet @ int m @ int 'ey @ int n string str+ % ,, ; (or )int i%- ; i
int % ) ) in!erseDM * ) ))intcipherTet0i1 2 34 2 'ey 5 n ; str+ % )char34 ; 6 return str+ ; 6 int menu ) ; int main) AEneCipher aEne ; bool state % true ; 8hile )state s8itch ) menu) case 9: cout << ,nnter The lain Tet : n,; string str ; char ch ; 8hile ) )ch%getche) % =r= i( ) ch %% = = continue ; str % ch ; 6 int m @ n @ 'ey;
// n % +3 @ i( english
character cout << ,nnter The Multiplier M : , ; cin >> m ; cout << ,nter The "ey )Shi(t : , ; cin >> 'ey ; cout << ,nter The Alpha SiGe : , ; cin >> n; i( ) aEne.chec'"ey)m@n cout << ,CB), << m << ,@, << n << , % 9tCorrect n,; cout << ,The Cipher Tet is : , << aEne.encryption)str@m@'ey@n << endl; 6 else cout << ,CB), << m << ,@, << n << , % 9 tIncorrect n,@ cout << ,$ou Must Choose Another M and n, ; brea' ;
6 case +: cout << ,nnter The Cipher Tet : n,; string str ; char ch ; 8hile ) )ch%getche) % =r= i( ) ch %% = = continue ; str % ch ; 6 int m @ n @ 'ey;
// n % +3 @ i( english
character cout << ,nnter The Multiplier M : , ; cin >> m ; cout << ,nter The "ey )Shi(t : , ; cin >> 'ey ; cout << ,nter The Alpha SiGe : , ; cin >> n; i( ) aEne.chec'"ey)m@n cout << ,CB), << m << ,@, << n << , % 9tCorrect n,; cout << ,The lain Tet is : , << aEne.decryption)str@m@'ey@n << endl; 6 else cout << ,CB), << m << ,@, << n << , % 9 tIncorrect n,@ cout << ,$ou Must Choose Another M and n, ; brea' ;
6 case &: int m @ n ;
// n % +3 @ i( english
character cout << ,nter The Multiplier M : , ; cin >> m; cout << ,nter The Alpha SiGe : , ; cin >> n; i( )aEne.chec'"ey)m@n cout << ,Correct "eyn,; else