Skip to content

Instantly share code, notes, and snippets.

@slayerlab
Last active October 4, 2015 20:52
Show Gist options
  • Save slayerlab/696c818377534ed99f0a to your computer and use it in GitHub Desktop.
Save slayerlab/696c818377534ed99f0a to your computer and use it in GitHub Desktop.
Simulator - XOR Encryption / Decryption
/***********************************************************************************
* Developed by: SLAYER OWNER | sl4y3r 0wn3r
*
* This is a simple script for simulator XOR Encryption/Decryption
* and for being an "simple script", remember that I not responsible
* any lack of security ;)
*
* For more information, read this:
* https://slayerowner.blogspot.com.br/2015/08/xor-cipher-playin-in-morning.html
*
* mailto: slayerowner!:!gmail!!com:!:
*********************************************************************************/
#include "stdio.h"
#include <stdlib.h>
#include <string.h>
#define MAX 512
void r_newline(char *r_);
void xor(FILE *infile, FILE *outfile, char *key);
int main(int argc, char *argv[]){
if(argc != 3){
fprintf(stdout,"\t\t\t\t************************************\n");
fprintf(stdout,"\t\t\t\t********** X0R ENCRYPTI0N **********\n");
fprintf(stdout,"\t\t\t\t************sl4y3r 0wn3r************\n");
fprintf(stdout,"\t\t\t\t************************************\n");
fprintf(stdout,"\t\t\t\t Usage: %s <SOURCE> <DESTINE>\n",argv[0]);
exit(0);}
FILE *input; FILE *output;
input=fopen(argv[1],"r"); output=fopen(argv[2],"w");
if(input == NULL){fprintf(stdout,"[!] An error occurred in an attempt to read the %s.\n",argv[1]);
exit(0);}
if(output == NULL){fprintf(stdout,"[!] An error occurred in an attempt to write into %s.\n",argv[2]);
exit(0);}
char *key = malloc(MAX);
fprintf(stdout,"Chave: ");
fgets(key, MAX, stdin);
fprintf(stdout,"[+] %s is encrypting...\n",argv[1]);
r_newline(key);
xor(input, output, key);
fprintf(stdout,"[+] Well done. Your %s data has been encrypted with successfully.\n",argv[2]);
free(key);
fclose(input);
fclose(output);
return 0;
}
void xor(FILE *infile, FILE *outfile, char *key){
int encrypt, k=0;
while((encrypt=fgetc(infile)) != EOF){fputc(encrypt ^ key[k], outfile);}
++k;}
void r_newline(char *r_){
if(r_[strlen(r_)-1]=='\n'){r_[strlen(r_)-1]='\0';}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment