impl B32Encode<String,String> for B32<String>{
fn encode(data:String)->String{
let mut len_data:usize=data.len();
let mut ptr_data:*const u8=data.as_ptr();
let size:usize=len_data/5*8+if len_data%5==0 {0}else{8};
let mut string:String=String::with_capacity(size);
unsafe{
let mut vector=&mut string.as_mut_vec();
vector.resize(size,0);
let mut pointer=vector.as_mut_ptr();
let ptr_alphabet=ALPHABET32.as_ptr();
let mut d:u64;
while len_data>8{
d=(*(ptr_data as *const u64)).to_be();
*pointer.offset(0)=*ptr_alphabet.offset((((d>>59))&0b11111) as isize);
*pointer.offset(1)=*ptr_alphabet.offset((((d>>54))&0b11111) as isize);
*pointer.offset(2)=*ptr_alphabet.offset((((d>>49))&0b11111) as isize);
*pointer.offset(3)=*ptr_alphabet.offset((((d>>44))&0b11111) as isize);
*pointer.offset(4)=*ptr_alphabet.offset((((d>>39))&0b11111) as isize);
*pointer.offset(5)=*ptr_alphabet.offset((((d>>34))&0b11111) as isize);
*pointer.offset(6)=*ptr_alphabet.offset((((d>>29))&0b11111) as isize);
*pointer.offset(7)=*ptr_alphabet.offset((((d>>24))&0b11111) as isize);
pointer=pointer.offset(8);
ptr_data=ptr_data.offset(5);
len_data-=5;
}
while len_data>4{
*pointer.offset(0)=*ptr_alphabet.offset(((*ptr_data.offset(0)&0b11111000)>>3) as isize);
*pointer.offset(1)=*ptr_alphabet.offset((((*ptr_data.offset(0)&0b00000111)<<2)|((*ptr_data.offset(1)&0b11000000)>>6)) as isize);
*pointer.offset(2)=*ptr_alphabet.offset(((*ptr_data.offset(1)&0b00111110)>>1) as isize);
*pointer.offset(3)=*ptr_alphabet.offset((((*ptr_data.offset(1)&0b00000001)<<4)|((*ptr_data.offset(2)&0b11110000)>>4)) as isize);
*pointer.offset(4)=*ptr_alphabet.offset((((*ptr_data.offset(2)&0b00001111)<<1)|((*ptr_data.offset(3)&0b10000000)>>7)) as isize);
*pointer.offset(5)=*ptr_alphabet.offset(((*ptr_data.offset(3)&0b01111100)>>2) as isize);
*pointer.offset(6)=*ptr_alphabet.offset((((*ptr_data.offset(3)&0b00000011)<<3)|((*ptr_data.offset(4)&0b11100000)>>5)) as isize);
*pointer.offset(7)=*ptr_alphabet.offset(((*ptr_data.offset(4)&0b00011111)>>0) as isize);
pointer=pointer.offset(8);
ptr_data=ptr_data.offset(5);
len_data-=5;
}
if len_data==4{
*pointer.offset(0)=*ptr_alphabet.offset(((*ptr_data.offset(0)&0b11111000)>>3) as isize);
*pointer.offset(1)=*ptr_alphabet.offset((((*ptr_data.offset(0)&0b00000111)<<2)|((*ptr_data.offset(1)&0b11000000)>>6)) as isize);
*pointer.offset(2)=*ptr_alphabet.offset(((*ptr_data.offset(1)&0b00111110)>>1) as isize);
*pointer.offset(3)=*ptr_alphabet.offset((((*ptr_data.offset(1)&0b00000001)<<4)|((*ptr_data.offset(2)&0b11110000)>>4)) as isize);
*pointer.offset(4)=*ptr_alphabet.offset((((*ptr_data.offset(2)&0b00001111)<<1)|((*ptr_data.offset(3)&0b10000000)>>7)) as isize);
*pointer.offset(5)=*ptr_alphabet.offset(((*ptr_data.offset(3)&0b01111100)>>2) as isize);
*pointer.offset(6)=*ptr_alphabet.offset(((*ptr_data.offset(3)&0b00000011)<<3) as isize);
*pointer.offset(7)=61;
}else{
if len_data==3{
*pointer.offset(0)=*ptr_alphabet.offset(((*ptr_data.offset(0)&0b11111000)>>3) as isize);
*pointer.offset(1)=*ptr_alphabet.offset((((*ptr_data.offset(0)&0b00000111)<<2)|((*ptr_data.offset(1)&0b11000000)>>6)) as isize);
*pointer.offset(2)=*ptr_alphabet.offset(((*ptr_data.offset(1)&0b00111110)>>1) as isize);
*pointer.offset(3)=*ptr_alphabet.offset((((*ptr_data.offset(1)&0b00000001)<<4)|((*ptr_data.offset(2)&0b11110000)>>4)) as isize);
*pointer.offset(4)=*ptr_alphabet.offset(((*ptr_data.offset(2)&0b00001111)<<1) as isize);
*pointer.offset(5)=61;
*pointer.offset(6)=61;
*pointer.offset(7)=61;
}else{
if len_data==2{
*pointer.offset(0)=*ptr_alphabet.offset(((*ptr_data.offset(0)&0b11111000)>>3) as isize);
*pointer.offset(1)=*ptr_alphabet.offset((((*ptr_data.offset(0)&0b00000111)<<2)|((*ptr_data.offset(1)&0b11000000)>>6)) as isize);
*pointer.offset(2)=*ptr_alphabet.offset(((*ptr_data.offset(1)&0b00111110)>>1) as isize);
*pointer.offset(3)=*ptr_alphabet.offset(((*ptr_data.offset(1)&0b00000001)<<4) as isize);
*pointer.offset(4)=61;
*pointer.offset(5)=61;
*pointer.offset(6)=61;
*pointer.offset(7)=61;
}else{
if len_data==1{
*pointer.offset(0)=*ptr_alphabet.offset(((*ptr_data.offset(0)&0b11111000)>>3) as isize);
*pointer.offset(1)=*ptr_alphabet.offset(((*ptr_data.offset(0)&0b00000111)<<2) as isize);
*pointer.offset(2)=61;
*pointer.offset(3)=61;
*pointer.offset(4)=61;
*pointer.offset(5)=61;
*pointer.offset(6)=61;
*pointer.offset(7)=61;
}
}
}
}
}
return string;
}
}
impl B32Decode<String,String> for B32<String>{
fn decode(data:String)->String{
let mut len_data:usize=data.len();
let mut ptr_data:*const u8=data.as_ptr();
let np;
unsafe{
np=if len_data>6 {
if *ptr_data.offset((len_data-6) as isize)==61 {6}else{
if *ptr_data.offset((len_data-4) as isize)==61 {4}else{
if *ptr_data.offset((len_data-3) as isize)==61 {3}else{
if *ptr_data.offset((len_data-1) as isize)==61 {1}else{0}
}
}
}
}else{0}
}
let size=(len_data-np)*5/8;
let mut string:String=String::with_capacity(size);
unsafe{
let mut vector=&mut string.as_mut_vec();
vector.resize(size,0);
let mut pointer=vector.as_mut_ptr();
let ptr_alphabet=_ALPHABET32.as_ptr();
while len_data>8{
*pointer.offset(0)=*ptr_alphabet.offset(*ptr_data.offset(0) as isize)<<3|*ptr_alphabet.offset(*ptr_data.offset(1) as isize)>>2;
*pointer.offset(1)=*ptr_alphabet.offset(*ptr_data.offset(1) as isize)<<6|*ptr_alphabet.offset(*ptr_data.offset(2) as isize)<<1|*ptr_alphabet.offset(*ptr_data.offset(3) as isize)>>4;
*pointer.offset(2)=*ptr_alphabet.offset(*ptr_data.offset(3) as isize)<<4|*ptr_alphabet.offset(*ptr_data.offset(4) as isize)>>1;
*pointer.offset(3)=*ptr_alphabet.offset(*ptr_data.offset(4) as isize)<<7|*ptr_alphabet.offset(*ptr_data.offset(5) as isize)<<2|*ptr_alphabet.offset(*ptr_data.offset(6) as isize)>>3;
*pointer.offset(4)=*ptr_alphabet.offset(*ptr_data.offset(6) as isize)<<5|*ptr_alphabet.offset(*ptr_data.offset(7) as isize)<<0;
pointer=pointer.offset(5);
ptr_data=ptr_data.offset(8);
len_data-=8;
}
if len_data==8{
if np>0{
if np>3{
if np>5{
*pointer.offset(0)=*ptr_alphabet.offset(*ptr_data.offset(0) as isize)<<3|*ptr_alphabet.offset(*ptr_data.offset(1) as isize)>>2;
*pointer.offset(1)=*ptr_alphabet.offset(*ptr_data.offset(1) as isize)<<6;
}else{
*pointer.offset(0)=*ptr_alphabet.offset(*ptr_data.offset(0) as isize)<<3|*ptr_alphabet.offset(*ptr_data.offset(1) as isize)>>2;
*pointer.offset(1)=*ptr_alphabet.offset(*ptr_data.offset(1) as isize)<<6|*ptr_alphabet.offset(*ptr_data.offset(2) as isize)<<1|*ptr_alphabet.offset(*ptr_data.offset(3) as isize)>>4;
*pointer.offset(2)=*ptr_alphabet.offset(*ptr_data.offset(3) as isize)<<4;
}
}else{
if np>2{
*pointer.offset(0)=*ptr_alphabet.offset(*ptr_data.offset(0) as isize)<<3|*ptr_alphabet.offset(*ptr_data.offset(1) as isize)>>2;
*pointer.offset(1)=*ptr_alphabet.offset(*ptr_data.offset(1) as isize)<<6|*ptr_alphabet.offset(*ptr_data.offset(2) as isize)<<1|*ptr_alphabet.offset(*ptr_data.offset(3) as isize)>>4;
*pointer.offset(2)=*ptr_alphabet.offset(*ptr_data.offset(3) as isize)<<4|*ptr_alphabet.offset(*ptr_data.offset(4) as isize)>>1;
*pointer.offset(3)=*ptr_alphabet.offset(*ptr_data.offset(4) as isize)<<7;
}else{
*pointer.offset(0)=*ptr_alphabet.offset(*ptr_data.offset(0) as isize)<<3|*ptr_alphabet.offset(*ptr_data.offset(1) as isize)>>2;
*pointer.offset(1)=*ptr_alphabet.offset(*ptr_data.offset(1) as isize)<<6|*ptr_alphabet.offset(*ptr_data.offset(2) as isize)<<1|*ptr_alphabet.offset(*ptr_data.offset(3) as isize)>>4;
*pointer.offset(2)=*ptr_alphabet.offset(*ptr_data.offset(3) as isize)<<4|*ptr_alphabet.offset(*ptr_data.offset(4) as isize)>>1;
*pointer.offset(3)=*ptr_alphabet.offset(*ptr_data.offset(4) as isize)<<7|*ptr_alphabet.offset(*ptr_data.offset(5) as isize)<<2|*ptr_alphabet.offset(*ptr_data.offset(6) as isize)>>3;
*pointer.offset(4)=*ptr_alphabet.offset(*ptr_data.offset(6) as isize)<<5;
}
}
}else{
*pointer.offset(0)=*ptr_alphabet.offset(*ptr_data.offset(0) as isize)<<3|*ptr_alphabet.offset(*ptr_data.offset(1) as isize)>>2;
*pointer.offset(1)=*ptr_alphabet.offset(*ptr_data.offset(1) as isize)<<6|*ptr_alphabet.offset(*ptr_data.offset(2) as isize)<<1|*ptr_alphabet.offset(*ptr_data.offset(3) as isize)>>4;
*pointer.offset(2)=*ptr_alphabet.offset(*ptr_data.offset(3) as isize)<<4|*ptr_alphabet.offset(*ptr_data.offset(4) as isize)>>1;
*pointer.offset(3)=*ptr_alphabet.offset(*ptr_data.offset(4) as isize)<<7|*ptr_alphabet.offset(*ptr_data.offset(5) as isize)<<2|*ptr_alphabet.offset(*ptr_data.offset(6) as isize)>>3;
*pointer.offset(4)=*ptr_alphabet.offset(*ptr_data.offset(6) as isize)<<5|*ptr_alphabet.offset(*ptr_data.offset(7) as isize)<<0;
}
}
}
return string;
}
}