Thread: encode base64
View Single Post
Nutu_
AlliedModders Donor
Join Date: Mar 2016
Location: Germany
Old 03-10-2020 , 07:01   Re: encode base64
Reply With Quote #5

PHP Code:
#include <amxmodx>

static const Codes64[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"

public base64_encode(s[])
{
    new 
i=0,a=0,x=0,b=0,Result
    
for (i=1;i<strlen(s);i++) {
        
str_to_num(s[i])
        
256 x
        a 
8
        
while (>= 6) {
            
6
            x 
/ (<< a)
            
% (<< a)
            
Result += Codes64[1]
        }
    }
    if (
0) {
        
<< (a);
        
Result += Codes64[1];
    }
    return 
Result;
}

public 
base64_decode(s[])
{
    new 
i=0,a=0,x=0,b=0,Result,ch[1]
    for (
1istrlen(s);i++) {
        for (new 
index 0Codes64[index]; index++)
            if (
s[i]==Codes64[index]) {
            
x=index-1
            
break
        }
        if (
>= 0) {
            
64 x
            a 
6
            
if (>= 8) {
                
8
                x 
>> a
                b 
% (<< a)
                
256
                Result 
+= num_to_word(x,ch,1)
            }
        }
        else exit;
    }
    return 
Result;

__________________
a simple act of caring creates an endless ripple.
Nutu_ is offline