Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suggest a very simple algorithm.</p> <ol> <li>Feed the password into a hash function.</li> <li>Initialize a random number generator with the hash or something you derived from the hash.</li> <li>Generate a 12 digit random number.</li> <li>Add this random number to the input digit by digit modulo 10 to encrypt.</li> </ol> <p>To decrypt subtract the random number modulo 10. <strike>This is actually a form of <a href="http://en.wikipedia.org/wiki/One-time_pad" rel="nofollow noreferrer">One Time Pad</a>.</strike> Because of the comments on this answer I realized that refering to <a href="http://en.wikipedia.org/wiki/One-time_pad" rel="nofollow noreferrer">One Time Pad</a> was a bad choice. A better reference is <a href="http://en.wikipedia.org/wiki/Polyalphabetic_substitution" rel="nofollow noreferrer">Polyalphabetic cipher</a> - while One Time Pad uses polyalphabetic substitution its main characteristic is not to use any key bit twice.</p> <pre> Input 1234 1234 1234 Random number 6710 3987 2154 Output 7944 4111 3388 </pre> <p>There is one remaining problem with that - the algorithm might create leading zeros. To solve this problem one could use <code>XOR</code> instead of addition and substraction. Just transform the digits with <code>XOR</code>. If the first digit turns into a zero, don't encrypt the first digit. When you decrypt with <code>XOR</code> again, the first digit will turn into zero and you know that the first digit was not enrcypted.</p> <p><strong>UPDATE</strong></p> <p>A simple <code>XOR</code> is not the solution because it will produce to large numbers - <code>2 XOR 9 = 11</code> for example. Going to rethinks this...</p> <p><strong>UPDATE</strong></p> <p>The nice propoerties of <code>XOR</code> are <code>XOR(a, b) = XOR(b, a)</code> and <code>XOR(XOR(a, b), b) = a</code>. This makes encryption and decryption the same and allows to detect the unencrypted leading digit. But it is further required that our function only returns values in the range from 0 to 9 what <code>XOR</code> doesn't do.<br> But maybe we can build a custom function with all required properties. So we create an array <code>FUNC</code> with 10 columns and 10 rows and use it as a lookup table for our function. What values to but in? I actually don't know - I am not even sure that it is possible. But if we pick three number from the range 0 to 9 we have to make the following six entries. (It is a symmetric matrix.)</p> <pre> FUNC[x,y] = z FUNC[x,z] = y FUNC[y,z] = x FUNC[y,x] = z FUNC[z,x] = y FUNC[z,y] = x </pre> <p>So maybe it is possible to create such a function by repeatedly choosing random numbers and filling the six entries if there is no conflict. Maybe it is not. I would like to see the table if one finds a solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload