Operating System - HP-UX
1748161 Members
3911 Online
108758 Solutions
New Discussion

want a64l like function in shell script

 
SOLVED
Go to solution
arking1981
Frequent Advisor

want a64l like function in shell script

Dear all,

 

please suggest if there is any utility in shell script to do the function of a64l.

I need to convert the 64based ascii password characters to interger.

 

Any available utility or methods? Please advise.

 

Thanks and Regards

Kang

Hello world...
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: want a64l like function in shell script

Hi:

 

I believe that you are going to have to write your own C code using 'a64l(3C)' :

 

http://bizsupport.austin.hp.com/bc/docs/support/SupportManual/c02252931/c02252931.pdf

Regards!

 

...JRF...

arking1981
Frequent Advisor

Re: want a64l like function in shell script

thanks. but I must deal with it in shell script.

I only need to decode at most 1 character in one time, not too complicated, and I am thinking a couple of possible solutions

 

1 create an array containing all base64 ascii which is "./0-9A-Za-z", then use cut to extract ervery single char and compare it with input to decide the index, which will be the wanted integer

2 devide 64base ascii into 5 categories

  . for 0

  / for 1

  0-9: simply plus 2 for 2-11

  A-Z: convert it to ASCII(65-90) and minus 53 for 12-37

  a-z: convert it to ASCII(97-122) and minus 59 for 38-63

3 use some utility to tell the index of input character in string"./0-9A-Za-z"

   I don't know if shell has such an utility. I though about grep, sed, awk and not find any way to do it.

   Do you know any tool to achieve such a task?

 

regards

kang

Hello world...
Dennis Handly
Acclaimed Contributor
Solution

Re: want a64l like function in shell script

>3 use some utility to tell the index of input character in string"./0-9A-Za-z"

>I thought about grep, sed, awk and not find any way to do it.

 

grep -n can do it but would be expensive.  ;-)

But you can use awk's  index:

awk -v char=$char '

BEGIN {
   print index("./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", char)-1;
   exit 0
} ' /dev/null

arking1981
Frequent Advisor

Re: want a64l like function in shell script

it is amazing........ thanks a ton. I kudos you, thanks
Hello world...