Alphanumeric encrypt/decrypt

Hello,

Is there an encryption (decryption) routine that will return only
alphanumeric characters? Looking forward to your help.

RF

On Sun, Aug 3, 2008 at 1:19 AM, Ruby F. [email protected] wrote:

Hello,

Is there an encryption (decryption) routine that will return only
alphanumeric characters? Looking forward to your help.

You could take any old routine and pack / unpack it as hex. Would
that do the trick?

unpacked = “non-alpha numeric stuff: ^#%# foas”.unpack(“H*”)
=>
[“6e6f6e2d616c706861206e756d657269632073747566663a205e23252320666f6173”]
unpacked.pack(“H*”)
=> “non-alpha numeric stuff: ^#%# foas”

-greg

Greg, Thanks for the pack hack. I am using it for file names and the
pack output is a little too long. I will look for other solutions, but
that does the trick.

On Sun, Aug 3, 2008 at 12:19 AM, Ruby F. [email protected] wrote:

Hello,

Is there an encryption (decryption) routine that will return only
alphanumeric characters? Looking forward to your help.

RF

s = ‘aoa3(;12)>,$!’
[s].pack(‘m’).chomp

=> “YW9hMyg71mwyKT4sJC=”

I haven’t read the RFC for base64, but it looks like you would then
need to allow the ‘=’ symbol along with letters and numbers, but no
other special characters besides that. Perhaps ‘=’ is a padding
character.

cheers,
Todd

Todd, thank you. I think that will work for me. Just to note that we
can’t remove one ‘=’ in encrypt and add one in decrypt, the number of
‘=’ could vary.

s = ‘1231243234232’;
[s].pack(‘m’)
=> “MTIzMTI0MzIzNDIzMg==\n”

Todd B. wrote:

On Sun, Aug 3, 2008 at 12:19 AM, Ruby F. [email protected] wrote:

Hello,

Is there an encryption (decryption) routine that will return only
alphanumeric characters? Looking forward to your help.

RF

s = ‘aoa3(;12)>,$!’
[s].pack(‘m’).chomp

=> “YW9hMyg71mwyKT4sJC=”

I haven’t read the RFC for base64, but it looks like you would then
need to allow the ‘=’ symbol along with letters and numbers, but no
other special characters besides that. Perhaps ‘=’ is a padding
character.

cheers,
Todd

On Sun, Aug 3, 2008 at 1:51 AM, Ruby F. [email protected] wrote:

Greg, Thanks for the pack hack. I am using it for file names and the
pack output is a little too long. I will look for other solutions, but
that does the trick.

Is there any reason you need to decrypt the filenames? If not, you
could use something like SHA.

-greg

Greg, Since I am using it for file names, I thought if the cipher is
both way, I am guaranteed to not get collisions. Actually I don’t use
decryption.

On Sun, Aug 3, 2008 at 4:40 AM, Ruby F. [email protected] wrote:

Greg, Since I am using it for file names, I thought if the cipher is
both way, I am guaranteed to not get collisions. Actually I don’t use
decryption.

If it’s one way…

my_string.hash #for a number

…or…

my_string.crypt(my_seed_string)

Todd

On Sun, Aug 03, 2008 at 02:51:31PM +0900, Ruby F. wrote:

Greg, Thanks for the pack hack. I am using it for file names and the
pack output is a little too long. I will look for other solutions, but
that does the trick.

Unfortunately, with the encryption string being limited to alphanumeric
characters, a short string would probably be indicative of a very weak
encryption routine. In other words, the fewer characters you allow as
encryption output, the longer the string has to be for reasonably strong
encryption algorithms.

Of course, hexadecimal ignores about 77% of the alphabet, so if there’s
an option that allows use of the entire alphabet (rather than rendering
as hexadecimal), you should be able to get shorter strings.