Page 1 of 2 12 LastLast
Results 1 to 15 of 22

Thread: Um... i didn't want this source to go public but...

  1. #1
    Join Date
    Apr 2005
    Location
    Pennsylvania, USA
    Posts
    520
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Um... i didn't want this source to go public but...

    I know there isn't much to it, but i was making a "fun program" that i was gonna release on downloads.com but i really didn't wanna release the source code. (if you read it and figure out the nature you'll understand why.) But for some reson the cin.getline is compleatly ignored for both arrays of "pass". I may change this around a little bit and add some extra encoding stuff to it after this is solved due to the fact i had to release the source code to the public. Can some one take a shot at it?

    Download Links:
    Links are hidden from guests. Please register to be able to view these links. Also could anyone give me some kinda clue how to use resource files so i could try embedding some things within the exe itself like if i ever add music to one of my future projects i'd like to know how to put it in the exe, but my top priority is getting this fixed and up on cnet or somthing.

    I really hate this... it's how "leaking" occures. Oh well, at least it wasn't encoding of some really really huge 3d game i was making or anything along those lines.
    Last edited by kohlrak; 17th-August-2005 at 12:20.

  2. #2
    Join Date
    Feb 2005
    Location
    Limbo
    Posts
    3,706
    Thanks
    0
    Thanked 2 Times in 2 Posts
    EP Points
    10

    Default

    I'm trying to understand the code first It seems like some basic coding/decoding algorithm. Though you should use something harder to decode, addition/substraction will NOT be enough, I've already decoded some formats that used that method. Go with binary XOR, but even that can be hacked.

    Actually, I can't seem to figure out what that passcount/readcount stuff does.
    First, the passcount/readcount could be set just by getting the length of the string/array.
    Second, that passcount/readcount_two thing is totally unnecessary, you could simply alter the current character with the pass[fpos % passlength], where fpos is the current file position, and passlength is the length of the password.
    Third, what the heck does passcount++; passcount--; do?

    Another suggestion, combine the 2 functions into one. Whether it codes or decodes depends on its argument. With XOR that won't even be necessary. Getting filenames from the command line would be nice, too.

    As to why the getline doesn't work... read is an array, not a stream. You should not even be using that function, if you do not want to be able to only code/decode text files. Plus, it would be hell if something got encrypted so that it would be a new line character, when it is not. So, use binary mode.

    Anyway, don't worry about releasing simple source code like this to the public, unless it is of malicious nature, of course.

  3. #3
    Join Date
    Apr 2005
    Location
    Pennsylvania, USA
    Posts
    520
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well really it's ment to be simple and i really don't want anyone copying the idea and making people pay for it. Plus, the last time i used binary mode and opened a file and mearly wrote it to another (basically a test when i made a program to open an exe and write a new one from the old one the very same way to try encryption later, didn't go as planned. Basically all i want this program to do is read text, then add and subtract ASCII values of a "password" which is user input. Basically, i figured out as much as ifstream has a thing against going 1 char at a time. So i'm trying to get the data into the array using cin. Any ideas?

    and as for using the bitwise operators to encode... um, that's the last thing of C++ i feel i'll ever understand. I guess it's my fault from ignoring the warnings that say don't make C++ your first programming language to learn.

  4. #4
    Join Date
    Feb 2005
    Location
    Limbo
    Posts
    3,706
    Thanks
    0
    Thanked 2 Times in 2 Posts
    EP Points
    10

    Default

    Just use the getline function properly.
    Instead of

    fin.getline(read, max, '\n')

    MSDN says it should be

    getline(fin,read,'\n')

    Never used it, though.

  5. #5
    Join Date
    Apr 2005
    Location
    Pennsylvania, USA
    Posts
    520
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I thought the first parameter was for the variable name where the data is to be stored. o.o

    I'm trying your idea and now i'm getting error messages galor...

    --------------------Configuration: Cpp1 - Win32 Debug--------------------
    Compiling...
    Cpp1.cpp
    C:\Documents and Settings\Kohlrak\Cpp1.cpp(30) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : could not deduce template argument for 'class
    std::basic_istream<_E,_Tr> &' from 'class std::basic_ifstream<char,struct std::char_traits<char> >'
    C:\Documents and Settings\Kohlrak\Cpp1.cpp(30) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : could not deduce template argument for 'class
    std::basic_string<_E,_Tr,_A> &' from 'char [99999]'
    C:\Documents and Settings\Kohlrak\Cpp1.cpp(30) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : expects 2 arguments - 3 provided
    e:\vc98\include\string(140) : see declaration of 'getline'
    C:\Documents and Settings\Kohlrak\Cpp1.cpp(71) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : could not deduce template argument for 'class
    std::basic_istream<_E,_Tr> &' from 'class std::basic_ifstream<char,struct std::char_traits<char> >'
    C:\Documents and Settings\Kohlrak\Cpp1.cpp(71) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : could not deduce template argument for 'class
    std::basic_string<_E,_Tr,_A> &' from 'char [99999]'
    C:\Documents and Settings\Kohlrak\Cpp1.cpp(71) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : expects 2 arguments - 3 provided
    e:\vc98\include\string(140) : see declaration of 'getline'
    Error executing cl.exe.

    Cpp1.exe - 6 error(s), 0 warning(s)
    How i love the "std::basic" things where they refer to it as somthing other than the names in the namespace we're using. I never trust microsoft, despite that's what makes my compiler and my OS... pkt, while you're at it, think you can come up with a logical explimation of the bitwise operators? X'D Maybe it's the binary part that i can't comprehend... Plus my real error is in the "cin.getline(pass, max, '\n');" part, not the file input, it dosn't even get that far. It just skips over it.

  6. #6
    Join Date
    Feb 2005
    Location
    Limbo
    Posts
    3,706
    Thanks
    0
    Thanked 2 Times in 2 Posts
    EP Points
    10

    Default

    WOW, that's a bunch of errors. Now I gotta go compile it and all.

    Oh, hey. Wait.

    "cin.getline" does not work for the same reason as "fin.getline". Those stream classes don't have such a method (at least I didn't find it) It should be getline(inputstream,output,separatorchar)

    So, after I try to explain bitwise operators I really will go and compile it. Honest.

    I assume you know the logical operators, AND, OR, NOT, and XOR, so I'll skip the truth tables. So, the corresponding bitwise operators do this bit by bit in some piece of data (don't forget that any data is ultimately stored in binary form, that is 10001010) So, for example, take AND logical operator, and replace every 'true' in the truth table with 1, the 'false's with 0. There you got, that's the basic workings of these operators.

    You're surely asking what this is good for. To do operations on a binary level, of course! This can save you a lot of space and long, ineffiecent code when dealing with switches (that would be the ideal case, since basic switches have only 2 positions, ON and OFF = 1 and 0 bits) You'll see that if you need to pass switches to a function you'll usually be using macros and the binary OR operator. This way, 8 switches can be easily read from a single byte.

    So, on to actual usage. You've got yourself a byte, and want to use it for reading/writing the status of some switches. For this you'll need a 'key'. This will have 0 bits everywhere, except for the switches you want to operate on. So, if you want to operate the third switch so it will be ON, you'll need something like this.
    Download Links:
    Links are hidden from guests. Please register to be able to view these links. That can be done by the OR operator ( | ), since S | K (s and k are short for switch and key bit) will only equal to 0 if both of them are zero. This way the other switches won't get altered, only the one we want will be turned on if it isn't already.
    To get the state of the switch, you'll need to use the AND operator ( & ). S & K only returns 1 if both are equal to one. Since in the case of the non-tested switches K is always 0, this will only check the bits that are set to 1 in the 'key'.
    The XOR operator ( ^ ) switches the selected bits. S ^ K will return !S ( NOT s, obviously !1=0 and vice versa) if K is 1.

    Other bitwise operators are shifting (which is essentially mulitplying/dividing by two) It's almost the same as adding / taking a zero from a number in decimal format - just that it's binary, and that results in multiplication/division by 2, not 10. This is useful when setting the key. Since 00000001 = 1, 00000100 = 4, it's easier to write 1 << 2, since the '1' goes two positions to the left.
    Last edited by pkt-zer0; 6th-August-2005 at 11:29.

  7. #7
    Join Date
    Apr 2005
    Location
    Pennsylvania, USA
    Posts
    520
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i don't know where you've been looking but even the C++ tutorial that came with my compiler (also supported) states that it's called "cin.getline" and "fin.getline". Even the compiler has kinda like an auto complete thing for things like that. fin and cin both have a getline() function in the standard libraries...

    EDIT: it auto completes fin based on the ifstream.

  8. #8
    Join Date
    Dec 2004
    Location
    Fantasy Dreamland
    Posts
    1,655
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by kohlrak
    i don't know where you've been looking but even the C++ tutorial that came with my compiler (also supported) states that it's called "cin.getline" and "fin.getline". Even the compiler has kinda like an auto complete thing for things like that. fin and cin both have a getline() function in the standard libraries...

    EDIT: it auto completes fin based on the ifstream.
    It's weird since AFAIK Cin, Cout, etc are the members of
    iosteram Class therefore they're methods and AFAIK methods
    cannot have submethods so the . (dot) thing is not
    applicable to the cin or any other of the methods you've mentioned.
    getLine is a method I remember to be applied to the String (or AnsiString) Class...

    Yeah I may be wrong...but...


  9. #9
    Join Date
    Apr 2005
    Location
    Pennsylvania, USA
    Posts
    520
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default



    I really don't wanna be mean like i am right now (could be the lack of sleep) but i just had to show you guys the screenshot. Note that added code i did to display the auto complete will not be used, it was just to show the auto complete. Which instead of showing all 3 auto completes, it shows the format.

    And getline is for arrays specifically as shown.
    Last edited by kohlrak; 6th-August-2005 at 11:45.

  10. #10
    Join Date
    Feb 2005
    Location
    Limbo
    Posts
    3,706
    Thanks
    0
    Thanked 2 Times in 2 Posts
    EP Points
    10

    Default

    http://msdn.microsoft.com/library/de...eamgetline.asp

    Check this. Anyway, cin is a derived class, a child of istream, isn't it? So it's not a method, it's an object. Of course this is all AFAIK.

    I don't really see why you have to put the address-of operator there, since the array name in itself should be a constant pointer... oh well.
    Last edited by pkt-zer0; 6th-August-2005 at 11:46.

  11. #11
    Join Date
    Apr 2005
    Location
    Pennsylvania, USA
    Posts
    520
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Nice... little.. tut... but wouldn't that cause more of a risk of loosing info from it going off... like... lets's say 1000000 and you << it'll be 0000000... Wouldn't >> keep it 0000000?

    AFAIK? And...

    Gets a line from the input stream.

    basic_istream& getline(
    char_type *_Str,
    streamsize _Count
    );
    basic_istream& getline(
    char_type *_Str,
    streamsize _Count,
    char_type _Delim
    );
    Parameters
    _Count
    The number of characters to read from strbuf.
    _Delim
    The character that should terminate the read if it is encountered before _Count.
    _Str
    A string in which to write.
    is that not backing up what i'm saying, or am i missing somthing again like maybe a difference between a char array and a string... If there is, it wouldn't be the first time...

  12. #12
    Join Date
    Dec 2004
    Location
    Fantasy Dreamland
    Posts
    1,655
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default

    Yeah. This shows how much I stll have to learn:
    This is the info about this method shown by Dev C++.
    Maybe this will help.
    You'll have to pass a pointer to an array so the name of the array
    should be enough if not try using *name or *(name) maybe this'll help...

    Attached Images Attached Images


  13. #13
    Join Date
    Feb 2005
    Location
    Limbo
    Posts
    3,706
    Thanks
    0
    Thanked 2 Times in 2 Posts
    EP Points
    10

    Default

    Quote Originally Posted by kohlrak
    Nice... little.. tut... but wouldn't that cause more of a risk of loosing info from it going off... like... lets's say 1000000 and you << it'll be 0000000... Wouldn't >> keep it 0000000?
    It shouldn't be a risk, you have to know what you're doing. Though there are bit-wise shifting function that 'rotate' the bit going out back on the other side. Plus, you wouldn't want to use 9 bits in a byte, trust me.

    Quote Originally Posted by kohlrak
    is that not backing up what i'm saying, or am i missing somthing again like maybe a difference between a char array and a string... If there is, it wouldn't be the first time...
    Yes, I'm saying that I apparently found the getline method... I didn't know about it previously. But the thing that I was REALLY trying to point out is this part.

    Download Links:
    Links are hidden from guests. Please register to be able to view these links. Why the hell is that & there??? It should already be a const pointer.

  14. #14
    Join Date
    Apr 2005
    Location
    Pennsylvania, USA
    Posts
    520
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    // Ex3_03.cpp
    // Counting string characters
    #include <iostream>
    using namespace std;

    int main()
    {
    const int MAX = 80; // Maximum array dimension
    char buffer[MAX]; // Input buffer
    int count = 0; // Character count

    cout << "Enter a string of less than 80 characters:\n";
    cin.getline(buffer, MAX, '\n'); // Read a string until \n

    while(buffer[count]!= '\0')
    // Increment count as long as the current character
    // is not null
    count++;

    cout << endl
    << "The string \"" << buffer
    << "\" has " << count << " characters.";

    cout << endl;
    return 0;
    }
    According to wrox's screenshot, that works w/o pointer.

    // basic_istream_getline.cpp
    // compile with: /EHsc
    #include <iostream>
    using namespace std;

    int main( )
    {
    char c[10];

    cin.getline( &c[0], 5, '2' );
    cout << c << endl;
    }
    That's not my code, that's what's on msdn...

  15. #15
    Join Date
    Feb 2005
    Location
    Limbo
    Posts
    3,706
    Thanks
    0
    Thanked 2 Times in 2 Posts
    EP Points
    10

    Default

    Mehness, I would rewrite the whole code, but I'm too lazy now...
    Sorry, I'm not that great in bugfixing and patching up programs that don't work. I rather rewrite and redesign that whole part of the program...

    If Pascal source code works for you, and I can fetch the proggy I wrote, oh, a few years ago on a different HDD and a comp that is now God knows where (yeah, that's very likely), I'll put it up here.

    So, expect a rewritten program in the upcoming 24 hours.

Similar Threads

  1. eXeem lite public beta released...
    By Soeru in forum Free 4 All
    Replies: 27
    Last Post: 12th-March-2005, 22:01
  2. doom source ports
    By madcrow in forum General Gaming
    Replies: 5
    Last Post: 20th-July-2004, 16:33
  3. Emulation News - Raine Source Packages and Docs & ZSNES WIP
    By EmuFreak in forum Everything Emulation
    Replies: 0
    Last Post: 23rd-August-2003, 12:43
  4. Source Code nemu .8
    By nevetsmiller in forum ROM & ISO Requests
    Replies: 2
    Last Post: 22nd-March-2002, 16:55

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About Us

We are the oldest retro gaming forum on the internet. The goal of our community is the complete preservation of all retro video games. Started in 2001 as EmuParadise Forums, our community has grown over the past 18 years into one of the biggest gaming platforms on the internet.

Social