The best (unbreakable) and simplest has to be the One-time_pad. This originally was restricted to 26 letters. To include all printables you would need to transpose "\n" to say chr(127) (unprintable just after 126 printable) to keep the printables + a token for "\n" sequential. Then you generate N random numbers between 0 and 95 (hereafter the key), one for each character in the input. The encryption is to subtract 32 from the ord of each character in the input and add it to its corresponding key value modulo 95. Add 32 to that and you have the ord of a printable except for 127 which you replace with "\n". Same for the key - add 32, chr it and transpose chr(127) to "\n" for printing it out. The key (one-time pad) is issued on encryption and is needed for decryption. Decryption is simply the inverse -- subtract 32 from the key characters and input characters, subtract each key value from the input character value modulo 95, add 32, print except that 127 is printed as "\n". Both the key and the encrypted files are random, so without the key, the code is completely unbreakable.

In reply to Re: crypto with core modules only by TheloniusMonk
in thread crypto with core modules only by morgon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.