/**********************************************************************************************************************************
* *
* )( ADM Encryption File )( *
* *
* Copyright © 2018 Abyss Morgan. All rights reserved. *
* *
* Download: https://github.com/AbyssMorgan/SA-MP/tree/master/include/SAM *
* Publication: https://sampforum.blast.hk/showthread.php?tid=595203 *
* Website: http://8.ct8.pl *
* *
* Plugins: SScanf *
* Modules: MD5 *
* *
* File Version: 3.0.0 *
* SA:MP Version: 0.3.7 *
* SScanf Version: 2.8.2 *
* *
* File Functions: *
* :InvertFile(const input[],const output[]); *
* :HexNegativeFile(const input[],const output[],key[]); *
* :RollXFile(const input[],const output[],key[]); *
* :ADMx32(const input[],const output[],key[]); *
* :ADMx64(const input[],const output[],key[]); *
* :ADMx128(const input[],const output[],key[]); *
* :ADMx256(const input[],const output[],key[]); *
* :ADMx512(const input[],const output[],password[],bool:invertpassword = false); *
* :MergeFile(const first_file[],const second_file[],bool:erase_second=false); *
* :MergeFileGroup(const group_name[],const output[],upperbound_index,bool:erase_input=false); *
* :SplitFile(const input[],const output[],max_size,&upperbound_index=0); *
* *
* String Functions: *
* :InvertString(input[],output[],maxdest = sizeof(output)); *
* :HexNegativeString(input[],output[],key[],maxdest = sizeof(output)); *
* :RollXString(input[],output[],key[],maxdest = sizeof(output)); *
* :ADMx32String(input[],output[],key[],maxdest = sizeof(output)); *
* :ADMx64String(input[],output[],key[],maxdest = sizeof(output)); *
* :ADMx128String(input[],output[],key[],maxdest = sizeof(output)); *
* :ADMx256String(input[],output[],key[],maxdest = sizeof(output)); *
* :ADMx512String(input[],output[],password[],bool:invertpassword = false,maxdest = sizeof(output)); *
* :StringToHexString(input[],output[],maxdest = sizeof(output)); *
* :HexStringToString(input[],output[],maxdest = sizeof(output)); *
* *
* Dump Functions: *
* :GetFreeID(); *
* :GetType(const name[]); *
* :IsOpen(index); *
* :IsValid(const name[]); *
* :Create(const name[],key[],type = KEY_TYPE_ADMx32); *
* :Destroy(index); *
* :Open(const name[],key[],type = KEY_TYPE_ADMx32); *
* :Close(index); *
* :Write(index,string[]); *
* :IsEmpty(const name[]); *
* *
* Extended Functions: *
* :Create(const name[]); *
* :IsValidKey(key[],type); *
* :GetKeyType(key[],bool:distorted = false); *
* :GetErrorName(code); *
* :DecodeADMKey(inputkey[],outputkey[],type,maxdest = sizeof(outputkey)); *
* :CreateADMKey(key[],type,maxdest = sizeof(key)); *
* *
* Return value: *
* ADM_ERROR_CODE_UNEXEC //Function unexecutable *
* ADM_ERROR_CODE_OK //Success *
* ADM_ERROR_CODE_INPUT //Input file not exist *
* ADM_ERROR_CODE_OUTPUT //Output file exist *
* ADM_ERROR_CODE_KEY //Invalid key *
* ADM_ERROR_CODE_SIZE //Invalid file size *
* ADM_ERROR_CODE_DEST //Destination size *
* ADM_ERROR_CODE_OPEN_INPUT //Open input file *
* ADM_ERROR_CODE_OPEN_OUTPUT //Open output file *
* ADM_ERROR_CODE_INVALID_TYPE //Invalid key type *
* ADM_ERROR_CODE_PASSWORD //Invalid password len *
* ADM_ERROR_CODE_MD5 //Invalid MD5 Load *
* ADM_ERROR_CODE_DMP_NAME //Invalid dump file name *
* ADM_ERROR_CODE_DMP_IDX //Invalid dump file index *
* *
* Key Generator: *
* http://8.ct8.pl/admkg *
* *
**********************************************************************************************************************************/
ADM_ERROR_CODE_UNEXEC //function unexecutable
ADM_ERROR_CODE_OK //success
ADM_ERROR_CODE_INPUT //input file not exist
ADM_ERROR_CODE_OUTPUT //output file exist
ADM_ERROR_CODE_KEY //invalid key
ADM_ERROR_CODE_SIZE //invalid file size
ADM_ERROR_CODE_DEST //error destination size
ADM_ERROR_CODE_OPEN_INPUT //error open input file
ADM_ERROR_CODE_OPEN_OUTPUT //error open output file
ADM_ERROR_CODE_INVALID_TYPE //invalid key type
ADM_ERROR_CODE_PASSWORD //invalid password length
ADM_ERROR_CODE_MD5 //invalid MD5 Load
ADM_ERROR_CODE_DMP_NAME //invalid dump file name
ADM_ERROR_CODE_DMP_IDX //invalid dump file index
KEY_TYPE_UNKNOWN //invalid key type
KEY_TYPE_HEXNEGATIVE
KEY_TYPE_ROLLX
KEY_TYPE_ADMx32
KEY_TYPE_ADMx64
KEY_TYPE_ADMx128
KEY_TYPE_ADMx256
MAX_KEY_LEN_HEXNEGATIVE
MAX_KEY_LEN_ROLLX
MAX_KEY_LEN_ADMx32
MAX_KEY_LEN_ADMx64
MAX_KEY_LEN_ADMx128
MAX_KEY_LEN_ADMx256
MAX_KEY_LEN_ADMx512
Encrypt Key: 191 12 239 86
Decrypt Key: 65 244 17 170
a - encrypt argument
b - decrypt argument
b = 256-a
256 - 191 = 65
256 - 12 = 244
256 - 239 = 17
256 - 86 = 170
new edi;
edi = ADM::ADMx32("test.txt","test.adm","191 12 239 86");
printf("ADM return code %d",edi);
switch(edi){
case ADM_ERROR_CODE_UNEXEC: print("Error: function unexecutable");
case ADM_ERROR_CODE_OK: {
print("Encryption successfully completed");
ADM::ADMx32("test.adm","test2.txt","65 244 17 170");
}
default: {
printf("%s",ADM::GetErrorName(edi));
}
}
new buffer[256];
ADM::ADMx32String("This is test string", buffer, "191 12 239 86");
printf("Binary data: '%s'",buffer); // 'tXЙЯubv3qbĘЯcČ(zV'
new buffer2[512]; //2 * sizeof(buffer)
ADM::StringToHexString(buffer,buffer2);
printf("Hex data: '%s'",buffer2); // '137458C9DF756276337162CADF7F63C8287A56'
#define SCRIPT_DUMP_KEY "191 12 239 86"
new GameModeLog = INVALID_DUMP_FILE,
GameModeLogName[80];
forward WriteGameModeError(string[]);
public WriteGameModeError(string[]){
if(!DMP::IsValid(GameModeLog)){
GameModeLog = DMP::Create(GameModeLogName,SCRIPT_DUMP_KEY,KEY_TYPE_ADMx32); //create new dump file
}
if(!DMP::IsOpen(GameModeLog)){
GameModeLog = DMP::Open(GameModeLogName,SCRIPT_DUMP_KEY,KEY_TYPE_ADMx32); //open dump file
}
new edi = DMP::Write(GameModeLog,string);
DMP::Write(GameModeLog,"\n");
if(edi == ADM_ERROR_CODE_OK) return 1;
printf("%s",ADM::GetErrorName(edi));
return 0;
}
public OnGameModeInit(){ //OnFilterScriptInit
new wl_date[3], wl_time[3];
getdate(wl_date[0],wl_date[1],wl_date[2]);
gettime(wl_time[0],wl_time[1],wl_time[2]);
format(GameModeLogName,sizeof(GameModeLogName),"GM_%02d.%02d.%02d_%02d%02d%02d.dmp",wl_date[0],wl_date[1],wl_date[2],wl_time[0],wl_time[1],wl_time[2]);
return 1;
}
public OnGameModeExit(){ //OnFilterScriptExit
if(DMP::IsEmpty(GameModeLogName)){
DMP::Close(GameModeLog);
fremove(GameModeLogName);
}
return 1;
}
new upperbound_index, edi;
edi = ADM::SplitFile("test.db","test_part",512,upperbound_index);
printf("[SplitFile] %d upp: %d",edi,upperbound_index);
edi = ADM::MergeFileGroup("test_part","new.db",upperbound_index);
printf("[MergeFileGroup] %d",edi);
#include <MD5>
#include <SAM/ADM>
if(!fexist(input)){
return ERROR_CODE_ADM_INPUT;
}
Good job there.
However, why don't you simply return the error messages? PHP код:
|
new ADM:edi;
edi = ADMx32("test.txt","test.adm","191 12 239 86");
printf("ADM return code %d",ADMToInt(edi));
switch(edi){
case ERROR_CODE_ADM_OK: {
print("Encryption successfully completed");
ADMx32("test.adm","test2.txt","65 244 17 170");
}
case ERROR_CODE_ADM_INPUT: print("Error: input file not exist");
case ERROR_CODE_ADM_OUTPUT: print("Error: output file exist");
case ERROR_CODE_ADM_KEY: print("Error: invalid key");
case ERROR_CODE_ADM_SIZE: print("Error: invalid file size");
}
ADMx256
the number of possible keys: 255^32 = 10216115020465815932616217175779729916574180022280 7601117528975009918212890625 Good luck |
ADM:InvertString(input[], output[], maxdest = sizeof(output));
ADM:ADMx32String(input[], output[], key[], maxdest = sizeof(output));
ADM:ADMx64String(input[], output[], key[], maxdest = sizeof(output));
ADM:ADMx128String(input[], output[], key[], maxdest = sizeof(output));
ADM:ADMx256String(input[], output[], key[], maxdest = sizeof(output));
ADM:StringToHexString(input[], output[], maxdest = sizeof(output));
ADM:HexStringToString(input[], output[], maxdest = sizeof(output));
ADM_fcreate(const name[]);
ADM:MergeFile(const first_file[],const second_file[],bool:erase_second=false);
ADM:MergeFileGroup(const group_name[],const output[],upperbound_index,bool:erase_input=false);
ADM:SplitFile(const input[],const output[],max_size,&upperbound_index=0);
new upperbound_index, ADM:edi;
edi = SplitFile("test.db","test_part",512,upperbound_index);
printf("[SplitFile] %d upp: %d",ADMToInt(edi),upperbound_index);
edi = MergeFileGroup("test_part","new.db",upperbound_index);
printf("[MergeFileGroup] %d",ADMToInt(edi));