Click here to Skip to main content
15,909,605 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why is this run time error occurring as "Unable to open Maths.lib"

C++
//Caesar Cipher

#include<iostream.h>
#include<conio.h>
//#include<string.h>
//#include<process.h>

char username[20];
char plain_text[20];
char cipher_text[20];

char encrypt(char,int);
//class Caesar
//{
// public:
void main()
{

	 cout<<"\n Enter your username";
	 cin>>username;

	 cout<<"\n Enter your password (it must be only characters)";
	 cin>>plain_text;

	 for(int i=0;i<20;i++)
	 {
	  switch(plain_text[i])
	  {
	   case 'a':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	   case 'b':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'c':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'd':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'e':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'f':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'g':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'h':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'i':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'j':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'k':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'l':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'm':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'n':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'o':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'p':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'q':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'r':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 's':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 't':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'u':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'v':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'w':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'x':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'y':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    case 'z':
		    cipher_text[i]=encrypt(plain_text[i],i);
		    break;
	    default: cout<<"\n Please enter only lowercase characters";
		    break;
	    }
	  }
 cout<<"The encrypted password is:- ";
    for(i=0;i<20;i++)
    {
     cout<<cipher_text[i];
    }

  getch();
 }

char encrypt(char letter,int j)
	{
	  int i=j;
	 switch(letter)
	  {
	   case 'a':
		    letter=plain_text[i+5];
		    break;
	   case 'b':
		    letter=plain_text[i+5];
		    break;
	    case 'c':
		    letter=plain_text[i+5];
		    break;
	    case 'd':
		    letter=plain_text[i+5];
		    break;
	    case 'e':
		    letter=plain_text[i+5];
		    break;
	    case 'f':
		    letter=plain_text[i+5];
		    break;
	    case 'g':
		    letter=plain_text[i+5];
		    break;
	    case 'h':
		    letter=plain_text[i+5];
		    break;
	    case 'i':
		    letter=plain_text[i+5];
		    break;
	    case 'j':
		    letter=plain_text[i+5];
		    break;
	    case 'k':
		    letter=plain_text[i+5];
		    break;
	    case 'l':
		    letter=plain_text[i+5];
		    break;
	    case 'm':
		    letter=plain_text[i+5];
		    break;
	    case 'n':
		    letter=plain_text[i+5];
		    break;
	    case 'o':
		    letter=plain_text[i+5];
		    break;
	    case 'p':
		    letter=plain_text[i+5];
		    break;
	    case 'q':
		    letter=plain_text[i+5];
		    break;
	    case 'r':
		    letter=plain_text[i+5];
		    break;
	    case 's':
		    letter=plain_text[i+5];
		    break;
	    case 't':
		    letter=plain_text[i+5];
		    break;
	    case 'u':
		    letter=plain_text[i+5];
		    break;
	    case 'v':
		    letter=plain_text[i+0];
		    break;
	    case 'w':
		    letter=plain_text[i+1];
		    break;
	    case 'x':
		    letter=plain_text[i+2];
		    break;
	    case 'y':
		    letter=plain_text[i+3];
		    break;
	    case 'z':
		    letter=plain_text[i+4];
		    break;
	    default: cout<<"\n Please enter only lowercase characters";
		    break;
	   }
	  return letter;
	 }
Posted
Updated 22-Dec-11 4:03am
v4
Comments
Richard MacCutchan 22-Dec-11 7:36am    
Show the exact error message and which line it is referring to.
Resmi Anna 22-Dec-11 8:13am    
you have written the function encrypt()within ur main
CurrentlyBE 22-Dec-11 9:41am    
is my logic for Caesar correct and even if it is correct is this the only way.

about the line:
char encrypt(char letter)


My compiler reports:
C++
error C2601: 'encrypt' : local function definitions are illegal


and (of course) it is right. You cannot have local functions in C++ (though you may have lambdas).

Put encrypt out of the main body.
 
Share this answer
 
Comments
RaisKazi 22-Dec-11 9:40am    
My 5.
CPallini 22-Dec-11 15:19pm    
Thank you.
Albert Holguin 22-Dec-11 11:07am    
Looks like he or someone else changed the code (didn't look too closely at the version history, just noticed it's different)... +5 anyway...
CPallini 22-Dec-11 15:19pm    
Thank you.
CurrentlyBE 22-Dec-11 11:43am    
yes I updated the question as first error was solved but new one has occurred
Unable to open Maths.lib
Your code is too lengthy and stuffy. I found the best code here:
http://wncoder.blogspot.in/2012/05/c-caesar-cipher-code.html
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900