[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

alphanumeric encrypt/decrypt

Ruby Facet

8/3/2008 5:20:00 AM

Hello,

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

RF
--
Posted via http://www.ruby-....

7 Answers

Gregory Brown

8/3/2008 5:29:00 AM

0

On Sun, Aug 3, 2008 at 1:19 AM, Ruby Facet <sechelon@ymail.com> 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

--
Killer Ruby PDF Generation named after a magnificent sea creature:
http://github.com/sa... | Non-tech stuff at:
http://metametta.bl...

Ruby Facet

8/3/2008 5:52:00 AM

0

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.
--
Posted via http://www.ruby-....

Gregory Brown

8/3/2008 5:58:00 AM

0

On Sun, Aug 3, 2008 at 1:51 AM, Ruby Facet <sechelon@ymail.com> 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

Todd Benson

8/3/2008 6:32:00 AM

0

On Sun, Aug 3, 2008 at 12:19 AM, Ruby Facet <sechelon@ymail.com> 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

Ruby Facet

8/3/2008 9:28:00 AM

0

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 Benson wrote:
> On Sun, Aug 3, 2008 at 12:19 AM, Ruby Facet <sechelon@ymail.com> 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

--
Posted via http://www.ruby-....

Ruby Facet

8/3/2008 9:40:00 AM

0

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.
--
Posted via http://www.ruby-....

Todd Benson

8/3/2008 6:58:00 PM

0

On Sun, Aug 3, 2008 at 4:40 AM, Ruby Facet <sechelon@ymail.com> 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