[C language] Can you write a string encode function based on this simple decode function?
Jochem Stoel
Posted on January 7, 2018
Hi. From the documentation of CCProxy, I got this function that decodes a user password. (string with numbers to string with characters)
I need the exact opposite as well, the code needed to encode the password. (to a 'number string').
To someone who knows a little C, this should be fairly trivial. If you can reproduce this function in JavaScript that would be even more terrific. That way I don't have to use a command line application child process to do this simple encoding/decoding.
Can you help me? Thanks!
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _MAX_BUF_LEN 2014
static char* PasswordDecode(char * szPassword)
{
char szEncode[1024];
char strDecodePass[_MAX_BUF_LEN + 1] = { "" }, strPass[_MAX_BUF_LEN + 1] = { "" };
strcpy(strDecodePass, szPassword);
for (unsigned int i = 0; i < strlen(strDecodePass) / 3; i++)
{
char szCode[_MAX_BUF_LEN + 1];
strcpy(szCode, strDecodePass + i * 3);
szCode[3] = 0;
int nCode = atoi(szCode);
nCode = 999 - nCode;
sprintf(szEncode, "%c", nCode);
strcat(strPass, szEncode);
}
strcpy(szPassword, strPass);
return szPassword;
};
int main(int argc, char **argv)
{
printf(
PasswordDecode(argv[1])
);
return 0;
}
To test if your Encode function is correct, the following plain text passwords and their encoded equivalent.
babble
901902901901891898
anus
902889882884
abcdefghijklmnopqrstuvwxyz1234567890
902901900899898897896895894893892891890889888887886885884883882881880879878877950949948947946945944943942951
💖 💪 🙅 🚩
Jochem Stoel
Posted on January 7, 2018
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.