@name Project Lereshel
@inputs
@outputs Output:string
@persist [Decrypt Encrypt]:table [Brk Output]:string
@trigger
runOnChat(1)
Chat=lastSaid()
K=chatClk()

#Won't work without concmd enabled!

if(!entity():owner()){selfDestruct()}
if(first()){
    Encrypt=table()
    Decrypt=table()
    #abcdefghijklmnopqrstuvwxyz
    #deserned
    #Lereshel
    EnNum="@$^*)!#%&(2468013579`"      #Numerical encryption cipher
    EnUpp="OPGLEWCNAXVDFTIBZSRHYKMQUJ" #Uppercase encryption cipher
    EnLow="opglewcnaxvdftibzsrhykmquj" #Lowercase encryption cipher
    DeLow="abcdefghijklmnopqrstuvwxyz" #Lowercase decryption cipher (normal alphabet)
    DeUpp="ABCDEFGHIJKLMNOPQRSTUVWXYZ" #Uppercase decryption cipher
    DeNum="1234567890!@#$%^&*()~"      #numerical decrpytion cipher
    
    Encryption=EnLow+EnUpp+EnNum #append all encryption strings together
    Decryption=DeLow+DeUpp+DeNum #append all decryption strings together, as long as the order maches it's ok.
    
    for(C=1,Encryption:length()){
        Encrypt[Decryption[C],string]=Encryption[C] #create a look up table for encrypting D->E
        Decrypt[Encryption[C],string]=Decryption[C] #create a look up table for decrpyting E->D
    }
    Brk="`"  #A "break" character you are unlikely to use at all in typing because it usually opens the console. 
    function string string:code(){
    
        Table=table() #stores arrays of locations where characters are found in a string
        CE=This[1]=="~" #Chat encode character, type this as the first character of your message
        CD=This[1]=="`" #Chat decode character, this becomes the first character of your encoded message
    
        Blank=Brk:repeat(This:length()) #use break character to generate a dummy message of equal size
        Message=Blank:explode(Brk) #Turn dummy message into an editable array
        
        if(CE){Message[1,string]="`"}
        if(CD){Message[1,string]="~"}
        
        for(C=2,This:length()){
            if(Decrypt:exists(This[C])){Char=""}else{Char=This[C]} #Bypass encryption for unknown characters
            
            if(CE){ #Chat Encode
                if(!Char){
                    Message[C,string]=Encrypt[This[C],string] 
                }else{
                    Message[C,string]=Char
                }
            }
            if(CD){ #Chat Decode
                if(!Char){
                    Message[C,string]=Decrypt[This[C],string]
                }else{
                    Message[C,string]=Char
                }
            }
        }
        
        return Message:concat()
    }
}



if(K){
    hideChat(0)
    Output=Chat:code()
    if(Output[1]=="~"){
        hideChat(0) 
        print(lastSpoke():name()+": "+Output) 
        #timer("1",650)
    }
    if(Output[1]=="`"&(owner()==lastSpoke())){
        hideChat(1) 
        #print(Output) 
        timer("1",650) #This was the fastest I could repeat the message
    }
}
if(clk("1")){
    hideChat(0) 
    concmd("say "+Output)
}

