I have a random number like 0.323978544752212. I want to encrypt a string using this random number into to numerical string i.e. final string is like 020006122188063255154070154055012148007180040020199052197129206154016135. I want to build a CGI application and want to use this encryption design. How can I achieve this type of encryption.
I should be able to de-crypt the same using the original random number. Also is there any predefined/standard method available for same?

  • Will the input number be floating point?
    – user49075
    Commented Oct 21, 2014 at 7:57
  • 3
    What is the reason behind these bizarre requirements?
    – Xander
    Commented Oct 21, 2014 at 18:31

2 Answers 2


I'm not aware of any specific and popularly reviewed encryption systems. While you may be able to roll something more specific, I recommend using common ciphers to achieve your needs:

  1. Use a password based key derivation function (e.g. Scrypt) to derive a key from a random number.

  2. Use a common encryption cipher such as AES, Blowfish, etc to encrypt the string with the derived key.

  3. Convert the result into base 10 format, which would be a 'numerical string'.


The one-time pad sounds pretty much exactly what you are doing. It would look something like this:

Generate a string of random numbers (base-10 or hex) large enough to encrypt your entire plaintext.

Convert your entire plaintext into base-10 or hex.

You can do simple digit to digit subtraction (no carry) to encrypt your plaintext. To reverse it, you would just add the numbers (no carry) back from your pad.

Example would look like:

P-Text: 3487621899
Pad:(-) 1245631862
C-Text: 2242090037
Pad:(+) 1245631862
P-Text: 3487621899

If you aren't going to use the randomly generated number for encrypting multiple streams of information, this is a very simple, very safe method of encrypting information. Each time you do it, you'll want to generate a new set of data to encrypt the information.

If you plan on using a currently existing cipher to encode multiple different pieces of information while using a randomly generated number to serve as some sort of key choice method, I would just generate a random number like you did, multiply it by a full hex value FFFFFFFFFFFFFFFF (for 64 bit keys) FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF for 128-bit keys, etc (each hex character is 4bits), and use the resultant hex value to be a key for whatever crypto-scheme you want to use. Then you can base-10 it and poof, done.

no need to be complicated ;)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .