Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Decryption help!!!

encryption

  • Please log in to reply
21 replies to this topic

#1 maria536

maria536

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 10 November 2011 - 06:47 AM

I have tried to start this program but I am so confused with dealing with strings. If any one could take a look it would be greatly appreciated. Heres the problem and what I have so far:

An organization wants to use encryption to protect classified information from eavesdroppers. The organization has developed an algorithm that encodes a string of characters into a series of integers between 0 and 94, inclusive. You have been asked to develop an application that decrypts this series of integers into its corresponding string of characters. The user should enter each integer of the encrypted message one at a time. After each integer is entered, the application should convert (that is, decrypt) the integer to its corresponding character, after which the application should display the string of characters that have already been decrypted. If the user enters a value that is less than zero or greater than 94, the application should terminate input.

2. Adding a global variable. Before main, add a definition for a string named message, which will hold the decrypted message. Initialize message to the empty string. Use one line for a comment.

3. Declaring a function prototype. After the variable you defined in Step 3, declare a function prototype for the decryptLetter function, which accepts an int parameter and does not return a value.

4. Defining a local variable, prompting the user for and storing the encrypted letter. Add code in main to define int variable named input, then prompt the user for and store the encrypted letter in that variable.

5. Testing the user input. Insert a while repetition statement that executes while the user input is in the range 0 to 94. This ensures that input terminates when the user enters a sentinel value.

6. Decrypting the input. Inside the while statement, call the decryptLetter function with input as its argument. This function, which you will define in Step 9, will decrypt the letter and append the character to string message.

7. Displaying output and prompting the user for the next input. Inside the while statement, add code to display the string message. Before the closing brace of the while statement, add code to prompt the user for and store the next encrypted letter.

8. Decrypting the input. After main, define the decryptLetter function, which accepts int parameter encryptedLetter. Letters should be decrypted by first adding 32 to the int. This value should then be converted to a char type. [ Note: You can implicitly convert an int to a char by assigning the value of an int to a char variable.] This calculation results in the number 1 decrypting to the character '!' and the number 33 decrypting to the character ' A'. To append the decrypted character to message, use the += operator. For example, message += ' A' appends the character ' A' to the end of message.

#include <iostream> // required to perform C++ stream I/O
#include <string>  // required for parameterized stream manipulators

using namespace std; // for accessing C++ Standard Library members

//string 
string message; //will hold the encoded message

//function prototype
void decryptLetter(char encryptedLetter){ 
 char decrypt = /* encryptLetter plus 32 */
 message = // message plus decrypet
 //done
}
// function main begins program execution
int main()
{
    int input; // user input

    //prompt for user input
    cout <<"\nEnter encrypted letter ( 0-94; -1 to exit): ";
    cin >> input;

    while ( input > 0 && input < 94)
    {
         message = decryptLetter (input);
    
    }



   cout << "\n"; // insert newline for readability
   return 0; // indicate that program ended successfully

} // end function main

//define decryptLetterFunction
void decryptLetter (int)
{
    int encryptedLetter;

}

THANKS FOR ANY HELP I CAN GET!!!!

