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

  • SEARCH
  • Home
  • 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 8331461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:25:28+00:00 2026-06-09T02:25:28+00:00

Integers from 0 to M are to be mapped to n-character codes, made up

  • 0

Integers from 0 to M are to be mapped to n-character codes, made up from a certain alphabet.
The tricky part is that the codes should look pseudo-random, non-sequential. Like so:

0    BX07SU
1    TYN9RQ
2    QZ1697

I assume it’s a common knowledge piece that I miss. How do they call this type of functions f(i) = s – which maps an integer to a pseudo-random character string, with no collisions within a certain range?

Reverse function would be great too: h(s) = i, able to ‘decode’ a valid string back into an integer, or determine that the supplied string is invalid.

  • 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-09T02:25:29+00:00Added an answer on June 9, 2026 at 2:25 am

    For small M @user1494736 is right: just make a lookup table that happens to be bijective, and tailor it to your needs.

    For large M storing the table becomes impractical; we need an algorithm to calculate the mapping. You mentioned we don’t need strong cryptography; this frees us to choose something more light-weight than standard ciphers. That said, they are quite fast and I expect you could use one easily with a 3rd-party library. But let’s suppose you prefer to avoid this for some reason.

    One way to make a poor man’s cipher is to xor a constant onto your plaintext (to change the Hamming weight), and then apply a bit permutation (to destroy locality.) Both of these steps are invertible. It sounds like you want to display your cipher letters as ASCII. So, we may want a final invertible transform (an addition) to ensure the cipher values are printable.

    You mentioned M might be as large as a few million. So, let’s take your plaintext letters (and so ciphertext letters) to be 32-bit values. Finding a random 32-bit value to xor is easy. How about the bit permutation?

    A few million plaintext letters translates into each letter being around 22 or 23 bits wide; this leaves at least 8 (logical) upper bits cleared in every plaintext letter. The permutation can take advantage of this to help ensure the ciphertext bytes are within the ASCII printable range. By sending that upper plaintext byte to the upper two bits of each of the four cipher bytes, we ensure each cipher byte takes values 0 to 63. The final step could then add 48 to make the range 48 to 111, well within the ASCII printable range.

    Playing off this observation, we could envision our plaintext letter as a 4x4 grid of bit pairs, and make our permutation a rotation of this grid:

    Plain
    
    A B C D   byte 3 (the high byte, expected to be all 0)
    E F G H   byte 2
    I J K L   byte 1
    M N O P   byte 0
    
    Cipher
    
    D H L P   byte 3
    C G K O   byte 2
    B F J N   byte 1
    A E I M   byte 0
    

    Or put another way:

    Byte       3    2    1    0
    Plain   ABCD EFGH IJKL MNOP
    Cipher  DHLP CGKO BFJN AEIM
    

    Notice that a piece of each plaintext byte appears in every ciphertext byte: this is what will ensure the encoding “looks random”.

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

Sidebar

Related Questions

for these guidelines: Write a loop that reads positive integers from standard input and
I am working on a program that requires reading in integers from a file
I am reading a huge number of Integers from a file, and at the
I'm reading 16-bit integers from a piece of hardware over the serial port. Using
Say we have a list of integers from 0 to 1000: [0, 1, 2,
The two programs below get n integers from file and calculates the sum of
This is a clojure program to read integers from a file and count the
Hi there I'm trying to input 3 integers from the keyboard and print rows
I am trying to read in 10 signed integers from a file into an
Using the following code, I'm retrieving a list of Integers from a DB and

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.