C++ Xecryption Code Help

Re: C++ Xecryption Code Help

Post by Smeezinator on Sat Sep 13, 2008 12:25 pm
([msg=11611]see Re: C++ Xecryption Code Help[/msg])

Okay I just changed some stuff and got it to compile without errors! Here's what the code is now:
Code: Select all
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;

//Randomizing function:
signed int rmz(void)
   {srand((unsigned)time(0));
    int random;
    int lowest= -10, highest= 10;
    int range= (highest-lowest)+1;
    random = lowest + int(range*rand() /(RAND_MAX + 1.0));
    return random;}
   
//Encrypting function:
void charfunc (char tcha[], int key)
   {int num1, num2, num3, i, intarray[1000];
    for (i=0; tcha[i] != '\0'; i++)
        {intarray[i]=(int)tcha[i];
         num1=((intarray[i]+key)/3)+rmz();
         num2=((intarray[i]+key)/3)+rmz();
         num3=((num1+num2)-intarray[i])+key;
         cout << '.' << num1 << '.' << num2 << '.' << num3;}}
        
        
int main()
{char tcha[1000], pcha[20], answer;
  int key, aspch;
  bool running=true;
  do
    {     cout << "Type or paste some text to encrypt (under 1000 characters): " << endl;
      cin >> tcha;
      cout << endl << "Now enter the password (under 20 characters): ";
      cin >> pcha;
      
      //Making the password into a number (key):
      for (int i=0; pcha[i] != '\0'; i++)
         {aspch=(int)pcha[i];
          key+=aspch;}
         
      charfunc(tcha, key);
      
      cout << endl << endl << "Encrypt more text? [y/n] ";
      cin >> answer;
      if (answer=='y')
         break;
      else
        {return 0;
          running=false;}}
   while (running==true);}


So as I said, this compiles fine and I was really pleased! BUT... it doesn't work right. D: When I run it here's what happens (my input is in bold, comments in italics):

Type or paste some text to encrypt (under 1000 characters):
hello this is a test
Now enter the password (under 20 characters): <--Not waiting for a response here .-402823458.-402823458.-2014117468.-402823459.-402823459.-2014117467.-402823456.-402823456.-2014117468.-402823456.-402823456.-2014117468.-402823455.-402823455.-2014117469
Encrypt more text? [y/n] <--Once again not waiting for my response, it just ends the program!
Smeezinator
New User
New User
 
Posts: 20
Joined: Sat Jun 28, 2008 5:22 pm
Blog: View Blog (0)


Re: C++ Xecryption Code Help

Post by leonidas_heaven on Sun Sep 14, 2008 12:17 am
([msg=11646]see Re: C++ Xecryption Code Help[/msg])

No this can't happen u may be kidding with us..
cin>>blah ;
should work..
Challenges are not meant to be taken easily,rather they are meant to be taken Seriously
leonidas_heaven
Experienced User
Experienced User
 
Posts: 66
Joined: Sun Jun 01, 2008 5:20 am
Location: Uttarakhand,India
Blog: View Blog (0)


Re: C++ Xecryption Code Help

Post by Smeezinator on Sun Sep 14, 2008 10:37 am
([msg=11713]see Re: C++ Xecryption Code Help[/msg])

No that's really what's happening... :?
Smeezinator
New User
New User
 
Posts: 20
Joined: Sat Jun 28, 2008 5:22 pm
Blog: View Blog (0)


Re: C++ Xecryption Code Help

Post by Orion001 on Wed Oct 08, 2008 4:30 am
([msg=13381]see Re: C++ Xecryption Code Help[/msg])

Hey, I copied your code from above and used it as-is in visual studio, it worked fine, it had 1 warning, 0 errors, and paused for each cin command. When i input the password (i used 'a'), it came up with a runtime error, but i pressed continue instead of debug, and it displayed the encrypted version, asked me if I still wanted to encrypt more text, i typed in y (seeing as it waited for me), and then it quit (which seems kinda pointless...).

but yeh, your cin works fine, try creating a completely new document, pasting in that code, and compiling it.

Hope iv helped somewhat
Orion001
New User
New User
 
Posts: 36
Joined: Tue Sep 09, 2008 5:44 am
Blog: View Blog (0)


Re: C++ Xecryption Code Help

Post by Smeezinator on Sun Oct 12, 2008 7:16 am
([msg=13593]see Re: C++ Xecryption Code Help[/msg])

Thanks! But when it encrypts your message are you getting the three digit numbers that it's supposed to make or are you getting the really long ones that I'm getting?
When I ran it again it worked but it still didn't wait for a password... :(
Smeezinator
New User
New User
 
Posts: 20
Joined: Sat Jun 28, 2008 5:22 pm
Blog: View Blog (0)


Re: C++ Xecryption Code Help

Post by Orion001 on Wed Oct 15, 2008 2:24 am
([msg=13727]see Re: C++ Xecryption Code Help[/msg])

Smeezinator wrote:Thanks! But when it encrypts your message are you getting the three digit numbers that it's supposed to make or are you getting the really long ones that I'm getting?
When I ran it again it worked but it still didn't wait for a password... :(


I dont get 3 digits... i get quite a few digits followed by a comma, followed by more digits, and so on. It always waited, but I dont know how many times I ran it..
Orion001
New User
New User
 
Posts: 36
Joined: Tue Sep 09, 2008 5:44 am
Blog: View Blog (0)


Previous

Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests