Skip to content

Instantly share code, notes, and snippets.

@forrestbthomas
Created May 26, 2015 06:00
Show Gist options
  • Save forrestbthomas/8aa0e0635c4a873155ae to your computer and use it in GitHub Desktop.
Save forrestbthomas/8aa0e0635c4a873155ae to your computer and use it in GitHub Desktop.
Repeating Key XOR
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char result[512];
void char_to_hex(char char_input, int should_copy)
{
char *result_char;
switch(char_input)
{
case '\v': result_char = "0b"; break;
case ' ': result_char = "20"; break;
case '!': result_char = "21"; break;
case '\"': result_char = "22"; break;
case '#': result_char = "23"; break;
case '$': result_char = "24"; break;
case '%': result_char = "25"; break;
case '&': result_char = "26"; break;
case '\'': result_char = "27"; break;
case '(': result_char = "28"; break;
case ')': result_char = "29"; break;
case '*': result_char = "2A"; break;
case '+': result_char = "2B"; break;
case ',': result_char = "2C"; break;
case '-': result_char = "2D"; break;
case '.': result_char = "2E"; break;
case '/': result_char = "2F"; break;
case '0': result_char = "30"; break;
case '1': result_char = "31"; break;
case '2': result_char = "32"; break;
case '3': result_char = "33"; break;
case '4': result_char = "34"; break;
case '5': result_char = "35"; break;
case '6': result_char = "36"; break;
case '7': result_char = "37"; break;
case '8': result_char = "38"; break;
case '9': result_char = "39"; break;
case ':': result_char = "3A"; break;
case ';': result_char = "3B"; break;
case '<': result_char = "3C"; break;
case '=': result_char = "3D"; break;
case '>': result_char = "3E"; break;
case '?': result_char = "3F"; break;
case '@': result_char = "40"; break;
case 'A': result_char = "41"; break;
case 'B': result_char = "42"; break;
case 'C': result_char = "43"; break;
case 'D': result_char = "44"; break;
case 'E': result_char = "45"; break;
case 'F': result_char = "46"; break;
case 'G': result_char = "47"; break;
case 'H': result_char = "48"; break;
case 'I': result_char = "49"; break;
case 'J': result_char = "4A"; break;
case 'K': result_char = "4B"; break;
case 'L': result_char = "4C"; break;
case 'M': result_char = "4D"; break;
case 'N': result_char = "4E"; break;
case 'O': result_char = "4F"; break;
case 'P': result_char = "50"; break;
case 'Q': result_char = "51"; break;
case 'R': result_char = "52"; break;
case 'S': result_char = "53"; break;
case 'T': result_char = "54"; break;
case 'U': result_char = "55"; break;
case 'V': result_char = "56"; break;
case 'W': result_char = "57"; break;
case 'X': result_char = "58"; break;
case 'Y': result_char = "59"; break;
case 'Z': result_char = "5A"; break;
case '[': result_char = "5B"; break;
case '\\': result_char = "5C"; break;
case ']': result_char = "5D"; break;
case '^': result_char = "5E"; break;
case '_': result_char = "5F"; break;
case '`': result_char = "60"; break;
case 'a': result_char = "61"; break;
case 'b': result_char = "62"; break;
case 'c': result_char = "63"; break;
case 'd': result_char = "64"; break;
case 'e': result_char = "65"; break;
case 'f': result_char = "66"; break;
case 'g': result_char = "67"; break;
case 'h': result_char = "68"; break;
case 'i': result_char = "69"; break;
case 'j': result_char = "6A"; break;
case 'k': result_char = "6B"; break;
case 'l': result_char = "6C"; break;
case 'm': result_char = "6D"; break;
case 'n': result_char = "6E"; break;
case 'o': result_char = "6F"; break;
case 'p': result_char = "70"; break;
case 'q': result_char = "71"; break;
case 'r': result_char = "72"; break;
case 's': result_char = "73"; break;
case 't': result_char = "74"; break;
case 'u': result_char = "75"; break;
case 'v': result_char = "76"; break;
case 'w': result_char = "77"; break;
case 'x': result_char = "78"; break;
case 'y': result_char = "79"; break;
case 'z': result_char = "7A"; break;
case '{': result_char = "7B"; break;
case '|': result_char = "7C"; break;
case '}': result_char = "7D"; break;
case '~': result_char = "7E"; break;
}
if (should_copy == 0)
{
strcpy(result, result_char);
}
else
{
strcat(result, result_char);
}
}
int main(int argc, char *argv[])
{
int i = 0;
int j = 0;
int k = 0;
int l = 0;
int I = 'I';
int C = 'C';
int E = 'E';
char temp[512];
for (i = 0; i < strlen(argv[1]); i+=3)
{
temp[i] = argv[1][i] ^ I;
}
for (j = 1; j < strlen(argv[1]); j+=3)
{
temp[j] = argv[1][j] ^ C;
}
for (k = 2; k < strlen(argv[1]); k+=3)
{
temp[k] = argv[1][k] ^ E;
}
for (l = 0; l < strlen(temp); l++)
{
char_to_hex(temp[l], l);
}
printf("%s\n", result);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment