Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8491985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:35:20+00:00 2026-06-10T22:35:20+00:00

Introduction I am working at a "prize codes" system for my website: the administrators

  • 0

Introduction

I am working at a "prize codes" system for my website: the administrators can assign credits to an user, giving them a code that they can redeem.
The idea itself is quite easy to implement: generate (I’ll assume the algorithm to be hardly-predictable) the codes, store them in a safe database and give administrators the power to read one random code. But I found that some features I want, do collide:

  1. The code must reasonably resist to attack with a reasonable computation power;
  2. There must be a large number of codes, 1 million;
  3. The code must be easy to type.

I thought of these solutions, until now:

After some thinking, I came up with this solution: using phrases of N words [I’m not talking about THE "n" word. I mean, "N times a random word"]. This seems to be a good idea, but I’m not experienced in this field.

Question 1

Is it safe to use phrases for codes? If yes, how many words should I use in order to be safe enough? [Assume an average length and the words an 8-years-old children knows.]

Question 2

Given a list of words, what is the best way to store them into the database?

  • Desktop-side, generate a file with the desired phrases, then read and put them into the database using PHP?
  • Server-side, reading a list of words and writing the phrases directly into the database?
  • Other ways?

Please note that I can’t just let the administrators read the phrases files, as it is harder to code than using a database. Also notice that the words must be in common Italian: I estimate from 4.000 to 6.000 words to be used.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:35:21+00:00Added an answer on June 10, 2026 at 10:35 pm

    I’m going to assume throughout that your codes will be generated from proper (pseudo)random numbers. If you generate lots of them, make sure to provide enough entropy to the random number generator of the computer that generates them.

    Codes like you are talking about are often created as strings of random printable characters. One way to do it, for example, would be to generate a 144-bit random number and base64-encode it. This will give you 144 bits of information with strings of 24 characters. Usually people don’t mind that the strings read as garbage because they’re either copy&pasted or embedded in URLs. You can think about this string as a sequence of 24 symbols each generated from an alphabet of 64 characters, or as sequences of 144 symbols each generated from an alphabet of 2 bits. It comes out to the same.

    Generating a list of WORDS instead of a list of CHARACTERS (or BITs) is similar. Instead of an alphabet of 2 bits or 64 characters, you’re using an alphabet of 4000 to 6000 words. That’s a much bigger alphabet (more information), but you expect to use fewer or them in your phrase (less information).

    Using n words, you will get log₂((4000 to 6000)ⁿ) bits. For simplicity, let’s say you choose an alphabet of 4096 words. To contain the same amount of information as 144-bit tokens, your phrases will need to contain 12 words each.

    Your requirement “There must be a large number of codes, 1 million” is unclear. Do you mean that the codespace must be 1 million phrases, or that you intend to generate 1 million different phrases that are each part of a codespace that is much larger.

    If your codespace needs to be 1 million, that’s only log₂(1000000) = 20 bits. Phrases of 2 words will do. I guess that’s probably a bit of a small codespace though… but it depends how many chances an adversary is likely to be able to get to guess correct phrases and how quickly they are going to be able to make guesses. And it also depends how damaging it would be for an adversary to guess a correct code. Without knowing your requirements I can only guess how big of a codespace you want to have. Perhaps twice as many bits (1 trillion codes)?

    Question 2: It doesn’t really make any difference where you generate the phrases so long as the computer that does it has a good source of randomness. If in doubt, use your desktop. Then it doesn’t really matter how you load them into the database, be it RPCs, remote database access, or copying the file to the server.

    If you generate a lot of phrases, be aware that storing them as plain strings in the database is going to be costly. You can save a lot of space by encoding them as a sequence of integers that are indices into your reference wordlist.

    EXTRA: Note that if you use more than 2 or 3 words in each phrase, you may find that the phrases are just as hard to remember and type as random sequences of characters. This is because even though they will be made up of real words, the phrases will mostly be nonsense, including words that grammatically cannot fit next to one another.

    If you want to mitigate this, you can use a statistical model of how often certain words appear next to each other in a corpus of text (say, a collection of literature) in order to make sequences of words that are likely to seem natural to a human. Modelling adjacent parts, triples, or 4-tuples of adjacent words is called second, third, or n-level Markov chains, respectively.

    Obviously, generating your phrases like this is going to REDUCE the amount of information (in the information-theoretic sense) in your phrases so you will have to compensate by making them longer. The exact amount of information reduction that results from using a particular statistical model is left as an exercise for you to calculate 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to write some code working with fonts. Is there a good introduction
I have to write some code working with bitmaps. Is there a good introduction
I have to write some code working with timezones. Is there a good introduction
I have to write some code working with locales. Is there a good introduction
I'm working on a positioning system which using matrixes can not satisfy my needs.
Introduction In a current project I'm working on we're using the ChartBoost SDK for
Introduction: I'm trying to get additional fields to log with log4j, and its working
In the W3C working draft for HTML5 here's a line I find confusing: http://www.w3.org/TR/html5/introduction.html#html-vs-xhtml
I am working on a project at the moment, that allows the user to
I am working through the Introduction to Algorithms book by Cormen, and I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.