Edited by WingedPanther, 10 November 2011 - 06:56 AM.
add code tags (the # button)

  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 10 November 2011 - 06:58 AM

I added code tags for you (the # button).

What's your question?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 maria536

maria536

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 10 November 2011 - 07:10 AM

I get the following errors:

1>------ Build started: Project: Decryption, Configuration: Debug Win32 ------
1>Compiling...
1>Decryption.cpp
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial11\exercises\decryption\decryption\decryption\decryption.cpp(18) : error C2059: syntax error : '}'
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial11\exercises\decryption\decryption\decryption\decryption.cpp(30) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(914): could be 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const std::basic_string<_Elem,_Traits,_Ax> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(919): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const _Elem *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(924): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(_Elem)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> while trying to match the argument list '(std::string, void)'
1>Build log was saved at "file://c:\Documents and Settings\pdmmonte\Desktop\SimplyCpp\Tutorial11\Exercises\Decryption\Decryption\Decryption\Debug\BuildLog.htm"
1>Decryption - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Edited by Roger, 10 November 2011 - 10:03 AM.

  • 0

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 10 November 2011 - 07:14 AM

one problem: what you labeled as a prototype has code in it that cannot be compiled.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 maria536

maria536

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 10 November 2011 - 07:22 AM

Ok, I took that out but I still have errors!!!
  • 0

#6 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 10 November 2011 - 07:55 AM

What is the current code/errors?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#7 maria536

maria536

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 10 November 2011 - 08:02 AM

More output capture

1>------ Build started: Project: Decryption, Configuration: Debug Win32 ------
1>Compiling...
1>Decryption.cpp
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial11\exercises\decryption\decryption\decryption\decryption.cpp(27) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(914): could be 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const std::basic_string<_Elem,_Traits,_Ax> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(919): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const _Elem *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(924): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(_Elem)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> while trying to match the argument list '(std::string, void)'
1>Build log was saved at "file://c:\Documents and Settings\pdmmonte\Desktop\SimplyCpp\Tutorial11\Exercises\Decryption\Decryption\Decryption\Debug\BuildLog.htm"
1>Decryption - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Edited by Roger, 10 November 2011 - 10:05 AM.
added quote tags

  • 0

#8 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 10 November 2011 - 08:45 AM

Beginning with the first error: what's on line 27?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#9 maria536

maria536

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 10 November 2011 - 08:49 AM

message = decryptLetter (input);
  • 0

#10 AKMafia001

AKMafia001

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 118 posts

Posted 10 November 2011 - 09:44 AM

//function prototype
void decryptLetter(char encryptedLetter){ 

}
//define decryptLetterFunction
void decryptLetter(int)
{

}

These aren't prototype and definition of decryptLetter(). Both are definitions and you have overloaded it for the type int.

---------- Post added at 10:34 PM ---------- Previous post was at 10:30 PM ----------

message = decryptLetter (input);


I don't see that the message is declared in your main().

---------- Post added at 10:36 PM ---------- Previous post was at 10:34 PM ----------

The code isn't doing anything. The errors are fixed and your program will work now.

Hope it helped!

---------- Post added at 10:44 PM ---------- Previous post was at 10:36 PM ----------

Well! If you fix it and get some more code -- you have to figure out this,
message = decryptLetter(input);

Here, the expect that the function is returning and you assign that return value to a variable. While your function,
void decryptLetter(parameter(s))
{

}
is not returning. The return type is void.
  • 0
I think i'm able to write a code for printing "Hello, World!". Proud of that!

#11 maria536

maria536

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 10 November 2011 - 09:48 AM

Ok, now I am really confused, Here is my code thus far.

#include <iostream> // required to perform C++ stream I/O
#include <string>  // required for parameterized stream manipulators

using namespace std; // for accessing C++ Standard Library members

//string 
string message; //will hold the encoded message

//function prototype
void decryptLetter(char encryptedLetter){ 

} 
// function main begins program execution
int main()
{
	int input; // user input

	//prompt for user input
	cout <<"\nEnter encrypted letter ( 0-94; -1 to exit): ";
	cin >> input;

	while ( input > 0 && input < 94)
	{
		 message = decryptLetter (input);
	
	}



   cout << "\n"; // insert newline for readability
   return 0; // indicate that program ended successfully

} // end function main

//define decryptLetterFunction
void decryptLetter (int)
{
	
}
this is my error now;

1>------ Build started: Project: Decryption, Configuration: Debug Win32 ------
1>Compiling...
1>Decryption.cpp
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial11\exercises\decryption\decryption\decryption\decryption.cpp(28) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(914): could be 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const std::basic_string<_Elem,_Traits,_Ax> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(919): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const _Elem *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(924): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(_Elem)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> while trying to match the argument list '(std::string, void)'
1>Build log was saved at "file://c:\Documents and Settings\pdmmonte\Desktop\SimplyCpp\Tutorial11\Exercises\Decryption\Decryption\Decryption\Debug\BuildLog.htm"
1>Decryption - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Edited by Roger, 10 November 2011 - 10:06 AM.
added [code] tags

  • 0

#12 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 10 November 2011 - 10:09 AM

decryptLetter is declared as type void. You can't put that on the right-hand side of an =. Either change it's return type or do something else.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/






Also tagged with one or more of these keywords: encryption

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download