C

Reverse a Unicode String in C

Please don’t reverse a string to obsfucate/encrypt it. Combine various methods/algorithms. Reverse it, xor it, encode it using for ex. base64 and encrypt it using a strong encryption algorithm such as AES 256, RSA etc..

Definitions and Includes:

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <stdbool.h>
 
bool ReverseString(WCHAR **dest, const WCHAR *src, int slen);

Reverse function:

bool ReverseString(WCHAR **dest, const WCHAR *src, int slen){
	if (src == NULL || slen <= 0 || src[slen - 1] != '\0') return false;
 
	*dest = _wcsrev(_wcsdup(src));
	return true;
}

Usage:

int main(void){
	WCHAR *reversed;
	const WCHAR plain[] = L"maldevel\0";
 
	if (ReverseString(&reversed, plain, wcslen(plain) + 1)){
		wprintf(L"original string: %s\n", plain);
		wprintf(L"reversed string: %s\n", reversed);
	}
 
	return EXIT_SUCCESS;
}