[unsloved] encoder system and decoder system works but not 100%.. -
Code:
#include <a_samp>
new alfabet[72][10]={
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
".",
",",
"\\",
"/",
"?",
"!",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
" ",
"+",
"=",
"-"
};
/*
new encryption[72][10]={
"|44|",
"|16|",
"|33|",
"|65|",
"|22|",
"|72|",
"|75|",
"|47|",
"|25|",
"|77|",
"|45|",
"|51|",
"|11|",
"|92|",
"|73|",
"|18|",
"|39|",
"|58|",
"|88|",
"|84|",
"|36|",
"|13|",
"|31|",
"|95|",
"|98|",
"|69|",
"|42|",
"|24|",
"|27|",
"|76|",
"|55|",
"|61|",
"|21|",
"|49|",
"|99|",
"|19|",
"|81|",
"|64|",
"|57|",
"|28|",
"|00|",
"|97|",
"|53|",
"|83|",
"|96|",
"|86|",
"|89|",
"|68|",
"|56|",
"|35|",
"|23|",
"|26|",
"|29|",
"|50|",
"|20|",
"|80|",
"|01|",
"|04|",
"|07|",
"|93|",
"|41|",
"|60|",
"|54|",
"|14|",
"|46|",
"|17|",
"|78|",
"|08|",
"|10|",
"|15|",
"|37|",
"|38|"
};
*/
new encryption[72][10]={
"44",
"16",
"33",
"65",
"22",
"72",
"75",
"47",
"25",
"77",
"45",
"51",
"11",
"92",
"73",
"18",
"39",
"58",
"88",
"84",
"36",
"13",
"31",
"95",
"98",
"69",
"42",
"24",
"27",
"76",
"55",
"61",
"21",
"49",
"99",
"19",
"81",
"64",
"57",
"28",
"00",
"97",
"53",
"83",
"96",
"86",
"89",
"68",
"56",
"35",
"23",
"26",
"29",
"50",
"20",
"80",
"01",
"04",
"07",
"93",
"41",
"60",
"54",
"14",
"46",
"17",
"78",
"08",
"10",
"15",
"37",
"38"
};
public OnFilterScriptInit(){
new
mode,
modestr[256],
modestrx[256],
sizea,
sizeb,
File:modef,
strf[256],
File:input,
File:output,
temp[256];
sizea = sizeof(alfabet);
sizeb = sizeof(encryption);
mode = 1;
print(" ");
print(" ");
print(" ");
if(!fexist("/C0DERZ/mode.cfg")){
print("scriptfiles/C0DERZ/mode.cfg has been created, Mode set to: 1");
print(" ");
modef = fopen("/C0DERZ/mode.cfg",io_append);
fwrite(modef,"1");
fclose(modef);
}
print("opening mode.cfg...");
modef = fopen("/C0DERZ/mode.cfg",io_read);
print("...opened.");
print(" ");
print("reading mode.cfg...");
while(fread(modef,strf)){
format(modestrx,256,"%s",strf);
mode = strval(modestrx);
print("mode.cfg loaded");
}
print("mode.cfg read, closing file");
fclose(modef);
print("mode.cfg closed.");
if(mode == 1){format(modestr,256,"MODE: ENCODE");}
if(mode == 0){format(modestr,256,"MODE: DECODE");}
print(" ");
print("Checking size of Source Array and Encryption Array...");
if(sizea == sizeb){
print("Size of source....... OK");
print("Size of encryption... OK");
print(" ");
print("Launching C0DERZ...");
print(modestr);
print(" ");
print("removing output.txt..");
fremove("/C0DERZ/output.txt");
print("... removed!");
print(" ");
if(!fexist("/C0DERZ/source.txt")){
print("No 'source.txt' found! Terminating conversion process.");
return 0;
}
print("Opening 'source.txt' ...");
input = fopen("/C0DERZ/source.txt",io_read);
print("... opened.");
print(" ");
print("Creating and opening 'output.txt' ...");
output = fopen("/C0DERZ/output.txt",io_append);
print("... done!");
print(" ");
if(mode == 1){
print("ENCODING SOURCE to OUTPUT...");
while(fread(input,temp)){
fwrite(output,code(temp,1));
}
print("...SOURCE ENCODED sucesfully!");
}else
if(mode == 0){
print("DECODING SOURCE to OUTPUT...");
while(fread(input,temp)){
fwrite(output,code(temp,0));
}
print("...SOURCE DECODED sucesfully!");
}
print(" ");
print("Closing files...");
fclose(input);
fclose(output);
print("...done");
print(" ");
print("...CONVERSION DONE!");
print(" ");
}else{
printf("ERROR: Sizes of arrays do not match! (source : %d, encryption: %d)",sizeof(alfabet),sizeof(encryption));
return 0;
}
return 1;
}
stock code(strx[],en=1) {
new tmp[512];
set(tmp,strx);
if(en){
//print("encoding...");
for(new i = 0;i < sizeof(alfabet);i++){
tmp=strreplace(alfabet[i],encryption[i],tmp);
}
}else
if(!en){
//print("decoding...");
for(new i = 0;i < sizeof(alfabet);i++){
tmp=strreplace(encryption[i],alfabet[i],tmp);
}
}
return tmp;
}
/*
stock encode(strx[]) {
new tmp[256];
set(tmp,strx);
for(new i;i < sizeof(alfabet);i++){
tmp=strreplace(alfabet[i],encryption[i],tmp);
}
return tmp;
}
stock decode(strx[]) {
new tmp[256];
set(tmp,strx);
for(new i;i < sizeof(alfabet);i++){
tmp=strreplace(encryption[i],alfabet[i],tmp);
}
return tmp;
}
*/
stock set(dest[],source[]) {
new count = strlen(source);
new i=0;
for (i=0;i<count;i++) {
dest[i]=source[i];
}
dest[count]=0;
}
stock strreplace(trg[],newstr[],src[]) {
new f=0;
new s1[256];
new tmp[256];
format(s1,sizeof(s1),"%s",src);
f = strfind(s1,trg);
tmp[0]=0;
while (f>=0) {
strcat(tmp,ret_memcpy(s1, 0, f));
strcat(tmp,newstr);
format(s1,sizeof(s1),"%s",ret_memcpy(s1, f+strlen(trg), strlen(s1)-f));
f = strfind(s1,trg);
}
strcat(tmp,s1);
return tmp;
}
stock reverse_strreplace(trg[],newstr[],src[]) {
new f=0;
new s1[MAX_STRING55];
new tmp[MAX_STRING55];
format(s1,sizeof(s1),"%s",src);
f = strfind(s1,newstr);
tmp[0]=0;
while (f>=0) {
strcat(tmp,ret_memcpy(s1, 0, f));
strcat(tmp,trg);
format(s1,sizeof(s1),"%s",ret_memcpy(s1, f+strlen(newstr), strlen(s1)-f));
f = strfind(s1,newstr);
}
strcat(tmp,s1);
return tmp;
}
ret_memcpy(source[],index=0,numbytes) {
new tmp[256];
new i=0;
tmp[0]=0;
if (index>=strlen(source)) return tmp;
if (numbytes+index>=strlen(source)) numbytes=strlen(source)-index;
if (numbytes<=0) return tmp;
for (i=index;i<numbytes+index;i++) {
tmp[i-index]=source[i];
if (source[i]==0) return tmp;
}
tmp[numbytes]=0;
return tmp;
}
it encodes the lowercase characters good and it goes wrong at the point when it has to encode uppercase characters and/or numbers it goes wrong.. at the using "|" and without the "|" .. anyone help?
Re: [unsloved] encoder system and decoder system works but not 100%.. -
A better question is why are you encoding things in the first place - this is a very important question! If you need encoding for things like passwords then you're going about it very wrong - passwords should not be decodable. You test people entered the right password by encoding what they typed and checking that encoded string against the stored encoded string. Also, if this is for passwords, you are using the most basic form of encryption ever - straight replacement. There is a plugin for whirlpool which is a much better encoding method, AFAIK it's not been cracked yet.
If you are encoding data other than passwords for storage then I would still recommend a different algorithm. DSA is quite fast for large stream data and can be decrypted if you have the key.
Re: [unsloved] encoder system and decoder system works but not 100%.. -
well it's not for password ;x.. for password i made my own encryption that is not possible to decode it.. 1 way only ;p but I want this just for my *fun*. writing to my friends etc.. but erm the only forum about PAWN i know is sa-mp hehe
Re: [unsloved] encoder system and decoder system works but not 100%.. -
I would not recommend using your own encryption - even if it is truly one way. There are more things than that to consider, the most important one being collisions. A collision is where two different passwords give the same encrypted string - the more collisions there are the easier it is to break people's passwords - you may not know their password, but you know another one which gives the same result, so the fact that it's different doesn't matter. Just use known encryptions with known good profiles.
And I know why it goes wrong with numbers at least - you are replacing letters with numbers, you are then replacing numbers with other numbers, but this includes the numbers you have just inserted as replacements for the letters.
Re: [unsloved] encoder system and decoder system works but not 100%.. -
Re: [unsloved] encoder system and decoder system works but not 100%.. -