Skip to content

Commit

Permalink
Add XOR enc
Browse files Browse the repository at this point in the history
Signed-off-by: 0x4248 <60709927+0x4248@users.noreply.github.com>
  • Loading branch information
0x4248 committed Nov 22, 2024
1 parent 5b6bbd3 commit 72b5bdb
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
16 changes: 16 additions & 0 deletions c/XORenc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: GPL-3.0
# XORenc
#
# CMakeLists.txt
#
# COPYRIGHT NOTICE
# Copyright (C) 2024 0x4248 and contributors
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the license is not changed.
#
# This software is free and open source. Licensed under the GNU general
# public license version 3.0 as published by the Free Software Foundation.

project(XORenc)

add_executable(main main.c)
44 changes: 44 additions & 0 deletions c/XORenc/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* SPDX-License-Identifier: GPL-3.0
* XORenc
*
* main.c
*
* COPYRIGHT NOTICE
* Copyright (C) 2024 0x4248 and contributors
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the license is not changed.
*
* This software is free and open source. Licensed under the GNU general
* public license version 3.0 as published by the Free Software Foundation.
*/

#include <stdio.h>

char *encode(char *str, int *key){
/**
* Loop over each item in input string (str) and XOR it with the key using
* the modulo operator to get the correct index of the key.
*
* If we hit \0 we are at the end of the string and we can stop.
*/
for(int i = 0; str[i] != '\0'; i++){
str[i] = str[i] ^ key[i % 4];
}
return str;
}

int main(){
char str[] = "Hello, World!";
int key[] = {7, 4, 5, 3};


/* Encrypt */
encode(str, key);
printf("%s\n", str);


/* Decrypt */
encode(str, key);
printf("%s\n", str);
return 0;
}
3 changes: 2 additions & 1 deletion scraps.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ MK-S += fortran/filetest/Makefile
MK-S += !c/writing_raw
MK-S += !c/http_server
MK-S += @c/tiny/build.sh
MK-S += !c/factorial
MK-S += !c/factorial
MK-S += !c/XORenc

0 comments on commit 72b5bdb

Please sign in to comment.