Thread: better way than hardcode things

  1. #1
    Registered User I C everything's Avatar
    Join Date
    Apr 2019
    Posts
    101

    Question better way than hardcode things

    Hi
    is there a good alternative than hardcode things because I want to hide data,so you just dont can cheat quiz with open the text file in a texteditor

    I know its possible to read in data,but maybe a crypto format in data file that gets dechiffered?
    M
    you tell me you can C,why dont you C your own bugs?

  2. #2
    Registered User
    Join Date
    Apr 2019
    Posts
    62
    What are your real goals? Anything that's included with the program can be read by anything with that program. You can't encrypt things because the program would necessarily need to include the decryption key, and there's nothing to stop anyone from just decrypting it themselves or adding a few lines of code that dumps the data after your program decrypts it. Or they could use a debugger to see that data at any time.

    However, if all you're looking to do is prevent a casual observer from viewing the answers to a quiz, a simple caesar cipher will do that, and is very easy to implement. Or, even better, store the answers in a file or a char array (not a string literal, since this will make a lot of unprintable characters" that uses XOR encryption. XOR encryption is extremely easy to implement (a single line function can handle both encryption and decryption) and will produce absolute jibberish that doesn't even resemble english text.

  3. #3
    Registered User I C everything's Avatar
    Join Date
    Apr 2019
    Posts
    101
    Quote Originally Posted by gaxio View Post
    What are your real goals? Anything that's included with the program can be read by anything with that program. You can't encrypt things because the program would necessarily need to include the decryption key, and there's nothing to stop anyone from just decrypting it themselves or adding a few lines of code that dumps the data after your program decrypts it. Or they could use a debugger to see that data at any time.

    However, if all you're looking to do is prevent a casual observer from viewing the answers to a quiz, a simple caesar cipher will do that, and is very easy to implement. Or, even better, store the answers in a file or a char array (not a string literal, since this will make a lot of unprintable characters" that uses XOR encryption. XOR encryption is extremely easy to implement (a single line function can handle both encryption and decryption) and will produce absolute jibberish that doesn't even resemble english text.
    thanks
    I want is to stop Ordinary Joe,from just read it as plain textfile,not waste time and energy to make it impossible to access info
    also I want to go from lots of hardcoded strings and char arrays to a cleaner and better way doing it
    you tell me you can C,why dont you C your own bugs?

  4. #4
    Registered User I C everything's Avatar
    Join Date
    Apr 2019
    Posts
    101
    if I read file in deschiffer and have init function that goes thru string data after the first string it searches after for string ending and updates a pointer in a pointer array to point at next string would that be good way of handling structure with string data with different lenght,mixed with few integers in ascii format?
    anything must be better than have to use a mastodont switch with lots of hardcoded data
    you tell me you can C,why dont you C your own bugs?

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    For a cleaner and better way of doing things, store the quiz answers in a database with an embedded database engine like SQLite. For your low-requirement security, encrypt the database file and just embed the secret key in your program. SQLite has an encryption extension, but it isn't free.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by laserlight View Post
    For a cleaner and better way of doing things, store the quiz answers in a database with an embedded database engine like SQLite. For your low-requirement security, encrypt the database file and just embed the secret key in your program. SQLite has an encryption extension, but it isn't free.
    Hummmm... it isn't free as "freedom", but it is public domain and free to use:

    SQLite Copyright

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by flp1969 View Post
    Hummmm... it isn't free as "freedom", but it is public domain and free to use:

    SQLite Copyright
    No, unlike SQLite itself, the encryption extension is not in the public domain and isn't free to use. Refer to the sample license agreement, as well as the price quoted on the info page: "The cost of a perpetual source code license for SEE is US $2000."
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    May 2016
    Posts
    104
    You can use any of the cryptographyic libraries, like Libcrypto API - OpenSSLWiki to encrypt and decrypt whatever data you want.
    If security is not an issue, pick a fast algorithm, like DES in ECB mode; although to be honest, the operation mode you chose is irrelevant to performance compared to the time complexity of the algorithm itself.

  9. #9
    Registered User I C everything's Avatar
    Join Date
    Apr 2019
    Posts
    101
    thanks laserlight,Dren
    you tell me you can C,why dont you C your own bugs?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I have C Do 2 Things at Once?
    By mr_raging_money in forum C Programming
    Replies: 6
    Last Post: 03-21-2012, 04:18 AM
  2. Just a few things ...
    By AHCB in forum C++ Programming
    Replies: 10
    Last Post: 11-08-2005, 03:10 AM
  3. Please help with a few things
    By HAssan in forum C Programming
    Replies: 3
    Last Post: 09-24-2005, 01:24 PM
  4. i need help with a few things
    By kwm32 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 03-25-2004, 05:36 PM
  5. Help with these three things...
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 08-26-2001, 07:05 AM

Tags for this Thread