File-XOR-Encryption

所属分类:加密解密
开发工具:C
文件大小:98KB
下载次数:0
上传日期:2022-03-08 14:49:35
上 传 者sh-1993
说明:  我在2014年编程的一个小库,用于使用XOR加密资源(例如视频游戏中的图像)...
(A small lib that i program back in 2014, useful for encrypt resources(images in a videogame for example) using a XOR key.)

文件列表:
1.png (51252, 2022-03-08)
2.png (57335, 2022-03-08)
FileEncryptionOps.h (3940, 2022-03-08)

Greetings, today I come with a small library (which I hope to continue and improve in many aspects), which serves mainly to encrypt small resources and in the future hopefully they will be of more importance. What use is this to me? Well I will begin by saying that I was programming a minigame in SDL with C++ and I wanted to encrypt the game resources (like images and other files) because when a game is distributed we are not interested in the player to see all these resources... I came up with the idea of doing it on my own, this is my method and as I always say, you can improve it(in fact that's the idea) in the end this is more a "proof of concept", I hope soon to document more the use of SDL in some aspects... since I didn't find too much about how to load resources except RWops. Another interesting thing is that it encrypts without overwriting, with this I mean that if we have 2 files one with name A.ext and B.ext when encrypting it will be like this: A(0).ext and B(1).ext, the same when decrypting... **Encryption:** ![e1](https://github.com/1.png) **Decryption:**
In the same way you can decrypt it (with SDL I managed to make it runtime, so the user would not notice it). ![e2](https://github.com/2.png) Code: ```C /******************************************* * * * Author : Gabriel Zenobi * lib : FileEncryptionOps * Version : 0.9 * Description : Work mainly with images, allowing encryption/decryption, Compatible with SDL to work with RWops and resources. * Date : 24-2-2014 * ********************************************/ #include #include #include #include #ifndef __FILE_ENCRYPTION_OPS__ #define __FILE_ENCRYPTION_OPS__ #define BEGIN_FILE_POS (0x0001) #define WRITE_TEXT ("w") #define WRITE_BINARY ("wb") #define READ_TEXT ("r") #define READ_BINARY ("rb") long GetFileSize(const char *filePath); char *strlast(char *str, int last_n); void WriteXORFileEx(const char *InputFile, const char *OutputFile); void XOR_WriteFile_Encryption(const char *FilePath); #define __XOR_KEY__ #ifdef __XOR_KEY__ const char xor_key[]= {'N', 'V', 'K'}; #endif #endif long GetFileSize(const char *filePath) { int fp= open(filePath, O_RDONLY); return (lseek(fp, 0x0000, SEEK_END)); } void strlast(char *str, int last_n, char output_buf[]) { volatile register int __ptr_length __asm__("ebx"); register int __ptr_last_n __asm__("ecx"); __asm__( "mov %%eax, (%%esp);" "call _strlen;" "movl %%eax, %%ebx;" ::"a"(str) ); __asm__("mov %%edx, %%ecx;" "sub %%ebx, %%ecx;" "neg %%ecx;" :: "d"(last_n) ); for(int i=0; i<=last_n; i++) __asm__ volatile(";":"=r"(output_buf[i]):"a"(str[ __ptr_last_n++ ])); } void WriteXORFileEx(const char *InputFile, const char *OutputFile) { int fileSize= GetFileSize(InputFile); FILE *fInput= fopen(InputFile, READ_BINARY); // abre el archivo en modo binario FILE *fOutput= fopen(OutputFile, WRITE_BINARY); // escribe el archivo en modo binario int Buff[fileSize]; char EncBuf[fileSize]; char *Write= (char *)malloc(fileSize); fread(Write, fileSize, BEGIN_FILE_POS, fInput); for(int b=0;b Date: 24-2-2014

近期下载者

相关文件


收藏者