alphanumeric encrypt/decrypt

R

Ruby Facet

Hello,

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

RF
 
G

Gregory Brown

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
 
R

Ruby Facet

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.
 
G

Gregory Brown

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
 
T

Todd Benson

Hello,

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

RF

s = 'aoa3(;12)>,$!'
.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
 
R

Ruby Facet

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';
.pack('m')

=> "MTIzMTI0MzIzNDIzMg==\n"

Todd said:
Hello,

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

RF

s = 'aoa3(;12)>,$!'
.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
 
R

Ruby Facet

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.
 
T

Todd Benson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top