In my previously-posted Work Backup program, the script copies changed files to another location. One use is for "backup buddies" on a network (or with DSL etc.), so I'm adding features to make the files encrypted. I've got that part well in hand.

However, what about the file name? I'd like that to be safe from prying eyes (even accidently), too.

Now I could maintain a dictionary and simply assign meaningless names like file123456.dat to the destination. But I want to do without a central list, and make each file individually 1:1 reversable. That is, encrypt the file name and be able to decrypt it.

But, a regular encrypt will produce byte values that are in a larger range than the input. File names may be 94 ASCII characters, for example, but the output will be 0..255 fairly uniformly. That won't work for a filename!

A simple idea is to then BASE64 encode the results. That should not increase the length =too= badly. But I wonder if there may be a more elegant way, such as encrypting using a stream cypher that maps 94 input chars to the same 94 output chars. Does anybody know of such a thing?

—John


In reply to Encrypting a Filename by John M. Dlugosz

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.